Hello,
I've done the required Googling, and I can't find anything helpful, so here
goes:
I'm trying to find out the easiest way to 'increment' a symbol in Common
Lisp. What I am doing is building a structure of arbitrary size, and
assigning a unique letter to each node in the structure (A, B, C, ...). I
was told that there may be a way to be able to increment symbols to make
this task easier. Is there? If not, what is the simplest way to do it?
Thanks in advance,
-Geoff
From: Christopher C. Stacy
Subject: Re: can I increment a symbol?
Date:
Message-ID: <u3cepie5m.fsf@dtpq.com>
>>>>> On Mon, 22 Sep 2003 03:36:50 GMT, Geoff McGee ("Geoff") writes:
Geoff> What I am doing is building a structure of arbitrary size, and
Geoff> assigning a unique letter to each node in the structure (A, B,
Geoff> C, ...). I was told that there may be a way to be able to
Geoff> increment symbols to make this task easier.
You might consider GENSYM.
Hi Geoff McGee,
> I've done the required Googling, and I can't find anything helpful, so here
> goes:
>
> I'm trying to find out the easiest way to 'increment' a symbol in Common
> Lisp. What I am doing is building a structure of arbitrary size, and
> assigning a unique letter to each node in the structure (A, B, C, ...). I
> was told that there may be a way to be able to increment symbols to make
> this task easier. Is there? If not, what is the simplest way to do it?
You may not want to do what you think you want to do.
(loop for c from (char-code #\a) to (char-code #\z)
collect (intern (string (code-char c))))
(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)
Note how the string "a" became the symbol A. To 'increment' a symbol
build strings and then turn them into symbols.
Regards,
Adam
Adam Warner <······@consulting.net.nz> writes:
> (loop for c from (char-code #\a) to (char-code #\z)
> collect (intern (string (code-char c))))
>
> (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)
>
> Note how the string "a" became the symbol A.
I get |a| here. Have you tweaked READTABLE-CASE, or something?
Hi Kalle Olavi Niemitalo,
>> (loop for c from (char-code #\a) to (char-code #\z)
>> collect (intern (string (code-char c))))
>>
>> (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)
>>
>> Note how the string "a" became the symbol A.
>
> I get |a| here. Have you tweaked READTABLE-CASE, or something?
Oops. (setf (readtable-case *readtable*) :invert) is in my startup
scripts. And my description is incorrect. The symbol name is still a
lowercase a. It's just that the case gets inverted when printed and
read back in.
(eq 'A '|a|) => true
Regards,
Adam
"Adam Warner" <······@consulting.net.nz> wrote in message
···································@consulting.net.nz...
> Hi Kalle Olavi Niemitalo,
>
> >> (loop for c from (char-code #\a) to (char-code #\z)
> >> collect (intern (string (code-char c))))
> >>
> >> (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)
> >>
> >> Note how the string "a" became the symbol A.
> >
> > I get |a| here. Have you tweaked READTABLE-CASE, or something?
>
> Oops. (setf (readtable-case *readtable*) :invert) is in my startup
> scripts. And my description is incorrect. The symbol name is still a
> lowercase a. It's just that the case gets inverted when printed and
> read back in.
>
> (eq 'A '|a|) => true
Note that in ANSI Common Lisp without playing with the readtable:
CL-USER 12 > (intern "a")
\a
:INTERNAL
CL-USER 13 > (intern "A")
A
:INTERNAL
CL-USER 14 > (eq 'a '|a|)
NIL
The above, from LW4.1, is as it should be.
--
Coby Beck
(remove #\Space "coby 101 @ big pond . com")