> (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.
> (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.
use EQ.
#:Erik
--
ATTENTION, all abducting aliens! you DON'T need to RETURN them!
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.
< 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.
Guess symbol-name isn't needed afterall... My mistake.