[plt-scheme] Processing lists
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.
Aditya
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20090305/22e78775/attachment.html>