# [plt-scheme] Processing lists

 From: Matthias Felleisen (matthias at ccs.neu.edu) Date: Thu Mar 5 22:26:57 EST 2009 Previous message: [plt-scheme] Processing lists Next message: [plt-scheme] Processing lists Messages sorted by: [date] [thread] [subject] [author]

```Improve your examples. Write them as proper function calls. Rewrite
them as tests then:

(check-expect (f 1 2 3) 4)

On Mar 5, 2009, at 9:30 PM, aditya shukla wrote:

> 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 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 (+( 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)
>                               (cond
>                                 [(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.
>