On Sat, 2009-04-25 at 19:11 +0300, Nikodemus Siivola wrote:
> The attached patch is a work-in-progress, providing declarations
> GLOBAL and ALWAYS-BOUND, and uses these to implement DEFGLOBAL.
> GLOBAL declaration is analogous to SPECIAL: global variables cannot be
> locally bound or defined/bound as symbol macros, and all threads share
> the same value. The intention behind prohibiting rebinding is that
> this seems like a useful property that cannot be implemented by users:
> those wanting globals that _can_ be rebound can simply wrap the global
> in a symbol-macro to get the rebinding-allowing semantics. The
> intention is to support it as a local declaration as well, but this
> has not been implemented yet.
> ALWAYS-BOUND declaration is a bit more special: it can only be used in
> DECLAIM/PROCLAIM, not in a local DECLARE. To proclaim a variable as
> ALWAYS-BOUND it needs to be already bound and not a constant. The
> proclamation inhibits future attempts to MAKUNBOUND it. The reason for
> prohibiting local ALWAYS-BOUND declarations is that they are not safe
> -- and (OPTIMIZE (SAFETY 0)) already has the same effect in practice.
> If this is deemed too ugly, I can add support for local declarations
> as well -- either as no-ops, or as no-ops outside safe code, or
> DEFGLOBAL proclaims the defined variable as both GLOBAL and
> ALWAYS-BOUND, and is sort of between DEFVAR and DEFCONSTANT: the value
> is evaluated both compile-time and load-time iff the name is not
> already bound, in order to allow for the ALWAYS-BOUND declaration.
> This is to make things like
> (defglobal .lock. (make-mutex))
> safe (so as not to replace the mutex with a new one when
> reloading/compiling a file, etc), and to make DEFGLOBAL a mostly
> drop-in replacement for DEFVAR and DEFCONSTANT where appropriate.
> Users needing global equivalents of DEFPARAMETER get to roll their
> How does this look?
Interesting. Reminds me of:
If I got this right, depenending on how one look at it, DEFGLOBAL is
basically a DEFVAR with some constraints added (safety for users or
clarity of intent) and/or features removed (faster?).
I have at least one place in my code where I can see both of these
effects being useful.
> -- Nikodemus