From f021c09f2566cc0ca506c2c478972f1be29f1eec Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Mon, 14 Nov 2016 11:27:46 -0800 Subject: [PATCH] touchup --- beautiful-racket/br/demo/wires/expander.rkt | 18 ++++++------------ beautiful-racket/br/demo/wires/main.rkt | 5 +++-- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/beautiful-racket/br/demo/wires/expander.rkt b/beautiful-racket/br/demo/wires/expander.rkt index 45fd4cb..58f2253 100644 --- a/beautiful-racket/br/demo/wires/expander.rkt +++ b/beautiful-racket/br/demo/wires/expander.rkt @@ -24,18 +24,12 @@ num-or-wire (hash-ref! wire-cache num-or-wire num-or-wire))))) -(define (mod-16bit x) - (define max-16bit (expt 2 16)) - (define remainder (modulo x max-16bit)) - (if (not (negative? remainder)) - remainder - (mod-16bit (+ max-16bit remainder)))) - +(define 16bit-max (expt 2 16)) (define-macro (define-16bit ID+ARGS BODY) - #'(define ID+ARGS (mod-16bit BODY))) + #'(define ID+ARGS (modulo BODY 16bit-max))) -(define-16bit (AND arg1 arg2) (bitwise-and arg1 arg2)) -(define-16bit (OR arg1 arg2) (bitwise-ior arg1 arg2)) -(define-16bit (LSHIFT arg1 arg2) (arithmetic-shift arg1 arg2)) -(define-16bit (RSHIFT arg1 arg2) (arithmetic-shift arg1 (- arg2))) +(define-16bit (AND x y) (bitwise-and x y)) +(define-16bit (OR x y) (bitwise-ior x y)) +(define-16bit (LSHIFT x y) (arithmetic-shift x y)) +(define-16bit (RSHIFT x y) (LSHIFT x (- y))) (define-16bit (NOT arg) (bitwise-not arg)) \ No newline at end of file diff --git a/beautiful-racket/br/demo/wires/main.rkt b/beautiful-racket/br/demo/wires/main.rkt index 2ff7d3b..8e643ca 100644 --- a/beautiful-racket/br/demo/wires/main.rkt +++ b/beautiful-racket/br/demo/wires/main.rkt @@ -3,8 +3,9 @@ (provide read-syntax)) (define (read-syntax path port) - (define wire-strs (port->lines port)) - (define wire-datums (format-datums '(wire ~a) wire-strs)) + (define wire-datums + (for/list ([wire-str (in-lines port)]) + (format-datum '(wire ~a) wire-str))) (strip-context #`(module wires-mod br/demo/wires/expander #,@wire-datums))) \ No newline at end of file