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

From: Rodolfo Carvalho (rhcarvalho at gmail.com)
Date: Mon May 30 23:57:27 EDT 2011

It seems to me that the Design Recipe should come into play.
Try to think what's the relation between the solution for a list of
length n and one of length n-1.

[]s

On 2011-05-30, Matthias Felleisen <matthias at ccs.neu.edu> wrote:
>
> 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
>
>
> _________________________________________________
>   For list-related administrative tasks:
>   http://lists.racket-lang.org/listinfo/dev
>

-- 
Sent from my mobile device

Rodolfo Carvalho


Posted on the dev mailing list.