Scope 2...

Fabrizio Morbini <[email protected]>
Newsgroups gmane.lisp.allegro
Message-ID <[email protected]>
Hi, thank you very much for all the response to my previous mail!

Take this example:

(setq a 6)

(flet (
       (prova () (print a))
       )
      (let ((a 4))
	(print a)
	(prova)))

(print a)

The output is:

print: 4
prova: 6
print: 6

This is because the function prova isn't in the lexical environment
created by let...

using defvar instead of setq the output is:

print: 4
prova: 4
print: 6

*Why the let hidden the dinamic scope variable "a" (defvar) but not when
this is created by setq? My response is: because let start a new empty
lexical environment that doesn't contain "a" so let can't hidden a
variable that can't see... is correct?

Take this example:

(let ((a 6))
  (flet (
	 (prova () (print a))
	 )
	(print a)
	(let ((a 4))
	  (print a)
	  (prova)))
  (print a)
  )

the output is:

print: 6
print: 4
prova: 6
print: 6

This seems to reinforce my previous answer...

Thank you very much and best regards!

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