Newsgroups: comp.lang.scheme,comp.lang.lisp,comp.lang.misc,comp.lang.prolo
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!newsfeed.pitt.edu!gatech!news.mathworks.com!nntp.primenet.com!tank.news.pipex.net!pipex!oleane!jussieu.fr!math.ohio-state.edu!usc!news.isi.edu!gremlin!shomase!jbarnett
From: jbarnett@shomase.NoSubdomain.NoDomain (Jeff Barnett)
Subject: Re: Function to count the members in a list
Message-ID: <Dut7uB.5I0@gremlin.nrtc.northrop.com>
Sender: news@gremlin.nrtc.northrop.com (Usenet News Manager)
Reply-To: jbarnett@charming.nrtc.northrop.com
Organization: Northrop Automation Sciences Laboratory
References: <31DCD117.172F@tick.infomatik.uni-stuttgart.de> <19960717132319UDSD065@DSIBM.OKLADOT.STATE.OK.US>
Date: Fri, 19 Jul 1996 21:32:34 GMT
Lines: 28
Xref: glinda.oz.cs.cmu.edu comp.lang.scheme:16196 comp.lang.lisp:22108 comp.lang.misc:26302

In article <19960717132319UDSD065@DSIBM.OKLADOT.STATE.OK.US>, UDSD065@DSIBM.OKLADOT.STATE.OK.US writes:
|> 
|> Hi all,
|> 
|>   I am new to this news group. I am writing a small program that would
|> take a list and an atom as an argument and return the number of times th
|> e atom is in the list:
|>      eg:(foo '(a b c a r) '(a))                                         rmany
|>             -> 2.
|> Is there a built-in function that would count the number of elements the
|> atom has so that I would use a loop and use that number as my required
|> iteration?

Sure.  Try (count 'a '(a b c a r)).

Jeff

PS I suggest that you get a lisp manual and spend some of your spare
time looking through it.  It will help you build a few intuitions:
(1) if you want to do "foo", see if there is a function named "foo"
around--there often is, (2) any time you have an item and a
sequence (list or vector) as arguments, guess that the item is the
first argument and the sequence is the second, and (3) virtually all
search and ``is it there'' problems have builtins to solve them.
As you learn the language, pay particular attention to the things
documented along with member, find, assoc, and the like.  Also, read
about their optional keyword arguments and do some experimenting.
Good luck.
