From: Neil Jerram <neil@ossau.uklinux.net>
To: Gregory Marton <gremio@csail.mit.edu>
Cc: bug-guile@gnu.org
Subject: Re: comparing procedures
Date: Sat, 26 Jan 2008 13:10:52 +0000 [thread overview]
Message-ID: <871w84bulf.fsf@ossau.uklinux.net> (raw)
In-Reply-To: <Pine.LNX.4.62.0801251419480.14358@ashmore.csail.mit.edu> (Gregory Marton's message of "Fri, 25 Jan 2008 14:39:35 -0500 (EST)")
Gregory Marton <gremio@csail.mit.edu> writes:
> Hi folks,
>
> I'm trying to write a meaningful comparison operator for
> procedures.
Out of interest, why?
> Clearly this wants more than procedure-source, because
> variables in the source may be bound to different values in the
> procedure-environment.
Assuming that your objective is something like "will calling procedure
A have the same effect as calling procedure B", yes.
> I expected something like this to work:
> (define foo 3)
> (define bar (lambda (x) (+ x foo)))
> (define baz (lambda (x) (* x foo)))
> (define bar-env (procedure-environment bar))
> (define baz-env (procedure-environment baz))
OK up to here.
> (environment-fold
> bar-env
> (lambda (sym val so-far)
> (and so-far
> (environment-bound? baz-env sym)
> (equal? val (environment-ref baz-env sym))))
> #t)
Here is the problem. All of the environment-* procedures are an
experimental thing that actual has no current connection to the rest
of Guile.
> But it turns out that procedure-environment returns something which is
> not something these procedures take as an argument, it's an
> eval-closure.
Yes; an "eval-closure" is Guile's term for the top-level environment
of a module.
If the lambda had been defined in a non-top-level environment
(e.g. within a let), procedure-environment would give you something
like this:
(((a b c) . (3 #f (foo bar baz))) ; innermost lexical env vars
((s t) . ("hi" 23)) ; next outer lexical env vars
...
<eval-closure>) ; top level env
> I would have thought that this was the wrong procedure but for
> postings like this:
> http://www.cs.brown.edu/pipermail/plt-scheme/2005-August/009540.html
Well there's nothing wrong with procedure-environment. Perhaps you
could ask William Josephson if you can use his code?
> Could someone point me towards the right way to compare the
> environment of a procedure field by field? (Yes, I also have to make
> sure there are no extra fields in baz-env too, but that part I'll
> figure out.)
Given the above structure, you could compare the elements of the
list that procedure-environment returns. When you get to comparing
two <eval-closure>s, I think the only sensible thing is to use eq?.
I've appended some code below that I just used to explore this a bit.
> Thanks, confusedly,
> Grem
I'm afraid it is a bit confusing, with the environment-* procs sitting
there. I hope the above has helped.
Regards,
Neil
neil@arudy:~$ guile
guile> (define p (let ((a 1) (b 2)) (lambda () (list 4 5 6))))
guile> p
#<procedure p ()>
guile> (procedure-environment p)
(((b a) 2 1) #<eval-closure b7c238b0>)
guile> (define q (lambda () #t)
)
guile> (procedure-environment q)
(#<eval-closure b7c238b0>)
guile> (define pe (procedure-environment p))
guile> (define qe (procedure-environment q))
guile> (list? pe)
#t
guile> (list? qe)
#t
guile> (list? (car pe))
#t
guile> (list? (car qe))
#f
prev parent reply other threads:[~2008-01-26 13:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-25 19:39 comparing procedures Gregory Marton
2008-01-26 13:10 ` Neil Jerram [this message]
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=871w84bulf.fsf@ossau.uklinux.net \
--to=neil@ossau.uklinux.net \
--cc=bug-guile@gnu.org \
--cc=gremio@csail.mit.edu \
/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).