unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: <dsmich@roadrunner.com>
To: guile-user@gnu.org, Lawrence Bottorff <borgauf@gmail.com>
Subject: Re: Simulating rational number addition/subtraction
Date: Wed, 24 Feb 2016 18:32:12 -0500	[thread overview]
Message-ID: <20160224233212.D0GOI.246997.root@cdptpa-web08> (raw)
In-Reply-To: <CAFAhFSXeLgX73qZrF5ns1wkRHZZZ3sjsNKSBOXKWcTsXxn+hag@mail.gmail.com>


---- Lawrence Bottorff <borgauf@gmail.com> 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





  reply	other threads:[~2016-02-24 23:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-24 22:27 Simulating rational number addition/subtraction Lawrence Bottorff
2016-02-24 23:32 ` dsmich [this message]
2016-02-25  7:07   ` tomas
2016-02-26 13:01     ` Alex Vong
2016-02-25  6:52 ` Jan Wedekind

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160224233212.D0GOI.246997.root@cdptpa-web08 \
    --to=dsmich@roadrunner.com \
    --cc=borgauf@gmail.com \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).