Hi, <div><br>I thought I'd try a simple GUI app using the world/universe mutation-free approach, but trying to implement the 'world/universe' program design myself.<br><br>I've got my little sketch below, but I quickly came to conclusion that while I could use the teachpack, I don't know how to achieve the teachpack functionality myself.<br>
<br>I'm guessing I should use continuations, but that doesn't seem to be the approach in the universe.rkt source.<br><br>I could always just stuff the program into the canvas class, (as earlier games like slidey and same seem to do), but I really want to get a handle on how to implement the 'world/universe' style of program control.<br>
<br>Any suggestons would be appreciated.<br><br>Kind regards,<br><br>Stephen<br><br><br>;;;;----<br><span style="font-family:courier new,monospace">#lang racket/gui<br><br>; simple drawing program<br>; mousedown starts recording a list of points<br>
; mousechanged starts recording a new list<br>; paint callback paints the list of lists as lines.<br><br style="font-family:courier new,monospace"></span><span style="font-family:courier new,monospace">(define diagramframe (new frame% [label "paint"] [width 300] [height 300] [x 1000][y 300]))</span><br style="font-family:courier new,monospace">
<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">;(define lines '(((0 . 0) (0 . 300) (250 . 250) (150 . 176))))</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">(define lines '(((0 . 0) (0 . 300) (250 . 250) (150 . 176)) </span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> ((10 . 4) (280 . 10))))</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">(define paintcanvas% </span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> (class canvas%</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> (init-field mouse-event-callback)</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> (super-new)</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> (define dc (send this get-dc))</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> (define/override (on-event mouse-event)</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> (mouse-event-callback mouse-event))))</span><br style="font-family:courier new,monospace">
<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">(define (paint-cb c dc) </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> (for-each (λ (line) (send dc draw-lines line)) lines))</span><br style="font-family:courier new,monospace">
<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">(define (me-cb mouse-event)</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> (let ((x (send mouse-event get-x))</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> (y (send mouse-event get-y)))</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> (when (and (send mouse-event get-left-down)</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> (send mouse-event moving?))</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> (if (send mouse-event button-changed?)</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> ; if true append as new list</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> '() </span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> ; if false append existing list</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> '())))</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> )</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">(define Paintcanvas (new paintcanvas% </span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> [parent diagramframe]</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> [paint-callback paint-cb]</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> [mouse-event-callback me-cb]))</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">(define (main world)</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> (when world (main (??? world)))</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> (send diagramframe show #t))</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">(main lines)</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">(send diagramframe show #t)</span><br style="font-family:courier new,monospace"><br>;;-----<br><span></span></div>