From: Captain Obvious on 21 Apr 2010 03:35 TAR> One of them is to, in effect, declare the variable to be "locally" TAR> special. In other words, the particular references where there is no TAR> information are assumed to refer to a special variable. IIRC all implementations I've checked default to using symbol-value before signaling unbound/undefined variable condition. E.g. (in SBCL): CL-USER> (setf (symbol-value 'foobar) 42) 42 CL-USER> foobar 42 Doesn't even generate warnings TAR> I think this is at least similar to your lexical global in effect. Yeah, they are almost indistinguishable. There is global lexical variable implementation using symbol-macros: http://rpw3.org/hacks/lisp/deflex.lisp (Btw, it appears that symbol macros have semantics which exactly matches what is needed for making global lexicals, so probably they were deliberately made for this purpose, among other things.) Here's how global lexical variables work: CL-USER> (deflex blorg 15) BLORG ;; if there is lexical binding, it is captured by closure: CL-USER> (let ((fun (let ((blorg 16)) (lambda () blorg)))) (let ((blorg 17)) (funcall fun))) 16 ;; if there is no lexical binding, global value is used, but not value from lexical binding: CL-USER> (let ((fun (lambda () blorg))) (let ((blorg 17)) (funcall fun))) 15 "Undefined variables" work same way in SBCL: CL-USER> (setf (symbol-value 'blorgX) 15) 15 CL-USER> (let ((fun (let ((blorgX 16)) (lambda () blorgX)))) (let ((blorgX 17)) (funcall fun))) 16 CL-USER> (let ((fun (lambda () blorgX))) (let ((blorgX 17)) (funcall fun))) ; caught WARNING: ; This variable is undefined: ; BLORGX 15 They can be distinguished if we use (declare (special blorgX)): CL-USER> (let ((fun (lambda () blorgX))) (let ((blorgX 17)) (declare (special blorgX)) (funcall fun))) 17 Variable made via deflex does not react to this thing, but it can be considered an implementation artifact. Maybe there are other subtle differences, with multithreading or something like that... .. TAR> Other lisps (ARAIK only CMUCL and SBCL) will globally declaim the TAR> variable as being special. CMUCL does, SBCL does not.
First
|
Prev
|
Pages: 1 2 3 Prev: linux .emacs file Next: "C-like" syntax for Lisp in less than 100 lines of code |