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?
Thanks in advance.
Suppose the input to my function is a list.
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))
..........
)
But this check for "characterp" gives me false.
Thanks again.
Divya <ra...@frontiernet.net> wrote in message
news:7vtie4$15lg$1...@node17.cwnet.frontiernet.net...
(defun my-characterp (sym)
(equal 1 (length (symbol-name sym))))
which gives (under CMU Common Lisp):
* (my-characterp 'abc)
NIL
* (my-characterp 'a)
T
* (my-characterp (car '(a b c)))
T
* (my-characterp (car '(abc b c)))
NIL
*
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.
Regards,
Jim Driese
> Show me the light!
*fwap* (hits divya on the head with a lamp)
> 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?
You just did.
(a b c d) is a list of SYMBOLS.
(#\a #\b #\c #\d) is a list of CHARACTERS.
-matt
* R. Matthew Emerson
| *fwap* (hits divya on the head with a lamp)
hmmm... "lampda -- the ultimate source of light"
#:Erik, who fears he's about to be hit, too :)
characterp will return a true(T) or false(NIL) value.
In your example, a in '(a b c d) is not a character! It's called
"Symbol" so characterp
returns nil.
If you try your example with '(#\a #\b #\c #\d) you will get true when
you call characterp
with the list.
- jwc
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?
>
> Thanks in advance.
> 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?
Like that. It's not a character, it's a symbol!
(characterp (car '(#\a #\b))) -> T
--tim
with CHARACTERP or (TYPEP <whatever> 'CHARACTER).
| But this check for "characterp" gives me false.
then you don't have a character. how hard can this be to understand?
why don't you ask your real question, which ought to be very close to
"what are characters in Common Lisp?"
#:Erik
: 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.
-- Shin
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.
Divya
Divya <ra...@frontiernet.net> wrote in message
news:7vtlom$118c$1...@node17.cwnet.frontiernet.net...
> Sorry. Maybe I should have been more clear.
>
> Suppose the input to my function is a list.
>
> 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))
> ..........
>
> )
>
> But this check for "characterp" gives me false.
>
> Thanks again.
>
>
> Divya <ra...@frontiernet.net> wrote in message
> news:7vtie4$15lg$1...@node17.cwnet.frontiernet.net...
> > 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?
> >
> > Thanks in advance.
> >
> >
>
>
I am getting jelaous now! Please shoot at me! AT ME! You do need anybody
else when you have ME!
But to be serious: It is probably possible to alter the READER so that I can
define, what a "charcter" means. Hm?
Erik Naggum <er...@naggum.no> schrieb in im Newsbeitrag:
31507978...@naggum.no...
> * "Divya" <ra...@frontiernet.net>
> | I need to know if the car of this list is a character. How can I check
> | this?
>
> with CHARACTERP or (TYPEP <whatever> 'CHARACTER).
>
> | But this check for "characterp" gives me false.
>
sigh. <capitoline-7vo0b2/INN-2.2.1/acc...@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?
#:Erik
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 <er...@naggum.no> schrieb in im Newsbeitrag:
31508838...@naggum.no...
Divya wrote:
> Thank you all for your answers.
>
> 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.
dave