Hi, all
Is there a portable way to tell if a variable is declared special
globally?
My first shot is the following.
(defun special-variable-p (symbol)
(assert (symbolp symbol))
(let ((marker (gensym)))
(eval `(flet ((special-p ()
(and (boundp ',symbol) (eq ,symbol ',marker))))
(and (not (constantp ',symbol))
(let ((,symbol ',marker))
(special-p)))))))
This can't distinguish whether it is declared special globally or locally.
And the variable is once bound to a gensymed symbol, which might cause any
trouble if the variable is one of those used by the system like *package*.
Is there any better way to do it?
Regards,
Yuji.
Yuji Minejima wrote:
> Hi, all
>
> Is there a portable way to tell if a variable is declared special
> globally?
A semi-portable way is to use the environment functions from CLtL2. See
Chapter 8.5, especially VARIABLE-INFORMATION.
They have been dropped from the ANSI standard, but some CL
implementations still provide them, and Allegro Common Lisp 7.0 will
include a polished version of those.
Pascal
--
Tyler: "How's that working out for you?"
Jack: "Great."
Tyler: "Keep it up, then."
On Fri, 27 Aug 2004 11:46:43 +0200, Pascal Costanza wrote:
> A semi-portable way is to use the environment functions from CLtL2. See
> Chapter 8.5, especially VARIABLE-INFORMATION.
Thanks. I'll check that.
Cheers,
Yuji.
From: Iain Little
Subject: Re: A portable way to tell if a variable is declared special globally
Date:
Message-ID: <87d61d3wo5.fsf@yahoo.com>
Yuji Minejima <········@nifty.ne.jp> writes:
> Hi, all
>
> Is there a portable way to tell if a variable is declared special
> globally?
You could always do the test indirectly:
(defun globally-special-p (symbol)
(eval `(values (ignore-errors (let ((,symbol nil))
(flet ((test () ,symbol))
(let ((,symbol t))
(test))))))))
Which should work, but is a bit of a hack. It is probably better to
use implementation-specific extensions if for some reason you need to
do this in something serious.
Iain
Iain Little <······@yahoo.com> wrote in message news:<··············@yahoo.com>...
> Yuji Minejima <········@nifty.ne.jp> writes:
>
> > Hi, all
> >
> > Is there a portable way to tell if a variable is declared special
> > globally?
>
> You could always do the test indirectly:
>
> (defun globally-special-p (symbol)
> (eval `(values (ignore-errors (let ((,symbol nil))
> (flet ((test () ,symbol))
> (let ((,symbol t))
> (test))))))))
>
> Which should work, but is a bit of a hack. It is probably better to
> use implementation-specific extensions if for some reason you need to
> do this in something serious.
>
>
> Iain
Thank you for showing the alternative approach.
I also feel my version a bit hacky.
I'm now writing a portable optimizing loop implementation and
I can do an useful optimization if this functionality is available
which I explained in
http://groups.google.co.jp/groups?selm=pan.2004.08.25.07.57.58.700330%40nifty.ne.jp
.
Now I'm thinking of using implementation-specific extensions and use
the "portable" function in the last resort.
Yuji.http://groups.google.co.jp/groups?selm=pan.2004.08.25.07.57.58.700330%40nifty.ne.jp
Yuji Minejima <········@nifty.ne.jp> writes:
> Hi, all
>
> Is there a portable way to tell if a variable is declared special
> globally?
>
> My first shot is the following.
> (defun special-variable-p (symbol)
> (assert (symbolp symbol))
> (let ((marker (gensym)))
> (eval `(flet ((special-p ()
> (and (boundp ',symbol) (eq ,symbol ',marker))))
> (and (not (constantp ',symbol))
> (let ((,symbol ',marker))
> (special-p)))))))
> This can't distinguish whether it is declared special globally or locally.
This wouldn't be affected by local special declarations, though.
(The CLtL2 environment enquiries that Pascal Constanza mentioned
would provide information about those.)
---Vassil.
--
Vassil Nikolov <········@poboxes.com>
Hollerith's Law of Docstrings: Everything can be summarized in 72 bytes.
On Sat, 28 Aug 2004 11:48:44 -0400, Vassil Nikolov wrote:
> This wouldn't be affected by local special declarations, though.
> (The CLtL2 environment enquiries that Pascal Constanza mentioned
> would provide information about those.)
You're right. I misunderstood that point. Thanks for the correction.
Yuji.