[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Re: Lexical equivalent of progv]
What makes a lexical variable LEXICAL is that the place where it
is bound andl all uses of that binding are lexically apparent in
the program. (which implies they can be determined by a compiler)
Progv allows a program to COMPUTE the names of the variables, meaning that
they are NOT lexically apparent --- the same PROGV form can bind
variables of different names (even different numbers of vars) from
one execution to the next. So there can't be direct analog.
You could, with a macro, define a lexical progv that took an
UNEVALUATED list of variables and an EVALUATED list of bindings, e.g.
(defmacro LPROGV (varlist vallist &body b)
(unless (every #'symbolp varlist) (error "illegal variable list"))
`(apply #'(lambda (&optional ,@varlist &rest ignore)
(declare (ignore ignore))
This would, like PROGV, allow the valuelist to contain either fewer or
more values than the varlist. Unlike PROGV, if the value list contained
fewer values than the varlist, the excess vars would be bound to NIL.
(There is no concept of an unbound LEXICAL variable in common lisp.
I imagine the designers assume that by allowing optional parameters
in lambda lists to have both defaults AND supplied-p indicators,
programmers could live with that restriction. Personally, I think
it would hve been better to have the unbound concept for lexical variables
as well as specials, but I can't tell if UNBOUND is really at the root
of your request or not.)