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~~~~^^^^~~~~~--~~~~~~~~~~~~~~~++~~~~~~~