[plt-scheme] HTDP 21.1.2 - trying to put it together

From: Chris Warrington (chrisw at rice.edu)
Date: Sat Jul 15 23:00:51 EDT 2006

wooks . @ 2006-7-15 7:52:12 PM
"[plt-scheme] HTDP 21.1.2 - trying to put it together" <mid:BAY103-F568FFDE8392B4A82B38C1C06C0 at phx.gbl>


> ;fold (A [listof Y] -> [listof Y])  [listof Y] [listof A] -> [listof Y]
> thus far defining map in terms of fold gives us

> (define (map f a-list)
>    (fold someFunc empty a-list))

> Now to define someFunc.

> Well its contract must conform to

> ;someFunc: X [listof Y] -> [listof Y]

All of what you've said so far looks good to me.

> If we plug in Y for X and consider that Y is supposed to result from 
> applying  (the function we are mapping) to X
> then someFunc begins to look like this

> (define (someFunc f aloy)
>    (..... f ..... (first aloy)  (rest aloy))

> where f is a function with a contract

> (X -> Y)

> To produce a list as required by the contract  we have to use cons 
> somewhere.


> I would have said

> (define (someFunc f aloy)
>     (cons (f first aloy) (rest aloy)))

> but it's not right - is it.

What's the contract of someFunc now? Does it match (A [listof Y] ->
[listof Y])?

If you look at someFunc's contract, it is very close, but needs to be
"flattened" (I'm not sure if that's technically the correct word.). Is
there some way to flatten it?

Chris Warrington <chrisw at rice.edu>

If a vegetarian eats vegetables, what does a humanitarian eat?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 185 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20060715/972326bd/attachment.sig>

Posted on the users mailing list.