javuchi <nospam@nospam.com> wrote:
+---------------
| A translation:
| (define (a) (+ 5 5)) -> (defun a () (+ 5 5))
| but what is the translation for:
| (define a (+ 5 5))
+---------------
Depending on the context in which you're asking, the answer is either:
1. Pick one of these, depending on how it's going to be used, and
what you want to happen when the statement is executed again
(e.g., if the source file is reloaded):
(defvar *a* (+ 5 5))
(defparameter *a* (+ 5 5))
(defconstant +a+ (+ 5 5))
2. There isn't any translation, not directly, since ANSI Common Lisp
doesn't provide global lexical variables, though from time to time
suggestions have been voiced[1] about using a DEFINE-SYMBOL-MACRO hack
to get the same effect. In the latter case, one translation might be:
(deflexical a (+ 5 5))
-Rob
[1] Including me, but lately I've been having some problems with
my DEFLEX macro in CMUCL. I need to investigate a bit further,
but it looks like the symbol macro isn't being properly shadowed
in some cases by a subsequent lexical binding. [The problem seems
to arise when the inner lexical variable is used by a SETF-expander
such as INCF.] "Film at 11..."
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607