I just started to learn Lisp, and I have a small question: I have to
write a function which checks if an atom is contained in another atom.
For example:
>(setf expr 'xyz)
XYZ
> (checkp 'x expr)
T
>(checkp 'a expr)
NIL
Unfortunately I have no clue how I can access the single "chars" of an
atom. And it is kind of hard to find this information if you don't know
for which function to search. Could somebody give me a hint?
Thanks in advance,
Christian
You've been reading docs from the ancient days of Lisp. It's not
normal to use symbols as strings any more. Most Lisps have a string
datatype. But if you really want to get out the name of a symbol,
use
(symbol-name 'xyz) => "xyz"
CL-USER 3 > (find 'x (string 'xyz) :test 'string=)
#\X
CL-USER 4 > (find 'a (string 'xyz) :test 'string=)
NIL
CL-USER 5 >
Wade
> I just started to learn Lisp, and I have a small question: I have to
> write a function which checks if an atom is contained in another
> atom.
An atom is to be treated atomically. Note that the term "atom" is an
anacrhonism. Structures are "atoms", as are arrays.
It seems that you're trying to see if some substring of a symbol name is
the name of another symbol. Why not use strings from the start if you're
doing a substring search? You can use the wonderful sequences library
that is provided by all Lisp implementations to do your searching. E.g.,
you might want to look at POSITION, FIND, and SUBSEQ.
--
Rahul Jain
rj...@nyct.net
Professional Software Developer, Amateur Quantum Mechanicist
>
> CL-USER 3 > (find 'x (string 'xyz) :test 'string=)
> #\X
>
> CL-USER 4 > (find 'a (string 'xyz) :test 'string=)
> NIL
>
> CL-USER 5 >
If I have not totally screwed you up, the hint should be
CL-USER 4 > (search (string 'a) (string 'abc) :test 'string=)
0
CL-USER 5 > (search (string 'x) (string 'abc) :test 'string=)
NIL
CL-USER 6 >
Wade