[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Lexical variables



I've just finished implementing a feature I call LEXICAL-CLOSURE
which makes nonspecial variables into downward-only lexical variables:

(defun foo (a)
   (mem (lexical-closure '(lambda (pat elt)...)) ...))

allows the inner lambda to access the variable a even though not special.

So far it only works in compiled code, and it isn't installed.

I have two questions I want input on:

1) should it be necessary to write LEXICAL-CLOSURE explicitly to have
this feature?  Perhaps writing an unquoted lambda-expression should
do this?  Perhaps (FUNCTION (LAMBDA ...)) should do this?

2) Should I change the interpreter so that variables behave always
as they do in the compiler?  That is, if not declared special,
they would be completely local, unless the lexical-closure mechanism
(under whatever user interface is used) makes them visible to an internal lambda.

Note that expressions such as ((lambda ...) args) are compiled open by all`
lisp compilers I know of, so that explicit lexical-closure is not
needed in that case, and won't be in the future either.
This makes me feel that it would be inconsistent to reqire an
explicit lexical-closure in any other case just to get the same behavior.