From: William Kupersanin
Subject: neophyte question about atoms
Date:
Message-ID: <4g5opd$c2d@hecate.umd.edu>
Is there a way to test atoms to see if their name contains a specific
character? That is, I want to write a function that returns true if
the atom that is passed to it contains the letter X in its name. Is it
do-able? Thanks for any advice you can provide.
-- Willie
In article <··········@hecate.umd.edu>,
William Kupersanin <·····@csc.umd.edu> wrote:
>Is there a way to test atoms to see if their name contains a specific
I suspect you mean "symbols", not "atoms", since most other kinds of atoms
(such as numbers and arrays) don't really have names.
>character? That is, I want to write a function that returns true if
>the atom that is passed to it contains the letter X in its name. Is it
>do-able? Thanks for any advice you can provide.
Here's a simple implementation:
(defun symbol-contains-char (symbol char)
(find char (symbol-name symbol) :test #'char-equal))
If you really *did* mean atom, not just symbol, the following should work:
(defun thing-contains-char (thing char)
(find char (write-to-string thing) :test #'char-equal))
I wrote "thing" instead of "atom" because this function actually works for
any object, not just atoms, because it uses a completely general function
to convert the object to a string.
--
Barry Margolin
BBN PlaNET Corporation, Cambridge, MA
······@bbnplanet.com
Phone (617) 873-3126 - Fax (617) 873-6351
In article <··········@hecate.umd.edu>,
·····@csc.umd.edu (William Kupersanin) wrote:
>
>
>Is there a way to test atoms to see if their name contains a specific
>character? That is, I want to write a function that returns true if
>the atom that is passed to it contains the letter X in its name. Is it
>do-able? Thanks for any advice you can provide.
>
>-- Willie
>
>
This should be easy to accomplish. How about:
((MEMBER 'X (UNPACK WORD)))
If this statement is included in the body of a COND, you should be able to
branch as you desire, and take the appropriate action. For example:
(COND ((MEMBER 'X (UNPACK WORD))
(PRINT '|THE TEST WORD CONTAINS THE TEST CHARACTER|))
(T (PRINT '|THE TEST WORD DOES NOT CONTAIN THE TEST CHARACTER|)))
To make this statement more general, you would probably want to pass it the
letter and word as parameters. Naturally, 'X would become X, where X is now a
parameter that corresponds to the letter that you are looking for. Let me
know how this turns out.
·······@phoenix.net