guile-devel
[Top][All Lists]
Advanced

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

Re: Adding Identities to Peval


From: Andy Wingo
Subject: Re: Adding Identities to Peval
Date: Thu, 16 Feb 2012 10:36:51 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)

On Thu 16 Feb 2012 02:29, Noah Lavine <address@hidden> writes:

> (let* ((x (random))
>        (y x))
>   (eq? x y))
>
> The patch attached to this message lets peval optimize that to
>
> (begin (random) #t)

Neat :)

Note, we don't need to add extra identities to operands: they already
have their gensyms.  So to get the effect of this patch, you could add a
clause to fold-constants:

  ((primcall src 'eq? (lexical _ _ x) (lexical _ _ y))
   (if (eq? x y)
       (make-const src #t)
       <keep-original-expression>))

This works because peval already turns it into the following, after
processing the operands for value:

  (let ((x (random)))
    (eq? x x))

And all we have to do is check if the lexical is being compared against
itself.

Then, I was about to say:

    Now, while this is a valid reduction:

      (lambda (x) (eq? x x)) => (lambda (x) #t)

    This is not:

      (lambda (x) (eqv? x x)) =/> (lambda (x) #t)

    The reason is +nan.0: (eqv? +nan.0 +nan.0) => #f

But.... that's wrong!  (eqv? +nan.0 +nan.0) isn't specified by the R6RS,
and currently we have it be #t.  I guess that's good for our peval
purposes!

Cheers,

Andy
-- 
http://wingolog.org/



reply via email to

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