From e2df4fee70ae34ce02b98187316594d593edec91 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Tue, 30 Aug 2016 12:28:22 -0700 Subject: [PATCH] update func expander --- beautiful-racket/br/demo/bf/bf-expander.rkt | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/beautiful-racket/br/demo/bf/bf-expander.rkt b/beautiful-racket/br/demo/bf/bf-expander.rkt index 458d26d..b744172 100644 --- a/beautiful-racket/br/demo/bf/bf-expander.rkt +++ b/beautiful-racket/br/demo/bf/bf-expander.rkt @@ -5,22 +5,24 @@ PARSE-TREE)) (provide (rename-out [bf-module-begin #%module-begin])) +(define (fold-funcs apl bf-funcs) + (for/fold ([current-apl apl]) + ([bf-func (in-list bf-funcs)]) + (apply bf-func current-apl))) + (define-macro (bf-program OP-OR-LOOP-ARG ...) - #'(void (fold-args (list (make-vector 30000 0) 0) - OP-OR-LOOP-ARG ...))) + #'(begin + (define first-apl (list (make-vector 30000 0) 0)) + (void (fold-funcs first-apl (list OP-OR-LOOP-ARG ...))))) (provide bf-program) -(define (fold-args apl . bf-args) - (for/fold ([current-apl apl]) - ([bf-arg (in-list bf-args)]) - (apply bf-arg current-apl))) - (define-macro (loop "[" OP-OR-LOOP-ARG ... "]") #'(lambda (arr ptr) (for/fold ([current-apl (list arr ptr)]) ([i (in-naturals)] - #:break (zero? (apply current-byte apl))) - (fold-args current-apl OP-OR-LOOP-ARG ...)))) + #:break (zero? (apply current-byte + current-apl))) + (fold-funcs current-apl (list OP-OR-LOOP-ARG ...))))) (provide loop) (define-macro-cases op