guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Simulating rational number addition/subtraction


From: Lawrence Bottorff
Subject: Simulating rational number addition/subtraction
Date: Wed, 24 Feb 2016 22:27:45 +0000

With guile (and a few other Schemes/Lisps) you can directly add fractions or rational numbers:

(+ 1/2 1/12) 
=> 7/12

It's like magic, no? Anyway, I'm trying -- for educational purposes -- to reproduce this functionality. But right out of the blocks I'm stuck trying to figure out how to handle incoming parameters. So far I've got

(define (myrat a b)
   . . .)

(define (myrat a b c d)
   . . .)

where numerator and denominator are given separately, as well as 

(define (myrat . fracparams)
   . . .)

which still has my basic problem, namely, can one parameter hold both parts of a rational number, then allow the numerator and denominator to be peeled off and worked on, i.e., something like

(let ((num1 numepeeler(a))
       (denom1 denompeeler(a) 


LB

reply via email to

[Prev in Thread] Current Thread [Next in Thread]