[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why 'inexact' and 'exact' doesn't check 'number?' first?

From: Nala Ginrut
Subject: Re: Why 'inexact' and 'exact' doesn't check 'number?' first?
Date: Wed, 12 Dec 2012 13:55:37 +0800

On Wed, 2012-12-12 at 12:39 +0800, Daniel Hartwig wrote:
> On 12 December 2012 11:21, Nala Ginrut <address@hidden> wrote:
> > It's weird to see that:
> > (exact? 'a)
> > ================err msg===============
> > ERROR: In procedure exact?:
> > ERROR: In procedure exact?: Wrong type argument in position 1: a
> > ==================end=================
> >
> > And I have to do this:
> > (define (fraction? obj)
> >   (and (number? obj) (inexact? obj)))
> “Fraction” is not a very precise term or relevent to the type
> hierarchy in Scheme, please do not use that.  Disregard that GOOPS
> define such a class, the more precise term is “rational” for which
> there is already a predicate.

Many thanks!
But rational? returns TRUE both 1.5 & 1/2, I need a predicate to check
between 'float' and 'fraction' distinctly.

Are you suggesting I use (is-a? obj <fraction>) for 'fraction?' ?

> Your fraction? predicate is not equivalent to the GOOPS <fraction>
> class, which are exact? and (in all cases I believe) also rational?.
> >
> >
> > Why not 'exact?' and 'inexact?' doesn't check 'number?' first?
> Performance. They are intended to be used in numerical paths and
> requiring them to check first number? every time is very inefficient.
> You will note that they are documented as “exact? Z“ rather than
> “exact? obj”.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]