[plt-scheme] Processing lists

 From: aditya shukla (adityashukla1983 at gmail.com) Date: Thu Mar 5 19:13:03 EST 2009 Previous message: [plt-scheme] self-referential data structures Next message: [plt-scheme] Processing lists Messages sorted by: [date] [thread] [subject] [author]

```i am trying to solve a problem which is to find out number of occurrence of
a symbol in list of symbols.

;question in a given list find out how many times  a symbol occurs in the
list.
;contract : fun-with-lists s-list * symbol -> number
;purpose : this function takes an s-list and a symbol as input and finds out
how many times the symbol occurs in the list.
;examples 'a -> () =0 , ('a) =1 , ('b) = 0 , ('b 'c 'a 'a) = 2 , ('b 'c 'd)
=0
;template (define fun-with-lists (lambda s-list sym) (cond [(empty? s-list)]
[ else (first s-list) fun-with-lists(rest s-list])))
(define fun-with-lists (lambda (s-list sym )
(cond
[(empty? s-list) 0]
[else (cond
[(symbol=? (first s-list) sym ) 1]

[else (fun-with-lists (rest s-list) sym
)])])))

I got to this far using the recipe explained in htdp.I am stuck at the point
where i can't increment the occurrence of a symbol .Can someone give me a
hint.