From: Andy Wingo <wingo@pobox.com>
To: Noah Lavine <noah.b.lavine@gmail.com>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: Adding Identities to Peval
Date: Thu, 16 Feb 2012 16:06:02 +0100 [thread overview]
Message-ID: <87hayqkecl.fsf@pobox.com> (raw)
In-Reply-To: <CA+U71=MRpGuhvFZ6nauXdxHeCSpHDoLxPwJa7B6axd4HhyRCfw@mail.gmail.com> (Noah Lavine's message of "Thu, 16 Feb 2012 08:18:44 -0500")
On Thu 16 Feb 2012 14:18, Noah Lavine <noah.b.lavine@gmail.com> writes:
>> (let ((x (random)))
>> (eq? x x))
>
> (let* ((x (random))
> (y (list x))
> (z (car y))
> (eq? x z))
This one should reduce to the same thing, but currently doesn't because
(list x) is not considered a "constant expression" because `let' is a
"constructor" (quotes to indicate the language of peval). If we can
propagate it (probably true in this case, given that it has only one
use), then the expression folds as before:
(let* ((x (random))
(z (car (list x))))
(eq? x z))
=>
(let ((x-129 (random)))
(eq? x-129 x-129)))
So I don't think that for this purpose (identity) we need any more
mechanism
> 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.
For this purpose, have you considered creating a functional database of
facts? Then you can add facts when you see conditionals, for example,
and you get different facts in the different branches.
(if test consequent alternate)
;; assuming the test doesn't fold
=> (make-if (for-test test current-facts)
(for-tail consequent (add-fact test #t current-facts))
(for-tail consequent (add-fact test #f current-facts)))
You can also join the facts accumulated by a conditional branch with the
current facts if you detect that one of the branches leads to a nonlocal
exit, as in
(define (foo x)
(if (not (and (struct? x) (eq? (struct-vtable x) <foo>)))
(error ...))
;; here at this point, we have the fact: x is a struct, and its
;; vtable is <foo>
...)
This is related to range analysis. But, it's also something that's
easier to do with an explicit notion of control flow (i.e. a CPS IR).
Regards,
Andy
--
http://wingolog.org/
next prev parent reply other threads:[~2012-02-16 15:06 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
2012-02-16 15:06 ` Andy Wingo [this message]
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=87hayqkecl.fsf@pobox.com \
--to=wingo@pobox.com \
--cc=guile-devel@gnu.org \
--cc=noah.b.lavine@gmail.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).