• Support PF! Buy your school textbooks, materials and every day products Here!

Common Lisp Counting problem

  • Thread starter Kamekui
  • Start date
  • #1
14
0

Homework Statement



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.

Homework Equations



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

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

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?
 

Answers and Replies

Related Threads for: Common Lisp Counting problem

  • Last Post
Replies
1
Views
1K
  • Last Post
Replies
1
Views
1K
  • Last Post
Replies
1
Views
3K
  • Last Post
Replies
3
Views
5K
  • Last Post
Replies
7
Views
293
Replies
3
Views
786
  • Last Post
Replies
2
Views
760
Top