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

From: Yingjian Ma (yingjian.ma1955 at gmail.com)
Date: Mon May 30 19:17:36 EDT 2011

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))]
     [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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/dev/archive/attachments/20110530/8ede648e/attachment.html>

Posted on the dev mailing list.