[plt-scheme] Infinite?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Jul 16 09:15:15 EDT 2009

At Thu, 16 Jul 2009 14:07:01 +0100, "Paulo J. Matos" wrote:
> On Thu, Jul 16, 2009 at 2:00 PM, Matthew Flatt<mflatt at cs.utah.edu> wrote:
> > At Thu, 16 Jul 2009 10:00:25 +0100, "Paulo J. Matos" wrote:
> >> I find that the scheme languages misses infinite? which r6rs has.
> >> What's the reason for this?
> >
> > Only that there has never been any particular demand, as far as I know.
> >
> >> Is it ok to define infinite? as:
> >> (define (infinite? x) (or (eq? x +inf.0) (eq? x -inf.0)))
> >
> > Use `eqv?' instead of `eq?', and then that's right.
> >
> >
> 
> Some simple examples show that eq? works in some particular cases, any
> cases where it wouldn't work?

It should usually not work, I think:

 > (define (infinite? x) (or (eq? x +inf.0) (eq? x -inf.0)))
 > (infinite? (/ 0.0))
 #f
 > (/ 0.0)
 +inf.0

About the only time it would work is when you pass the literal constant
`+inf.0' or `-inf.0' to `infinite?'.

> Or is it just a matter of correct programming style to use eqv? over eq?.

It's not just style. The weak guarantees of `eq?' make it unsuitable
for defining `infinity?'.




Posted on the users mailing list.