You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
beautiful-racket/beautiful-racket-demo/wires-demo/with-promises.rkt

33 lines
954 B
Racket

6 years ago
#lang br/quicklang
(require "main.rkt")
(provide (all-from-out "main.rkt"))
(module+ reader
(provide read-syntax))
(define (read-syntax path port)
(define wire-datums
(for/list ([wire-str (in-lines port)])
(format-datum '(wire ~a) wire-str)))
(strip-bindings
#`(module wires-mod wires-demo/with-promises
#,@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)))]
[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))