[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Re: Simulating rational number addition/subtraction

**From**: |
dsmich |

**Subject**: |
Re: Simulating rational number addition/subtraction |

**Date**: |
Wed, 24 Feb 2016 18:32:12 -0500 |

---- 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*
This https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-14.html might be
enlightening....
-Dale