From: tranchin
Subject: Need help: Symbol comparison?
Date: 
Message-ID: <6u0odr$ocr$1@nunki.usc.edu>
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.

From: Erik Naggum
Subject: Re: Need help: Symbol comparison?
Date: 
Message-ID: <3115214732803047@naggum.no>
* ········@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!
From: Steve Gonedes
Subject: Re: Need help: Symbol comparison?
Date: 
Message-ID: <m290jgvu24.fsf@KludgeUnix.com>
········@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.
From: Steve Gonedes
Subject: Re: Need help: Symbol comparison?
Date: 
Message-ID: <m2d88ry4dy.fsf@KludgeUnix.com>
Steve Gonedes <········@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.