[plt-scheme] HtDP

From: Marco Morazan (morazanm at gmail.com)
Date: Mon Jul 7 19:04:27 EDT 2008

On Mon, Jul 7, 2008 at 6:11 PM, dave yrueta <dyrueta at gmail.com> wrote:
>
> (define(fold f th lox)
>  (cond
>    [(empty? lox)th]
>    [else
>     (f (first lox)
>        (fold f th (rest lox)))]))
>

What is the contract for fold?

>
> (define(mapp2 f lox)
>  (fold (cons f) empty lox))
>
> This won't work, because (cons f) is not a legitimate expression.  I
> started work on next problem in the meantime, and that seems even more
> puzzling, so I feel like there is some basic concept about abstraction
> that I'm not getting.  Any suggestions?
>

Here's where a contract is going to be useful for you. What does fold
expect as arguments? Certainly, (cons f) is not something fold is
expecting as its first argument.

Cheers,

Marco


Posted on the users mailing list.