counts number in a list

You have problems, and we're glad to hear them. Explain the problem, what you have tried, and where you got stuck.
Feel free to share a little info on yourself and the course.
Forum rules
Please respect your teacher's guidelines. Homework is a learning tool. If we just post answers, we aren't actually helping. When you post questions, be sure to show what you have tried or what you don't understand.
Post Reply
Ehsan
Posts: 8
Joined: Thu Jul 12, 2012 7:39 am

counts number in a list

Post by Ehsan » Thu Jul 12, 2012 7:44 am

Hi every one

I need a function count numbers in a list for example
(count-numbers '(3 4 5 a b c d 6 ) ) -> 4

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: counts number in a list

Post by Goheeca » Fri Jul 13, 2012 8:31 am

You can use the loop macro (search for a count clause) with a numberp predicate.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

nuntius
Posts: 538
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

Re: counts number in a list

Post by nuntius » Fri Jul 13, 2012 9:04 am

let, dolist, incf, and numberp would also work.

A recursive helper function could be used to eliminate the let, dolist, and incf; some classes prefer recursive solutions.

Ehsan
Posts: 8
Joined: Thu Jul 12, 2012 7:39 am

Re: counts number in a list

Post by Ehsan » Sat Jul 14, 2012 12:12 am

Tnxxxxxxxxxxxxxxxxxxxxxxxx

Post Reply