[racket-dev] Please help me to fix the code

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Mon May 30 19:29:08 EDT 2011

On May 30, 2011, at 7:17 PM, Yingjian Ma wrote:

> Hi All,
> I wrote a piece of code to count the occurrance of a letter in a list.  But it gave me an error saying "#<procedure:...uments..."
> The code is below:
> (define (count-matches s l)
>       (cond
>      [(empty? l) 0]    
>      [(equal? s (first l)) (lambda (i)(+ i 1))]

What's this lambda doing here? 

>      [else (count-matches s (rest l))]))
> Where the s is a letter and l is a list.  To use it as an example, I typed
> (count-matches 'f '(f )) 
> and got the error.  The right result should be 1.
> Do I need to initialize i?  If so, how can I do it?
> Note that the keywords that I can use are pretty much used in the code.  If the solution needs keywords outside this post, it may not be useful to me.
> Thank you very much.   
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/dev

Posted on the dev mailing list.