[racket] Advice: simulating stateful API in functional setting

From: Nadeem Abdul Hamid (nadeem at acm.org)
Date: Fri Jul 15 15:24:47 EDT 2011

On Fri, Jul 15, 2011 at 2:56 PM, Stephen Bloch <sbloch at adelphi.edu> wrote:

> The problem is that some sprite actions (most obviously, "move" when you're
> in pen-down mode) affect not only the sprite itself but the world's picture.
>  So far the least-bad solution I've come up with is to hide a mutation of
> that picture inside the otherwise-functional "move" function.
>
>
 Why don't you just have the picture generated based on the state of the
sprite each tick of the animation, just as in HtDP "world"? Functions like
move, rotate, etc. produce a modified sprite, and when that sprite gets
passed to the draw handler, the draw handler produces a new image of the
world based on that state.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110715/de840550/attachment.html>

Posted on the users mailing list.