1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Common Lisp Counting problem

  1. Mar 26, 2013 #1
    1. The problem statement, all variables and given/known data

    Write a function (count s x) that searches a data structure composed of pairs
    (arbitarily nested) for a symbol x and returns the number of times it occurs.

    2. Relevant equations

    Assuming you have the correct function written, you should get the following:

    (count '((a . b) b c () a . d) a) should return 2.

    3. The attempt at a solution

    I don't really know much about lisp, we just started talking about it. I do know how to write a very basic counting function, that just counts every element in a list:

    (defun count-elements(L)
    (cond ((null l) 0)
    ((atom l) 1)
    (t (+ (count-elements (car l))
    (count-elements (cdr l))))))

    So, how would I pick out a specific element in my list?
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted

Similar Discussions: Common Lisp Counting problem
  1. 2 Counting problems (Replies: 1)