Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Need help: Symbol comparison?

116 views
Skip to first unread message

tranchin

unread,
Sep 19, 1998, 3:00:00 AM9/19/98
to
Hi Everyone,
I have a question in comparing two symbols as follows:

> (setf a '(a b c d))
(A B C D)
> (char> (elt a 1) (elt a 2))
....some error messages....

Since (elt a 1) returns SYMBOL and char> is used to compare only characters.
I have no idea how I can compare these two symbols. I tried to find conversion
functions in case I can convert them to other types and compare, but still
cannot find it. Would you please give me suggestion in doing this?
Thank you in advance,
Pisut T.

tranchin

unread,
Sep 19, 1998, 3:00:00 AM9/19/98
to
Hi All,
I have a question how to compare two symbols as follows:

> (setf a '(a b c d))
(A B C D)
> (char> (elt a 1) (elt a 2))

...some error messages...

Since (elt a 1) returns SYMBOL and char> is used to compare only characters.
I have no idea how I can compare these two symbols. I tried to find conversion

functions in case I can conver them to other types and compare, but still
cannot find it. Would you please give me suggestion in doing this.

Erik Naggum

unread,
Sep 19, 1998, 3:00:00 AM9/19/98
to
* tran...@nunki.usc.edu (tranchin)

| I have a question in comparing two symbols as follows:

use EQ.

#:Erik
--
ATTENTION, all abducting aliens! you DON'T need to RETURN them!

Barry Margolin

unread,
Sep 19, 1998, 3:00:00 AM9/19/98
to
In article <6u0om4$olc$1...@nunki.usc.edu>,

The following will probably do what you want:

(string> (elt a 1) (elt a 2))

The string functions are required to accept symbols, and automatically use
the symbol's name. To get precisely what you asked for, though, would
require:

(char> (char (symbol-name (elt a 1))) (char (symbol-name (elt a 2))))

--
Barry Margolin, bar...@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.

Steve Gonedes

unread,
Sep 19, 1998, 3:00:00 AM9/19/98
to

tran...@nunki.usc.edu (tranchin) writes:


< Hi Everyone,
< I have a question in comparing two symbols as follows:


<
< > (setf a '(a b c d))
< (A B C D)
< > (char> (elt a 1) (elt a 2))

< ....some error messages....


<
< Since (elt a 1) returns SYMBOL and char> is used to compare only characters.

< I have no idea how I can compare these two symbols. I tried to find

< conversion functions in case I can convert them to other types and


< compare, but still cannot find it. Would you please give me

< suggestion in doing this? Thank you in advance, Pisut T.

Use `eq' to see if the symbols are the same; to do lexicographic
comparison you will have to use the names of the symbols.

(symbol-name 'ONE) => "ONE"

(let ((z '(a b c)))
(string< (symbol-name (nth 0 z)) (symbol-name (nth 1 z))))

The function `nth' is like elt, except specific for lists. It is
unfortunate that the number comes first; such is life I guess.

You should not modify the result of symbol-name (just a side note).

There is the function coerce for changing the type of some object but
should probably be used sparingly. Thought that you might find it
interesting.

(character (symbol-name 'a)) => #\A
(character (symbol-name '|a|)) => #\a ; the `|' preserves case
(string #\A) => "A"

(coerce '(#\a #\b #\c) 'string) => "abc"
(coerce "abc" 'list) => (#\a #\b #\c)
(coerce '(one #\e "one") 'vector) => #(ONE #\e "one")
(coerce '(1 2 3) '(simple-array (integer 1 3) (3))) => #(1 2 3)
(coerce '(lambda () (+ 2 3)) 'function) => #<Function (anonymous) ...>

Pretty neat, but probably a very expensive operation. Hope you enjoyed
the trivia. Have fun.

Steve Gonedes

unread,
Sep 20, 1998, 3:00:00 AM9/20/98
to

Steve Gonedes <jgon...@worldnet.att.net> writes:

< (symbol-name 'ONE) => "ONE"
<
< (let ((z '(a b c)))
< (string< (symbol-name (nth 0 z)) (symbol-name (nth 1 z))))

Guess symbol-name isn't needed afterall... My mistake.

0 new messages