Re: eval in procedure environment

From: Keith Wright <kwright_at_tiac.net>
Date: Mon, 10 Mar 97 22:25 EST

> I'm trying to execute a function (eg. defined in the global environment)
     Mistake -> ^^^^^^^^^^^^^^^^^^

> in the environment of a second function, so that it has access to
> the data of the second function. Example:
>
> >(define function2
> (let ((data 1))
> (lambda () data)))
> >(eval 'data (procedure-environment function2))
> 1
>
> Alright, that works. But if I try this with a procedure, it doesn't:
>
> >(define function1 (lambda () data)
> >(eval '(function1) (procedure-environment function2))
>
> Where is my mistake? What happens, if eval calls function1?

Eval does not execute a function, it evaluates an expression.
An expression is a list of symbols that happens to have certain syntax.
When you evaluate 'data you get the value of 'data in the
given environment, which is 1. When you evalate
'(function1) you get the value of 'function1 in the given
environment, and then call it. Well, the value of 'function1
in the given environment is a function of no argument that
accesses a certain global variable, whose name is of no relevance,
but which has not been assigned any value. Boom.

Perhaps what you mean to say is:

(define expression1 '(lambda() data))
(eval `( ,expression1 ) (procedure-environment function2))

-- 
     --Keith
This mail message sent by GNU emacs and Linux.
Power to the people. Linux is here.
Food, Shelter, Source code.
Received on Tue Mar 11 1997 - 04:26:48 CET

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST