[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Simulating rational number addition/subtraction
From: |
Jan Wedekind |
Subject: |
Re: Simulating rational number addition/subtraction |
Date: |
Thu, 25 Feb 2016 06:52:40 +0000 |
User-agent: |
K-9 Mail for Android |
On 24. Februar 2016 22:27:45 GMT+00:00, Lawrence Bottorff <address@hidden>
wrote:
>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
You can use GOOPS (*) to represent the rational numbers.
(*) http://www.gnu.org/software/guile/manual/html_node/GOOPS.html
--
Jan Wedekind
http://www.wedesoft.de/