Subject: Re: Scheme and Rational Numbers
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 2 Feb 2001 08:09:10 GMT
Newsgroups: comp.lang.scheme
Message-ID: <95dpv6$142ok$1@fido.engr.sgi.com>
Jeffrey Stephens  <jsteve17@tampabay.rr.com> wrote:
+---------------
| Let me see if I have understood what each of you is getting at. Suppose I
| have the number 3.5. In my hypothetical problem I know this number to be
| exact, i.e. I know it to be equal to 7/2.  If I understand you all
| correctly, I should express this number in Scheme as (/ 7 2) as opposed
| to 3.5 because Scheme itself has no way of reading my mind.  Is this
| a correct interpretation?
+---------------

Almost, but no "mind reading" is needed. The Scheme language provides
the input syntax "7/2", so you can express rationals directly as constant
input terms, without having to go through the process of computing them
by division. That is:

	> (eqv? 7/2 (/ 7 2))
	#t
	> (+ 7/2 3/5)
	41/10
	> (exact->inexact (+ 7/2 3/5))
	4.1
	>

Of course, there may be non-conformant *implementations* of Scheme
that don't accept the standard input syntax for rationals (and for
those implementations you might have to compute the rational value
at runtime using explicit division), but that's an implementation
issue, not a language issue.


-Rob

-----
Rob Warnock, 31-2-510		rpw3@sgi.com
SGI Network Engineering		http://reality.sgi.com/rpw3/
1600 Amphitheatre Pkwy.		Phone: 650-933-1673
Mountain View, CA  94043	PP-ASEL-IA