[plt-scheme] Processing lists

From: Richard Cleis (rcleis at mac.com)
Date: Thu Mar 5 20:47:51 EST 2009

Maybe you are thinking of 'incrementing' something, just like I used  
to do.  Instead, think of it as: "I want to add one to the amount I  
find in the rest of the list", or "I don't want to add anything to the  
amount I find in the rest of the list."

rac


On Mar 5, 2009, at 5:13 PM, aditya shukla wrote:

> 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
>
>
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.