Subject: Re: Simple noob question.
From: rpw3@rpw3.org (Rob Warnock)
Date: Sun, 24 Feb 2008 06:22:21 -0600
Newsgroups: comp.lang.lisp
Message-ID: <BIudnYsGJ9vg_FzanZ2dnUVZ_hGdnZ2d@speakeasy.net>
iant  <deadletter@iankthompson.org> wrote:
+---------------
| Kent M Pitman <pit...@nhplace.com> wrote:
| > It is recommended that, absent some strong compelling reason (not in
| > evidence), you always use global variables that have *...* around
| > their names.  The *'s are just alphabetic characters, but this
| > different naming is commonly used and helpful for reasons I'll
| > explain.
| 
| Is this because there are no variables with local scope?
+---------------

[I assume by "local scope" here you really mean "lexical scope"...]

No, there are certainly variables with lexical scope, but in
standard CL there are no global variables with lexical scope.[1]
Said another way, the global environment contains only variables
with dynamic scope (with the exception noted in [1]), and if you
rebind one with LET or LAMBDA you will give it a new *dynamic*
binding, which is not "local", and thus have effects you might not
expect if coming from languages with global lexical variables, e.g.:

    > (defparameter foo 13)

    FOO
    > (defun foo () foo)

    FOO
    > (defun bar () 27)

    BAR
    > (let ((foo 54)
	    (bar 91))
	(list foo (foo) bar (bar)))

    (54 54 91 27)
    > 

For this reason the Lisp community style [a *very* strong convention!]
is to use the *FOO* form for global (dynamic) variables so you won't
accidentally rebind one dynamically when you were intending to just
create a fresh lexical binding.


-Rob

[1] You can fake up global lexical variables by using symbol
    macros -- Google for DEFLEX, DEFLEXICAL, or DEFGLOBAL.
    Such "variables" are reliably shadowed by lexical rebindings,
    so there's no reason to use the *...* convention in their case.

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607