Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to search for an atom in another atom

1 view
Skip to first unread message

Christian Soltenborn

unread,
Jan 25, 2004, 5:53:32 PM1/25/04
to
Hi folks,

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

Paul Rubin

unread,
Jan 25, 2004, 5:56:12 PM1/25/04
to
Christian Soltenborn <no_spam_c...@webmail.de> writes:
> 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?

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"

Wade Humeniuk

unread,
Jan 25, 2004, 6:05:07 PM1/25/04
to

CL-USER 3 > (find 'x (string 'xyz) :test 'string=)
#\X

CL-USER 4 > (find 'a (string 'xyz) :test 'string=)
NIL

CL-USER 5 >

Wade

Rahul Jain

unread,
Jan 25, 2004, 7:43:45 PM1/25/04
to
Christian Soltenborn <no_spam_c...@webmail.de> writes:

> 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

Wade Humeniuk

unread,
Jan 25, 2004, 9:20:07 PM1/25/04
to
Wade Humeniuk wrote:

>
> 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

0 new messages