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.

counts number in a list

Postby 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
Ehsan
 
Posts: 8
Joined: Thu Jul 12, 2012 7:39 am

Re: counts number in a list

Postby 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).
User avatar
Goheeca
 
Posts: 220
Joined: Thu May 10, 2012 12:54 pm

Re: counts number in a list

Postby 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.
User avatar
nuntius
 
Posts: 500
Joined: Sat Aug 09, 2008 10:44 am
Location: Burlington, MA

Re: counts number in a list

Postby Ehsan » Sat Jul 14, 2012 12:12 am

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


Return to Homework

Who is online

Users browsing this forum: No registered users and 2 guests