Path: utzoo!attcan!uunet!tektronix!tekcrl!tekchips!willc From: willc@tekchips.TEK.COM (Will Clinger) Newsgroups: comp.lang.lisp Subject: Re: SETQ vs DEFVAR at the top level Summary: DEFVAR PROCLAIMs, SETQ doesn't Keywords: closure, HELP, DEFVAR, PROCLAIM, SPECIAL Message-ID: <3368@tekchips.TEK.COM> Date: 1 Jul 88 19:13:16 GMT References: <4431@medusa.cs.purdue.edu> Reply-To: willc@tekchips.UUCP (Will Clinger) Organization: Tektronix, Inc., Beaverton, OR. Lines: 19 In article <4431@medusa.cs.purdue.edu> bouma@cs.purdue.EDU (William J. Bouma) writes: > > In Common Lisp, what difference does it make if one gives his >global variables lexical scope (via SETQ) or dynamic scope (via DEFVAR)? >None you say, only it is better style to use DEFVAR? WRONG bucko! [long example deleted] That's right, friends. DEFVAR implicitly PROCLAIMs its variable to be SPECIAL, while SETQ does not. A variable PROCLAIMed SPECIAL by DEFVAR cannot be used as a lexical variable, and thus cannot be captured by a closure. Common Lisp provides DEFVAR (and PROCLAIM) to make it easier to introduce mysterious scoping bugs such as the one in Bouma's example. Without DEFVAR and PROCLAIM, each binding instance of a special variable would have to be explicitly declared as special, eliminating the need to scan entire programs in order to determine that a variable that appears lexical is in fact so. Peace, Will