Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion portable detection of special symbols?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
RG  
View profile  
 More options Apr 24 2011, 3:29 am
Newsgroups: comp.lang.lisp
From: RG <rNOSPA...@flownet.com>
Date: Sun, 24 Apr 2011 00:29:15 -0700
Local: Sun, Apr 24 2011 3:29 am
Subject: Re: portable detection of special symbols?
In article <87zkngf99q....@kuiper.lan.informatimago.com>,
 "Pascal J. Bourguignon" <p...@informatimago.com> wrote:

> D Herring <dherr...@at.tentpost.dot.com> writes:

> > Special Operator SYMBOL-MACROLET:
> > "symbol-macrolet signals an error if a special declaration names one
> > of the symbols being defined by symbol-macrolet"

> > Is there a better way not requiring the cltl2 environment interface?

> So far, we have:

> (defun specialp (symbol)
>   "Detects whether the symbol has been declared special."
>   (and (symbolp symbol)
>        (cond
>         ((constantp symbol) nil)
>         ((not (eql symbol (macroexpand symbol))) nil)
>         (t (handler-bind ((warning (function muffle-warning)))
>              (eval `(flet ((f () ,symbol))
>                       (let ((,symbol t))
>                         (not (nth-value 1 (ignore-errors (f))))))))))))

> (defvar a 1)
> (defconstant c 2)
> (define-symbol-macro sa a)
> (define-symbol-macro sb b)
> (define-symbol-macro sc c)
> (define-symbol-macro sd d)
> (define-symbol-macro se 42)

> (values
>  (funcall (compile nil (lambda ()
>                            (let ((b 1))
>                              (declare (special b))
>                              (list (specialp 'a)  (specialp 'b)
>                                    (specialp 'c)  (specialp 'd)
>                                    (specialp 'sa) (specialp 'sb)
>                                    (specialp 'sc) (specialp 'sd)
>                                    (specialp 'se))))))
>  (list (specialp 'a)  (specialp 'b)
>        (specialp 'c)  (specialp 'd)
>        (specialp 'sa) (specialp 'sb)
>        (specialp 'sc) (specialp 'sd)
>        (specialp 'se)))

> ;; (T T   NIL NIL NIL NIL NIL NIL NIL)
> ;; (T NIL NIL NIL NIL NIL NIL NIL NIL)

> I claim that SPECIALP is conforming, and any implementation not giving
> the same results on any symbol is not conforming.

Then CCL, CLisp and SBCL are all non-conforming:

Welcome to Clozure Common Lisp Version 1.7-dev-r14715M-trunk  
(DarwinX8664)!
? (defun specialp (symbol)
  "Detects whether the symbol has been declared special."
  (and (symbolp symbol)
       (cond
        ((constantp symbol) nil)
        ((not (eql symbol (macroexpand symbol))) nil)
        (t (handler-bind ((warning (function muffle-warning)))
             (eval `(flet ((f () ,symbol))
                      (let ((,symbol t))
                        (not (nth-value 1 (ignore-errors (f))))))))))))
SPECIALP
? (setf (symbol-value 'x) 1)
1
? (specialp 'x)
T
? (flet ((f () x)) (let ((x 2)) (f)))
;Compiler warnings :
;   In F inside an anonymous lambda form: Undeclared free variable X
;   In an anonymous lambda form at position 17: Unused lexical variable X
1

I won't bother to post the transcripts from CLisp and SBCL, the results
are the same.

rg


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.