unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* comparing procedures
@ 2008-01-25 19:39 Gregory Marton
  2008-01-26 13:10 ` Neil Jerram
  0 siblings, 1 reply; 2+ messages in thread
From: Gregory Marton @ 2008-01-25 19:39 UTC (permalink / raw)
  To: bug-guile

Hi folks,

I'm trying to write a meaningful comparison operator for procedures. 
Clearly this wants more than procedure-source, because variables in the 
source may be bound to different values in the procedure-environment.

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

But it turns out that procedure-environment returns something which is not 
something these procedures take as an argument, it's an eval-closure.
(environment? bar-env) ===> #f
(environment? (car bar-env)) ===> #f

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

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

I did dig a little farther, because I can still do this:
(local-eval 'foo bar-env) ===> 3
and local-eval says:
   -- Scheme Procedure: local-eval exp [env]
       Evaluate EXP in its environment.  If ENV is supplied, it is the
       environment in which to evaluate EXP.  Otherwise, EXP must be a
       memoized code object (in which case, its environment is implicit).

But perhaps not all environments are created equal?

This is in 1.8.1 and 1.8.3.

Thanks, confusedly,
Grem

-- 
------ __@   Gregory A. Marton                http://csail.mit.edu/~gremio/
--- _`\<,_                                                                .
-- (*)/ (*)             Contents may have settled out of court.
~~~~~~~~~~~~~~~~-~~~~~~~~_~~~_~~~~~v~~~~^^^^~~~~~--~~~~~~~~~~~~~~~++~~~~~~~





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-01-26 13:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-25 19:39 comparing procedures Gregory Marton
2008-01-26 13:10 ` Neil Jerram

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