From ... From: Erik Naggum Subject: Re: "Wrong" results from _Common LISPcraft_ scope example Date: 1998/09/26 Message-ID: <3115842049861794@naggum.no>#1/1 X-Deja-AN: 395189816 References: mail-copies-to: never Organization: Naggum Software; +47 8800 8879; http://www.naggum.no Newsgroups: comp.lang.lisp * mcfarlan@neca.com (D. Michael McFarland) | I'd appreciate any insights anyone can offer into which result is | "correct", how two CL implementations can differ on what seems a | fundamental point, or what I could have done wrong. it was a really bad example. it tried to show you that the SUM in SUM-AVERAGE-CALLER is not the same SUM as that in SUM-AVERAGE, but it attempts to use a "global, non-special variable", and those do not actually exist in Common Lisp. the example depends on the effects of the form (setq sum '(a b c)) when evaluated at top-level. CMUCL marks SUM as special, in effect performs a DEFVAR, which means SUM-AVERAGE-CALLER actually _binds_ the SUM that SUM-AVERAGE sets, so the outermost (= global) binding is not affected. CLISP and Wilensky assume that it is valid for a variable to be assigned a value in the top-level loop without being special. the reasonable behavior is to assume that a variable that is not closed over lexically has a special binding. if setting the value of a previously unbound symbol also causes it to be marked special in the top-level loop, I'd consider that a nicety of the implementation for most uses, but is by no means a requirement, and good Common Lisp programmers never rely on the effects of such operations, anyway. one could also argue that it would be a pain to declare variables you set at top-level special just because you need them to have some value when testing code, and I have come to think this is why some implementations don't do it. but, come to think of it, CMUCL prints a warning that it declares such a variable special, which you _should_ have noticed -- it's what lawyers call "material evidence". :) #:Erik