Page 2 of 2

Re: Behaviour of EVAL inside LET

Posted: Fri Nov 16, 2012 8:25 am
by abvgdeika
The discussion in this topic is aimed at better understanding how the principle "there is no difference between code and data in LISP" works in practice.
My intention was to "execute" comand-variables containing LISP code as their values (like variable "command") so that all variables which appear in this code assume local values within current lexical environment during the execution. And macro "true-eval" does this job! It may fail in some other situations like in your input-output operators (in some implementations). In my implementation (Allegro CL),
both your input-output codes with EVAL and TRUE-EVAL work identically without problems.

Re: Behaviour of EVAL inside LET

Posted: Fri Nov 16, 2012 9:07 am
by Goheeca
Yes, for that macros are good.
But I've wanted to point the difference between a runtime evaluation and a macroexpansion out (beacuse I didn't know you don't want the normal evaluation). Try in Allegro CL to factor out what was in the loop.

Code: Select all

(defun counted-result (i) (format t "~a> ~a~%" i (eval (read))))
(loop for i below 3 do (counted-result i))
vs.

Code: Select all

(defun counted-result (i) (format t "~a> ~a~%" i (true-eval (read))))
(loop for i below 3 do (counted-result i))
At the second snippet insert the top-level forms one by one and maybe use compile which can be used by program, so it's relevant.

Re: Behaviour of EVAL inside LET

Posted: Fri Nov 16, 2012 10:01 am
by abvgdeika
I am not so advanced LISP user to understand
the difference between a runtime evaluation and a macroexpansion out
(:-))))
But macro TRUE-EVAL has indeed a strange behaviour. It cannot be applied to formal variables inside function definitions, an attempt to compile

Code: Select all

(defun t-eval (x) (true-eval x) ) 
gives an error unless "x" already has some value.
My suggestion to those who read this forum and who plan to improve/better implement such a great langage as LISP is to take more attention to the evaluation operations.

Re: Behaviour of EVAL inside LET

Posted: Fri Nov 16, 2012 10:47 am
by Goheeca
Because the x gets evaluated during macroexpansion of the evaluate in macrolet, so you should have it quoted:

Code: Select all

(defun t-eval (x) (true-eval 'x))

Re: Behaviour of EVAL inside LET

Posted: Fri Nov 16, 2012 3:06 pm
by Paul
abvgdeika wrote:The discussion in this topic is aimed at better understanding how the principle "there is no difference between code and data in LISP" works in practice.
My intention was to "execute" comand-variables containing LISP code as their values (like variable "command") so that all variables which appear in this code assume local values within current lexical environment during the execution.
You can't do that, as a general rule. You're confusing symbols and variables -- they're not the same thing (except for "special" variables). Symbols are data objects used to name variables; a variable is just a memory address -- there's no way to link a symbol to an address in Lisp (you might be able to through the debugger interface, etc.), so you can't turn a symbol coming from outside into the same variable that was named by that symbol in a piece of source code. (And if you could, you'd break all sorts of things...)