[plt-scheme] Processing lists

From: aditya shukla (adityashukla1983 at gmail.com)
Date: Thu Mar 5 21:30:09 EST 2009

Thanks for the help guys , I did it like this.

;question in a given list find out how many times  a symbol occurs in the
;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)
;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 )
                           [(empty? s-list) 0]
                           [else (+( more-fun-with-lists(first s-list) sym)
( fun-with-lists(rest s-list) sym))])))

;contract more-fun with lists (symbol * symbol -> number)
;purpose : this function returns 1 if the (first s-list) = sym otherwise 0
(define more-fun-with-lists (lambda (sym1 sym2)
                                [(symbol=? sym1 sym2) 1]
                                [else 0])))

Earlier i was thinking of having  a counter which i would increment whenever
an occurrence is found  .Any suggestions on how to think in more of a
functional paradigm.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20090305/9a2cfc03/attachment.html>

Posted on the users mailing list.