character Comparison

0 views
Skip to first unread message

Rainer Joswig

unread,
Feb 20, 2000, 3:00:00 AM2/20/00
to
In article <mZLr4.9509$_e7.3...@news1.sshe1.sk.home.com>, "Chris H"
<newsgro...@NOJUNKhome.com> wrote:

> Hi all,
> I am a newbie in lisp programming ...

Make sure you have a Common Lisp reference handy.
The ANSI CL standard is available in a hypertextified
version. Another source of wisdom is CLtL2 (Common Lisp
the Language, 2nd edition) - also available as hypertext.
For more information about Lisp visit http://www.lisp.org .

> and
> I have a question on doing character comparison
> eg
>
> how do I check if character 'a' is in word 'banada'
>
> is any thing like substring() function ?


FIND item sequence &key :from-end :test :test-not :start
:end :key
[Function]
returns the first element in the specified portion of sequence that
matches item according to test, or nil if no element matches.


? (find #\a "BANANA" :test #'char=)
NIL

Rainer Joswig, ISION Internet AG, Harburger Schlossstraße 1,
21079 Hamburg, Germany, Tel: +49 40 77175 226
Email: rainer...@ision.de , WWW: http://www.ision.de/

Erik Naggum

unread,
Feb 20, 2000, 3:00:00 AM2/20/00
to
* "Chris H" <newsgro...@NOJUNKhome.com>

| how do I check if character 'a' is in word 'banada'
|
| is any thing like substring() function ?

yes. FIND, POSITION, SEARCH, CHAR, SUBSEQ, etc.

note that most operations on characters and strings in Common Lisp are
simply special cases of operations on elements and sequences. many
C-based programmers are frustrated because they think that Common Lisp
has few string-handling functions. Common Lisp has few string-only
functions, so remember to look for sequence and array functions, too.

#:Erik

Erann Gat

unread,
Feb 22, 2000, 3:00:00 AM2/22/00
to

As long as we're on the subject, what is the best way to iterate over
a string/sequence? (map nil ... s)? (dotimes (i (length s)) ...
(char s i) ...)?

E.

Reply all
Reply to author
Forward
0 new messages