[plt-scheme] real but not rational?

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Wed Feb 1 16:49:03 EST 2006

Greg Woodhouse wrote:
> Is it possible to (read) a value in PLT Scheme to get a value v such
> that (real? v) is true and (rational? v) is false? I suppse that with
> arbitrary precision arithmetic, this shouldn't be too surprising, but I
> was surprised to see that my evaluator always tags numeric values as
> rational, even values like 2.7e8 or 3.14159. I eventually plan to write
> my own reader, but for now, I'm just using the underlying Scheme.

Is inexact? what you need?

 > (require (lib "string.ss"))

 > (read-decimal-as-inexact #t)
 > (inexact? (read-from-string "1.2"))
#t

 > (read-decimal-as-inexact #f)
 > (inexact? (read-from-string "1.2"))
#f

-- 
Jens Axel Søgaard




Posted on the users mailing list.