guile-devel
[Top][All Lists]
Advanced

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

Re: Adding Identities to Peval


From: Noah Lavine
Subject: Re: Adding Identities to Peval
Date: Thu, 16 Feb 2012 08:18:44 -0500

Hello,

> 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))

Ah, that is a cleaner way to do it. But ideally I would like
identities to be things that we can store in lists, so that

(let* ((x (random))
       (y (list x))
       (z (car y))
  (eq? x z))

optimizes to (begin (random) #t). That requires more infrastructure,
though - probably some sort of struct representing a value, with parts
for the constant value and the identity, that gets passed around in
peval.

Also, David pointed out that this doesn't have many uses. That is
probably true. :-) I actually did it because it's a simpler version of
type-checking, which *does* have many uses. In order to type-check,
you need to be able to associate extra information with a value (its
type) even in cases where you don't know the value. Identities work
the same way, except that the information is simpler. So my ulterior
motive in doing this is to learn how to do that, and set up whatever
infrastructure I need for it.

Noah



reply via email to

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