[racket] Questions about the Canvas

From: Stephen Bloch (bloch at adelphi.edu)
Date: Wed Jun 13 16:11:26 EDT 2012

On Jun 13, 2012, at 3:16 PM, Hillary Ryan wrote:

> Why does this work?
> (define canvas (new canvas% [parent window] [paint-callback (lambda (canvas dc) (draw canvas dc))]))
> 
> But this doesn't
> (define canvas (new canvas% [parent window] [paint-callback  (draw canvas dc)]))
> 
> It seems that in both cases the paint-callback is being set to a 2-arity procedure.

No, "(draw canvas dc)" is the RESULT of a 2-arity procedure.  "draw" (no parentheses, no arguments) would be a 2-arity procedure, equivalent to "(lambda (canvas dc) (draw canvas dc))".

> However, in the second case the window doesn't update unless draw is called from REPL.

Yes, that's because you're only calling draw once, at the time you define canvas.



Stephen Bloch
sbloch at adelphi.edu



Posted on the users mailing list.