From: Ravi Kolli
Subject: Lisp -- Pl. help.
Date: 
Message-ID: <1994Jul24.203804.68965@kuhub.cc.ukans.edu>
Hi Friends!! I am working on a project of mine and i am having a hard time
to determine two things.  It would be great if someone could help me 
with this.

1). to determine if each element of a list is character or not.
2). to determine if each element of a list is a number or not.

I understand that i can use characterp and numberp respectively for one 
element of the list. But i am unable to determine how to do the same for 
each element of the list. Any help/suggestions will be appreciated.

ThankQ

rkolli.

······@jefferson.engr.ukans.edu

From: Adam Alpern
Subject: Re: Lisp -- Pl. help.
Date: 
Message-ID: <ala-2407942135030001@el_diente.cs.colorado.edu>
In article <······················@kuhub.cc.ukans.edu>, ······@tisl.ukans.edu (Ravi Kolli) wrote:

;; to determine two things.  It would be great if someone could help me 
;; with this.
;; 
;; 1). to determine if each element of a list is character or not.
;; 2). to determine if each element of a list is a number or not.
;; 

As with most things in Lisp, this can be done in a number of ways.
One easy way is like this:

? (find-if #'(lambda (item) (not (numberp item))) '(1 2 3 4 a))
a
? (find-if #'(lambda (item) (not (numberp item))) '(1 2 3 4 6))
nil

or substitue characterp to check if each item is a character.

the function find-if takes a function as it's first argument, and a 
sequence (a list is a sequence) as it's second argument. The function
passed as the first argument to find-if should take one argument, and 
return nil if the item does not satisfy whatever it is you are checking for.

In the example above, find-if will return nil if every element in the
list satisfies the test, that is, *is* a number. If the test returns 
t (or any non-nil value) for any item in the list, find-if will
return that item. In the first example, it returned the symbol a, 
because does not satisfy numberp.

Hope this helps!

Adam

-- 
Adam Alpern. HCC Group, University of Colorado at Boulder
···@cs.colorado.edu
···@neural.hampshire.edu
From: Marco Antoniotti
Subject: Re: Lisp -- Pl. help.
Date: 
Message-ID: <MARCOXA.94Jul25111954@mosaic.nyu.edu>
In article <····················@el_diente.cs.colorado.edu> ···@cs.colorado.edu (Adam Alpern) writes:


   From: ···@cs.colorado.edu (Adam Alpern)
   Newsgroups: comp.lang.lisp
   Date: Sun, 24 Jul 1994 21:35:03 -0700
   Organization: University of Colorado, Boulder
   Lines: 38
   References: <······················@kuhub.cc.ukans.edu>

   In article <······················@kuhub.cc.ukans.edu>, ······@tisl.ukans.edu (Ravi Kolli) wrote:

   ;; to determine two things.  It would be great if someone could help me 
   ;; with this.
   ;; 
   ;; 1). to determine if each element of a list is character or not.
   ;; 2). to determine if each element of a list is a number or not.
   ;; 

   As with most things in Lisp, this can be done in a number of ways.
   One easy way is like this:

   ? (find-if #'(lambda (item) (not (numberp item))) '(1 2 3 4 a))
   a
   ? (find-if #'(lambda (item) (not (numberp item))) '(1 2 3 4 6))
   nil

Even if this is a homework project, an easier way is

? (every #'characterp '(1 2 3 4 #\x))
nil

? (every #'characterp '(#\a #\s #\d))
t

? (some #'numberp '(1 2 3 4 #\x))
t

? (some #'caracterp "asd")
t

Happy Lisping

--
Marco Antoniotti - Resistente Umano
-------------------------------------------------------------------------------
Robotics Lab		| room: 1220 - tel. #: (212) 998 3370
Courant Institute NYU	| e-mail: ·······@cs.nyu.edu

...e` la semplicita` che e` difficile a farsi.
...it is simplicity that is difficult to make.
				Bertholdt Brecht
From: Peter Dudey
Subject: Re: Lisp -- Pl. help. (each item in a list)
Date: 
Message-ID: <DUDEYP.94Jul25102712@hume.cs.orst.edu>
In article <····················@el_diente.cs.colorado.edu> ···@cs.colorado.edu (Adam Alpern) writes:

   ? (find-if #'(lambda (item) (not (numberp item))) '(1 2 3 4 a))
   a
   ? (find-if #'(lambda (item) (not (numberp item))) '(1 2 3 4 6))
   nil

Or, equivalently,

(find-if-not #'numberp '(1 2 3 4 a))

-- 
; Peter Dudey, MS student in Artificial Intelligence, Oregon State University ;
; ······@research.cs.orst.edu | hagbard on IGS | 257 NE 13th, Salem, OR 97301 ;
;      My cubicle and desk don't fulfill my need for tabulatory gigantism.    ;
;       NOTICE:  As of August 20, 1994, I will become Peter Dudey Drake.      ;
From: Adam Alpern
Subject: Re: Lisp -- Pl. help. (each item in a list)
Date: 
Message-ID: <ala-2507941330310001@el_diente.cs.colorado.edu>
In article <····················@hume.cs.orst.edu>, ······@hume.cs.orst.edu (Peter Dudey) wrote:
···@cs.colorado.edu (Adam Alpern) writes:
;; 
;;    ? (find-if #'(lambda (item) (not (numberp item))) '(1 2 3 4 a))

;; Or, equivalently,
;; 
;; (find-if-not #'numberp '(1 2 3 4 a))
;; 

Or, conversely,

(every #'numberp '(1 2 3 4 a))

-- 
Adam Alpern. HCC Group, University of Colorado at Boulder
···@cs.colorado.edu
···@neural.hampshire.edu
From: DANIEL CORKILL
Subject: Re: Lisp -- Pl. help.
Date: 
Message-ID: <30vt7j$hqv@opine.cs.umass.edu>
>Hi Friends!! I am working on a project of mine and i am having a hard time
>to determine two things.  It would be great if someone could help me 
>with this.
>
>1). to determine if each element of a list is character or not.
>2). to determine if each element of a list is a number or not.
>
>I understand that i can use characterp and numberp respectively for one 
>element of the list. But i am unable to determine how to do the same for 
>each element of the list. Any help/suggestions will be appreciated.

Some, every, and friends may be what you're looking for.....