From ... From: Erik Naggum Subject: Re: beginner question Date: 1998/04/24 Message-ID: <3102397945639898@naggum.no>#1/1 X-Deja-AN: 347247097 References: <353F12C5.4FFC20F2@csst.cs.technion.ac.il> <6hp3jt$4t984@fido.asd.sgi.com> mail-copies-to: never Organization: Naggum Software; +47 8800 8879; http://www.naggum.no Newsgroups: comp.lang.lisp * Rob Warnock | That brings up a stupid-beginner-question of *mine*... I had the same question a few years ago, related to what SETQ at top-level would do to an undeclared symbol: CMUCL automatically declares it special, Allegro CL does not, so I thought there was something to a non-special global myself. as it turns out, that's just an ordinary symbol, but that is mainly an artifact of the top-level loop. I'm not sure I _fully_ understand Barry's and Kelly's responses, though. | In Common Lisp, how do you define a global variable that's *not* dynamic, | that is, that has lexical scope? you don't, but there is nothing to bar you from accessing a symbol's slots directly, such as with SYMBOL-VALUE. since the compiler will barf on references to undeclared symbols, you need to access them explicitly with (SYMBOL-VALUE 'SYMBOL) and (SETF (SYMBOL-VALUE 'SYMBOL)). this is not pretty, and might even be seen as thwarting the semantics of the language. | How does one avoid this when one wants normal (to a Scheme user) lexical | scope for a global variable? What declaration or initial definition form | does one use? well, in sharp contrast to Scheme, we have very easy access to lexical closures in Common Lisp. e.g., (let ((line-counter 0)) (defun foo (...) ... line-counter ...) (defun bar (...) ... line-counter ...)) will create two functions FOO and BAR that share the lexical binding of LINE-COUNTER. in Scheme, as I'm sure you are aware, the LET-form would remove the top-level-ness of the now _internal_ defining forms and just return some arbitrary values instead of defining new functions. in this regard, I find Common Lisp to be far superior to Scheme, which encourages a proliferation of global symbols with lexical semantics as opposed to carefully constrained access to shared lexical bindings, which I found real cumbersome to do last time I tried it in Scheme, but I'm certainly no fan of Scheme, so I might well have missed something important. #:Erik -- Abort, Retry, or Upgrade?