Question about scope and let...

[email protected]
Newsgroups gmane.lisp.allegro
Message-ID <[email protected]>
> Hi, why there is this behaviour?
>
> CL-USER(1): (setq var-test 5)
> 5
> CL-USER2: (let ((var-test 4)) var-test (eval 'var-test))
>
> 4
> 5
> CL-USER(3):
>
> Thank you very much and Best Regards.
>
> Fabrizio.

Don't you mean the following?

(let ((var-test 4))
  (print var-test)
  (eval 'var-test))

The reason is simple.  The first VAR-TEST being printed is the value of
the local variable, which is bound to 4 by the LET.  The second value
being printed (the 5) is what the LET returns and the top-level
read-eval-print loop prints, which is the value of the variable VAR-TEST
in the global environment, which is the value set by the SETQ - namely, 5.

Remember that EVAL evaluates expressions in the global environment
(unless weird things are done to force otherwise).

 -Bob
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.