[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: Daniel Hartwig
Subject: Re: Why 'inexact' and 'exact' doesn't check 'number?' first?
Date: Wed, 12 Dec 2012 12:39:11 +0800

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.

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]