diff --git a/beautiful-racket-demo/wires-demo/main.rkt b/beautiful-racket-demo/wires-demo/main.rkt index 02fd07a..5164bff 100644 --- a/beautiful-racket-demo/wires-demo/main.rkt +++ b/beautiful-racket-demo/wires-demo/main.rkt @@ -14,12 +14,12 @@ (provide #%module-begin) (define-macro-cases wire - [(wire ARG -> WIRE) #'(define/display (WIRE) - (val ARG))] - [(wire OP ARG -> WIRE) #'(define/display (WIRE) - (OP (val ARG)))] - [(wire ARG1 OP ARG2 -> WIRE) #'(define/display (WIRE) - (OP (val ARG1) (val ARG2)))] + [(wire ARG -> ID) + #'(define/display (ID) (val ARG))] + [(wire OP ARG -> ID) + #'(wire (OP (val ARG)) -> ID)] + [(wire ARG1 OP ARG2 -> ID) + #'(wire (OP (val ARG1) (val ARG2)) -> ID)] [else #'(void)]) (provide wire) @@ -27,7 +27,7 @@ #'(begin (define (ID) BODY) (module+ main - (displayln (format "~a: ~a" 'ID (val ID)))))) + (displayln (format "~a: ~a" 'ID (ID)))))) (define val (let ([val-cache (make-hash)]) @@ -45,4 +45,4 @@ (define-16bit NOT bitwise-not) (define-16bit LSHIFT arithmetic-shift) (define (RSHIFT x y) (LSHIFT x (- y))) -(provide AND OR NOT LSHIFT RSHIFT) \ No newline at end of file +(provide AND OR NOT LSHIFT RSHIFT) diff --git a/beautiful-racket-demo/wires-demo/with-promises.rkt b/beautiful-racket-demo/wires-demo/with-promises.rkt index 7a73d24..e98f96a 100644 --- a/beautiful-racket-demo/wires-demo/with-promises.rkt +++ b/beautiful-racket-demo/wires-demo/with-promises.rkt @@ -14,20 +14,12 @@ #,@wire-datums))) (define-macro-cases wire - [(wire ARG -> WIRE) #'(define/display (WIRE) - (val ARG))] - [(wire OP ARG -> WIRE) #'(define/display (WIRE) - (OP (val ARG)))] - [(wire ARG1 OP ARG2 -> WIRE) #'(define/display (WIRE) - (OP (val ARG1) (val ARG2)))] + [(wire ARG -> WIRE) + #'(begin + (define WIRE (delay ARG)) + (module+ main + (displayln (format "promise ~a: ~a" 'WIRE (force WIRE)))))] + [(wire OP ARG -> WIRE) #'(wire (OP (force ARG)) -> WIRE)] + [(wire ARG1 OP ARG2 -> WIRE) #'(wire (OP (force ARG1) (force ARG2)) -> WIRE)] [else #'(void)]) (provide wire) - -(define-macro (define/display (WIRE) BODY) - #'(begin - (define WIRE (delay BODY)) - (module+ main - (displayln 'promises) - (displayln (format "~a: ~a" 'WIRE (val WIRE)))))) - -(define (val num-or-wire) (force num-or-wire)) \ No newline at end of file