On Aug 24, 2015, at 2:32 PM, John Carmack <jo...@oculus.com> wrote: > The idea that you functionally compose images like this: > > (place-image image-1 x y > (place-image image-2 x y > (place-image image-3 x y))) > > Which draws image1 on top of image2 on top of image 3, which is backwards > from the "painters order" that would draw image 3, then image 2, then image 1. > > This imperative, side-effect-ing code is a little less clear to a beginner > with the OOP and DC concepts, but It better represents what actually happens, > and it is much easier to modify the code without worrying about the nesting. > > (send dc draw-bitmap imag3 x y) > (send dc draw-bitmap imag2 x y) > (send dc draw-bitmap imag1 x y)
This is a serious wart, but I didn't expect that when I read "backwards." In HtDP/ISL, I use [1] You can develop s0 ... s3 at the top-level, when you like them you esc-k, ctrl-y place them into a local: (define (render.v1 w) (local ((define s0 (empty-scene 100 100)) (define s1 (place-image (circle 30 'solid 'yellow) 5 20 s0)) (define s2 (place-image (rectangle 10 20 'solid 'blue) 90 90 s1)) (define s3 (place-image (triangle 100 'solid 'red) 90 10 s2))) s3)) [2] Or you can use let* as someone else pointed out (define (render.v2 w) (let* ((s (empty-scene 100 100)) (s (place-image (circle 30 'solid 'yellow) 5 20 s)) (s (place-image (rectangle 10 20 'solid 'blue) 90 90 s)) (s (place-image (triangle 100 'solid 'red) 90 10 s))) s)) [3} But my favorite is this, when i try to explain kids abstraction and the advantage of having values around instead of effects: (define (render.v3 w) (foldr (lambda (x s) (apply place-image- s x)) background pieces)) [4] We do need a for/image so that #lang racket programmers can do even better. ;; --- somewhere else: (define background (empty-scene 100 100)) (define pieces `((,(circle 30 'solid 'yellow) ,(rectangle 10 20 'solid 'blue) ,(triangle 100 'solid 'red)))) -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.