Characters and symbols are two different data types. In this case, #\a is a character and a is a symbol. It appears that what you are really asking is: How can I check if the car of my list is a symbol whose print name is a string of length 1? This is one way to do it:
my-characterp would have to be modified to handle lists (i.e. (mycharacterp '(a b c)) won't work). Using a function such as my-characterp is a bad idea anyway; I recommend instead that you familiarize yourself with the various Lisp data types (e.g. characters, strings, symbols, etc.) and then determine which data type is best suited for the problem at hand.
* Divya wrote: > Show me the light! > If I try: > (characterp #\a) then I get T > How do I do the same for: > (setq temp '(a b c d)) > (characterp (car temp)) gives me NIL. > How can I check if the car or my list is a character or not?
On Thu, 4 Nov 1999 23:18:21 -0500, "Divya" <ra...@frontiernet.net> wrote:
: I need to know if the car of this list is a character. How can I check : this? : : (defun my-func (list) : (cond : ((characterp (car list)) (do-something))
That function actually does what you _say_ you want it to do. That is, if LIST is '(#\c) then
(characterp (car list))
will return T.
Be sure you understand the difference between a character and a symbol in Lisp parlance. If you want your test to give T when LIST is '(c), then you are not looking for characters:
(characterp #\c) => T (characterp 'c) => NIL (symbolp #\c) => NIL (symbolp 'c) => T
(setq x #\c) => #\c (characterp x) => T (symbolp x) => NIL
(setq y 'c) => C (characterp y) => NIL (symbolp y) => T
But take into account that:
(symbolp 'i-am-a-symbol) => T
Also, a hint on style: if the flow depends on a unique predicate as in your code, WHEN is the natural choice.
I received some critique from some smart-asses too. I don't think I am doing bad for a 2 day old LISP programmer and I will ignore this critique from, probably LISP programmers of 40 years, for whom the basic concepts are second nature.
sigh. <capitoline-7vo0b2/INN-2.2.1/accr...@broadway.news.is-europe.net>, posted on 1999-11-03 01:40:55+01, contained your promise to _end_ your particular line of lunatic ravings, and I answered your questions in the spirit of that promise. you promised, and I quote your very words:
| But all right. This is my last response to you. You may response once | and I shall read your response and I shall not answer any more. So | please do not talk to me again (bur for your last response).
I am not particularly surprised that you can't even keep simple promises, but can you AT THE VERY LEAST PLEASE SHUT UP?
I am very sorry but I think that you answered my posting on Russian mental power AFTER our "final" messages. And my posting about Russian mental power had really nothing to with you and was not in any way offending you.
So it was you who started again. But I did not mind. I admit I was angry of you but I am not angry any more. I have forgiven you, dear Eric.
J.B.
Erik Naggum <e...@naggum.no> schrieb in im Newsbeitrag: 3150883876078...@naggum.no...
> posted on 1999-11-03 01:40:55+01, contained your promise to _end_ your > particular line of lunatic ravings, and I answered your questions in the > spirit of that promise. you promised, and I quote your very words:
> | But all right. This is my last response to you. You may response once > | and I shall read your response and I shall not answer any more. So > | please do not talk to me again (bur for your last response).
> I am not particularly surprised that you can't even keep simple promises, > but can you AT THE VERY LEAST PLEASE SHUT UP?
> I received some critique from some smart-asses too. I don't think > I am doing bad for a 2 day old LISP programmer and I will ignore > this critique from, probably LISP programmers of 40 years, for whom > the basic concepts are second nature.
No biggie. Symbols are not the most intutive thing for someone moving from other computer languages. You're doing fine.