On Thu 16 Feb 2012 02:29, Noah Lavine <noah.b.lav...@gmail.com> 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