unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Noah Lavine <noah.b.lavine@gmail.com>
To: Andy Wingo <wingo@pobox.com>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: Adding Identities to Peval
Date: Thu, 16 Feb 2012 08:18:44 -0500	[thread overview]
Message-ID: <CA+U71=MRpGuhvFZ6nauXdxHeCSpHDoLxPwJa7B6axd4HhyRCfw@mail.gmail.com> (raw)
In-Reply-To: <87mx8jjf0s.fsf@pobox.com>

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	other threads:[~2012-02-16 13:18 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-16  1:29 Adding Identities to Peval Noah Lavine
2012-02-16  2:32 ` Mark H Weaver
2012-02-16  6:00 ` David Kastrup
2012-02-16  6:39   ` David Kastrup
2012-02-16  8:14     ` David Kastrup
2012-02-16  9:36 ` Andy Wingo
2012-02-16 13:18   ` Noah Lavine [this message]
2012-02-16 15:06     ` Andy Wingo
2012-02-16 17:33       ` Andy Wingo
2012-02-17  2:22       ` Noah Lavine
2012-02-17  8:13         ` Andy Wingo
2012-02-18 16:20           ` Noah Lavine
2012-02-19  9:53             ` Andy Wingo
2012-02-20 20:25               ` Noah Lavine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+U71=MRpGuhvFZ6nauXdxHeCSpHDoLxPwJa7B6axd4HhyRCfw@mail.gmail.com' \
    --to=noah.b.lavine@gmail.com \
    --cc=guile-devel@gnu.org \
    --cc=wingo@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).