Subject: Re: symbol-value returns lexical value?
From: rpw3@rpw3.org (Rob Warnock)
Date: Wed, 25 Apr 2007 05:16:18 -0500
Newsgroups: comp.lang.lisp
Message-ID: <H8Odna8j0qXvt7LbnZ2dnUVZ_viunZ2d@speakeasy.net>
Kent M Pitman  <pitman@nhplace.com> wrote:
+---------------
| I tried to get global lexicals into the language, but the attempt failed.
| See info on failed X3J13 issue PROCLAIM-LEXICAL at 
| http://www.nhplace.com/kent/CL/Issues/proclaim-lexical.html
| There's no provision for it in the language, but it's an easy user
| program to write.  DEFINE-SYMBOL-MACRO is the operator you need,
| and you can google for prior discussion on how to set it up.
+---------------

Here's a version I posted just a few months ago:

    (defmacro deflex (var val &optional (doc nil docp))    
      (let ((backing-var (intern (concatenate 'string
					      (symbol-name '#:*deflex-var-)
					      (symbol-name var)
					      (symbol-name '#:*))
				 (symbol-package var))))
	`(progn
	   (defparameter ,backing-var ,val ,doc)
	   ,@(when docp `((setf (documentation ',var 'variable) ,doc)))
	   (define-symbol-macro ,var ,backing-var))))


-Rob

p.s. Reminder: If you're running CMUCL-19c or earlier, you will
need the path to MACROEXPAND-1 that I posted on 2006-12-18
[Message-ID: <Y_Cdnbvi_4Ir4RvYnZ2dnUVZ_tunnZ2d@speakeasy.net>]
or you will have problems with SETF expanders which reference
DEFLEX'd variable names.

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