[plt-scheme] Processing lists

From: Marc L. Smith (mlsmith at cs.vassar.edu)
Date: Thu Mar 5 21:17:38 EST 2009

Hi Aditya,

The template gives you all the functions available to you for each  
possible case of data. It is up to you, in using the template, to  
compose those functions in a way that solves the problem you are  
trying to solve. The template does not specify how many times you will  
need to use all the functions that are available. Sometimes a function  
may be available, and you won't need to use it at all; sometimes you  
will need to use a function one or more times...

I notice you return the value 1 when the list is not empty, and the  
first symbol in the list is equal to the symbol whose occurrences  
you're counting. What about the occurrences of the symbol that may be  
in the rest of the list?

Hope this helps,


On Mar 5, 2009, at 7:13 PM, plt-scheme-request at list.cs.brown.edu wrote:

Date: Thu, 5 Mar 2009 18:13:03 -0600
From: aditya shukla <adityashukla1983 at gmail.com>
Subject: [plt-scheme] Processing lists
To: PLT Scheme ML <plt-scheme at list.cs.brown.edu>
	<73045cca0903051613g21c496afic8962d3957d1e3a5 at mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

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  
;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- 
[ else (first s-list) fun-with-lists(rest s-list])))
(define fun-with-lists (lambda (s-list sym )
                           [(empty? s-list) 0]
                           [else (cond
                                   [(symbol=? (first s-list) sym ) 1]

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

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


Posted on the users mailing list.