From: Pillsy
Subject: Symbols, symbol names, packages and exporting: which to use?
Date: 
Message-ID: <1166461307.150142.84220@73g2000cwn.googlegroups.com>
So, I've recently been doing a lot of macrology, and along the way I've
discovered that I spend a lot of time writing things like this:

(mapcar #'(lambda (form)
	    (destructuring-bind (a b c) form
	      (declare (ignore b))
	      `(,c :for ,a))) a-bunch-of-forms)

I've learned you can do similar things with LOOP that are similar and
more concise, but I sort of hate LOOP, and even if I didn't, sometimes
the MAPCAR is buried inside another function that is passed the
anonymous as an argument, or pulls it out of an alist or something. So
I wrote a macro so that I could whip up that sort of lambda form more
conveniently:

(defmacro restruct (arglist template)
  (let ((dummies ()))
    (labels
	((uniquify (tree)
	   (cond ((null tree) nil)
		 ((and (symbolp tree)
		       (string= (symbol-name tree) "?"))
		  (let ((dummy (gensym)))
		    (push dummy dummies)
		    dummy))
		 ((atom tree) tree)
		 (t (cons (uniquify (car tree)) (uniquify (cdr tree)))))))
      (with-unique-names (list)
	`(lambda (,list)
	   (dbind ,(uniquify arglist) ,list
	     (declare (ignore ,@dummies))
	     ,template))))))

The only part that involves work is that part at the beginning
(UNIQUIFY) where I scan ARGLIST for instances of the symbol ?, replace
them with gensyms and ignore the gensyms. At first, I checked to see if
the symbol in question was EQL to '?, but that didn't work when I
exported RESTRUCT. That's why I use SYMBOL-NAME. I could just export ?
(but that seems like it's just begging for trouble) or I could restrict
myself to a keyword like :? which seems mostly harmless (a bit more
typing). I have a gut feeling  SYMBOL-NAME is the wrong thing, but I
have no idea why, and maybe it isn't the wrong thing.

What do you do in situations like this? Or in situations where you use
_ as an implicit variable in abbreviate syntax for anonymous functions?
Is my gut telling me the wrong thing about looking at the symbol's
name?

Thanks,
Matt

From: Tim Bradshaw
Subject: Re: Symbols, symbol names, packages and exporting: which to use?
Date: 
Message-ID: <1166462360.576308.260290@j72g2000cwa.googlegroups.com>
Pillsy wrote:

>
> What do you do in situations like this? Or in situations where you use
> _ as an implicit variable in abbreviate syntax for anonymous functions?
> Is my gut telling me the wrong thing about looking at the symbol's
> name?

I think it's fine.  LOOP must do this for its `keywords' for instance,
and we all know that whatever LOOP does *must* be right, right?

(seriously, I do think it's fine).

--tim
From: Pillsy
Subject: Re: Symbols, symbol names, packages and exporting: which to use?
Date: 
Message-ID: <1166577223.686322.12720@73g2000cwn.googlegroups.com>
Tim Bradshaw wrote:
> Pillsy wrote:

> > What do you do in situations like this? Or in situations where you use
> > _ as an implicit variable in abbreviate syntax for anonymous functions?
> > Is my gut telling me the wrong thing about looking at the symbol's
> > name?

> I think it's fine.  LOOP must do this for its `keywords' for instance,
> and we all know that whatever LOOP does *must* be right, right?

> (seriously, I do think it's fine).

That's a good point, so I'll leave it the way it is.

Cheers, Pillsy
From: Harold
Subject: Re: Symbols, symbol names, packages and exporting: which to use?
Date: 
Message-ID: <1166480035.466711.106290@j72g2000cwa.googlegroups.com>
Pillsy wrote:
>
> The only part that involves work is that part at the beginning
> (UNIQUIFY) where I scan ARGLIST for instances of the symbol ?, replace
> them with gensyms and ignore the gensyms. At first, I checked to see if
> the symbol in question was EQL to '?, but that didn't work when I
> exported RESTRUCT. That's why I use SYMBOL-NAME. I could just export ?
> (but that seems like it's just begging for trouble) or I could restrict
> myself to a keyword like :? which seems mostly harmless (a bit more
> typing). I have a gut feeling  SYMBOL-NAME is the wrong thing, but I
> have no idea why, and maybe it isn't the wrong thing.
>
> What do you do in situations like this? Or in situations where you use
> _ as an implicit variable in abbreviate syntax for anonymous functions?
> Is my gut telling me the wrong thing about looking at the symbol's
> name?
>

My gut agrees with your gut. Here's a pathological example of why:

* (let ((x (make-symbol "?"))
        (y (make-symbol "?")))
    (eq x y))

NIL
*

Both symbols have the same name, but are different symbols. This makes
your code look more attractive at first glance, but knowing that the
symbol to symbol name mapping is this flexible worries me.

A lot of Lisp code I've seen recently seems to favor the :? solution,
but I think exporting ? is just fine. If someone is using your package,
they'll import RESTRUCT and ? together. And if ? would conflict with a
different ?, you'll get the usual choices about shadowing it, etc.
From: Harald Hanche-Olsen
Subject: Re: Symbols, symbol names, packages and exporting: which to use?
Date: 
Message-ID: <pco4prser4f.fsf@shuttle.math.ntnu.no>
+ "Harold" <·······@gmail.com>:

| My gut agrees with your gut. Here's a pathological example of why:
|
| * (let ((x (make-symbol "?"))
|         (y (make-symbol "?")))
|     (eq x y))
|
| Nil
| *

(What implementation prints NIL that way?  Oh, never mind ...)

| Both symbols have the same name, but are different symbols. This makes
| your code look more attractive at first glance, but knowing that the
| symbol to symbol name mapping is this flexible worries me.

Just comparing them with string= will make the problem go away.

Note that string= is defined to act on string designators, which are
not the same as strings.  They include symbols.

(string= :foo "FOO")  =>  t

-- 
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- It is undesirable to believe a proposition
  when there is no ground whatsoever for supposing it is true.
  -- Bertrand Russell
From: John Thingstad
Subject: Re: Symbols, symbol names, packages and exporting: which to use?
Date: 
Message-ID: <op.tksakrj4pqzri1@pandora.upc.no>
On Tue, 19 Dec 2006 00:11:44 +0100, Harald Hanche-Olsen  
<······@math.ntnu.no> wrote:

>
> (string= :foo "FOO")  =>  t
>

(string= (symbol-name :foo) "FOO")

seems better..

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
From: John Thingstad
Subject: Re: Symbols, symbol names, packages and exporting: which to use?
Date: 
Message-ID: <op.tksam1kkpqzri1@pandora.upc.no>
On Tue, 19 Dec 2006 03:01:29 +0100, John Thingstad  
<··············@chello.no> wrote:

> On Tue, 19 Dec 2006 00:11:44 +0100, Harald Hanche-Olsen  
> <······@math.ntnu.no> wrote:
>
>>
>> (string= :foo "FOO")  =>  t
>>
>
> (string= (symbol-name :foo) "FOO")
>
> seems better..
>

try it with ACL with string sensitive lower.

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
From: John Thingstad
Subject: Re: Symbols, symbol names, packages and exporting: which to use?
Date: 
Message-ID: <op.tksa1vm5pqzri1@pandora.upc.no>
On Tue, 19 Dec 2006 03:02:51 +0100, John Thingstad  
<··············@chello.no> wrote:

> On Tue, 19 Dec 2006 03:01:29 +0100, John Thingstad  
> <··············@chello.no> wrote:
>
>> On Tue, 19 Dec 2006 00:11:44 +0100, Harald Hanche-Olsen  
>> <······@math.ntnu.no> wrote:
>>
>>>
>>> (string= :foo "FOO")  =>  t
>>>
>>
>> (string= (symbol-name :foo) "FOO")
>>
>> seems better..
>>
>
> try it with ACL with string sensitive lower.
>

so (equal (symbol-name :foo) "foo")

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
From: John Thingstad
Subject: Re: Symbols, symbol names, packages and exporting: which to use?
Date: 
Message-ID: <op.tksa5tn1pqzri1@pandora.upc.no>
On Tue, 19 Dec 2006 03:11:45 +0100, John Thingstad  
<··············@chello.no> wrote:

> On Tue, 19 Dec 2006 03:02:51 +0100, John Thingstad  
> <··············@chello.no> wrote:
>
>> On Tue, 19 Dec 2006 03:01:29 +0100, John Thingstad  
>> <··············@chello.no> wrote:
>>
>>> On Tue, 19 Dec 2006 00:11:44 +0100, Harald Hanche-Olsen  
>>> <······@math.ntnu.no> wrote:
>>>
>>>>
>>>> (string= :foo "FOO")  =>  t
>>>>
>>>
>>> (string= (symbol-name :foo) "FOO")
>>>
>>> seems better..
>>>
>>
>> try it with ACL with string sensitive lower.
>>
>
> so (equal (symbol-name :foo) "foo")
>

no (equalp (symbol-name :foo) "foo")


-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
From: Thomas A. Russ
Subject: Re: Symbols, symbol names, packages and exporting: which to use?
Date: 
Message-ID: <ymir6uuidjm.fsf@sevak.isi.edu>
"John Thingstad" <··············@chello.no> writes:

> On Tue, 19 Dec 2006 03:11:45 +0100, John Thingstad
> <··············@chello.no> wrote:
> > On Tue, 19 Dec 2006 03:02:51 +0100, John Thingstad
> > <··············@chello.no> wrote:
> >> On Tue, 19 Dec 2006 03:01:29 +0100, John Thingstad
> >> <··············@chello.no> wrote:
> >>> On Tue, 19 Dec 2006 00:11:44 +0100, Harald Hanche-Olsen
> >>> <······@math.ntnu.no> wrote:
> >>>>
> >>>> (string= :foo "FOO")  =>  t
> >>>>
> >>>
> >>> (string= (symbol-name :foo) "FOO")
> >>>
> >>> seems better..
> >>>
> >>
> >> try it with ACL with string sensitive lower.
> >>
> >
> > so (equal (symbol-name :foo) "foo")
> >
> 
> no (equalp (symbol-name :foo) "foo")

(string-equal 'foo "foo")

Also, for the OP:

  (string= '? :?)

works fine, since there aren't any case sensitivity issues.

-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Pascal Bourguignon
Subject: Re: Symbols, symbol names, packages and exporting: which to use?
Date: 
Message-ID: <877iwo8wwc.fsf@thalassa.informatimago.com>
"John Thingstad" <··············@chello.no> writes:

> On Tue, 19 Dec 2006 00:11:44 +0100, Harald Hanche-Olsen
> <······@math.ntnu.no> wrote:
>
>>
>> (string= :foo "FOO")  =>  t
>>
>
> (string= (symbol-name :foo) "FOO")
>
> seems better..

Yes, but it's useless.  string= takes string designators.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

"What is this talk of "release"?  Klingons do not make software
"releases".  Our software "escapes" leaving a bloody trail of
designers and quality assurance people in its wake."
From: John Thingstad
Subject: Re: Symbols, symbol names, packages and exporting: which to use?
Date: 
Message-ID: <op.tksckuq2pqzri1@pandora.upc.no>
On Tue, 19 Dec 2006 03:03:31 +0100, Pascal Bourguignon  
<···@informatimago.com> wrote:

> "John Thingstad" <··············@chello.no> writes:
>
>> On Tue, 19 Dec 2006 00:11:44 +0100, Harald Hanche-Olsen
>> <······@math.ntnu.no> wrote:
>>
>>>
>>> (string= :foo "FOO")  =>  t
>>>
>>
>> (string= (symbol-name :foo) "FOO")
>>
>> seems better..
>
> Yes, but it's useless.  string= takes string designators.
>

CL-USER 1 > (type-of (symbol-name :foo))
SIMPLE-BASE-STRING

CL-USER 2 > (type-of "FOO")
SIMPLE-BASE-STRING

CL-USER 3 > (string= (symbol-name :foo) "FOO")
T


-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
From: Bill Atkins
Subject: Re: Symbols, symbol names, packages and exporting: which to use?
Date: 
Message-ID: <m27iwo61hn.fsf@bertrand.local>
"John Thingstad" <··············@chello.no> writes:

> On Tue, 19 Dec 2006 03:03:31 +0100, Pascal Bourguignon
> <···@informatimago.com> wrote:
>
>> "John Thingstad" <··············@chello.no> writes:
>>
>>> On Tue, 19 Dec 2006 00:11:44 +0100, Harald Hanche-Olsen
>>> <······@math.ntnu.no> wrote:
>>>
>>>>
>>>> (string= :foo "FOO")  =>  t
>>>>
>>>
>>> (string= (symbol-name :foo) "FOO")
>>>
>>> seems better..
>>
>> Yes, but it's useless.  string= takes string designators.
>>
>
> CL-USER 1 > (type-of (symbol-name :foo))
> SIMPLE-BASE-STRING
>
> CL-USER 2 > (type-of "FOO")
> SIMPLE-BASE-STRING
>
> CL-USER 3 > (string= (symbol-name :foo) "FOO")
> T

and 

CL-USER 4 > (string= :foo "FOO")
T

What are you getting at?  It's hardly our fault that you've turned on
"modern mode."
From: John Thingstad
Subject: Re: Symbols, symbol names, packages and exporting: which to use?
Date: 
Message-ID: <op.tksdc4dmpqzri1@pandora.upc.no>
On Tue, 19 Dec 2006 03:52:36 +0100, Bill Atkins  
<························@not-a-real-domain.com> wrote:

> CL-USER 4 > (string= :foo "FOO")
> T
>
> What are you getting at?  It's hardly our fault that you've turned on
> "modern mode."

Actually that is LispWorks with case insensitive upper case.
My point is that equalp works either way and that (symbol-name :symbol) is  
cleaner.
You can't use case to distinguish symbols in this case of cource, but then  
you should
never rely on this in portable code.

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
From: Harald Hanche-Olsen
Subject: Re: Symbols, symbol names, packages and exporting: which to use?
Date: 
Message-ID: <pcok60o5n9j.fsf@shuttle.math.ntnu.no>
+ "John Thingstad" <··············@chello.no>:

| On Tue, 19 Dec 2006 03:52:36 +0100, Bill Atkins
| <························@not-a-real-domain.com> wrote:
|
|> CL-USER 4 > (string= :foo "FOO")
|> T
|>
|> What are you getting at?  It's hardly our fault that you've turned on
|> "modern mode."
|
| Actually that is LispWorks with case insensitive upper case.
| My point is that equalp works either way and that (symbol-name
| :symbol) is  cleaner.

Cleaner how?

In any case, I get that you're worried about case.  My example of
(string= :foo "FOO") was perhaps not well chosen if taken as an
example of good coding (it was merely meant to illustrate the fact
that string= will work on symbols).  (string= symbol #:foo) might have
been better, or use string-equal if you wish to ignore case.

-- 
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- It is undesirable to believe a proposition
  when there is no ground whatsoever for supposing it is true.
  -- Bertrand Russell
From: Tim Bradshaw
Subject: Re: Symbols, symbol names, packages and exporting: which to use?
Date: 
Message-ID: <1166530679.613355.148940@48g2000cwx.googlegroups.com>
Bill Atkins wrote:

> What are you getting at?  It's hardly our fault that you've turned on
> "modern mode."

He hasn't.  But the point is, I think, that you need to write these
things slightly carefully in libraries because there will be people who
use odd reader modes (and odd symbol cases) who might want to use your
code.  You might elect not to care about such people, of course.

I think the basic trick is to use something like (symbol-name
#:name-of-interest) in code and make sure this doesn't get compiled
away.  But I forget the details.