From ff24afea7b93b382e7c79bb155de5d84bfd72fbf Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Mon, 1 Aug 2016 15:37:18 -0700 Subject: [PATCH] add funstacker & stackerizer --- beautiful-racket/br/demo/funstacker-test.rkt | 8 +++++ .../br/demo/{stacker2.rkt => funstacker.rkt} | 4 +-- beautiful-racket/br/demo/stacker2-test.rkt | 8 ----- .../br/demo/stackerizer-test copy.rkt | 2 ++ beautiful-racket/br/demo/stackerizer.rkt | 29 +++++++++++++++++++ 5 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 beautiful-racket/br/demo/funstacker-test.rkt rename beautiful-racket/br/demo/{stacker2.rkt => funstacker.rkt} (88%) delete mode 100644 beautiful-racket/br/demo/stacker2-test.rkt create mode 100644 beautiful-racket/br/demo/stackerizer-test copy.rkt create mode 100644 beautiful-racket/br/demo/stackerizer.rkt diff --git a/beautiful-racket/br/demo/funstacker-test.rkt b/beautiful-racket/br/demo/funstacker-test.rkt new file mode 100644 index 0000000..ee623d8 --- /dev/null +++ b/beautiful-racket/br/demo/funstacker-test.rkt @@ -0,0 +1,8 @@ +#lang reader br/demo/funstacker +4 +8 + ++ +3 + +* \ No newline at end of file diff --git a/beautiful-racket/br/demo/stacker2.rkt b/beautiful-racket/br/demo/funstacker.rkt similarity index 88% rename from beautiful-racket/br/demo/stacker2.rkt rename to beautiful-racket/br/demo/funstacker.rkt index 7abed0d..a672243 100644 --- a/beautiful-racket/br/demo/stacker2.rkt +++ b/beautiful-racket/br/demo/funstacker.rkt @@ -5,7 +5,7 @@ (define (read-syntax src-path in-port) (define args (port->list read in-port)) - (define module-datum `(module stacker2-mod br/demo/stacker2 + (define module-datum `(module funstacker-mod br/demo/funstacker ,@args)) (datum->syntax #f module-datum)) @@ -24,4 +24,4 @@ (module+ test (require rackunit) - (check-equal? (with-output-to-string (λ () (dynamic-require "stacker2-test.rkt" #f))) "36")) \ No newline at end of file + (check-equal? (with-output-to-string (λ () (dynamic-require "funstacker-test.rkt" #f))) "36")) \ No newline at end of file diff --git a/beautiful-racket/br/demo/stacker2-test.rkt b/beautiful-racket/br/demo/stacker2-test.rkt deleted file mode 100644 index 8498812..0000000 --- a/beautiful-racket/br/demo/stacker2-test.rkt +++ /dev/null @@ -1,8 +0,0 @@ -#lang reader br/demo/stacker2 -4 -8 - -+ -3 - -* \ No newline at end of file diff --git a/beautiful-racket/br/demo/stackerizer-test copy.rkt b/beautiful-racket/br/demo/stackerizer-test copy.rkt new file mode 100644 index 0000000..2a0a2d8 --- /dev/null +++ b/beautiful-racket/br/demo/stackerizer-test copy.rkt @@ -0,0 +1,2 @@ +#lang s-exp br/demo/stackerizer +(+ 3 (* 6 (*) 2 (+ 145 56 3 6 (* 3 56436 9)) 15 22)) \ No newline at end of file diff --git a/beautiful-racket/br/demo/stackerizer.rkt b/beautiful-racket/br/demo/stackerizer.rkt new file mode 100644 index 0000000..398d0e4 --- /dev/null +++ b/beautiful-racket/br/demo/stackerizer.rkt @@ -0,0 +1,29 @@ +#lang br/quicklang +(provide + *) + +(define-macro (stackerizer-module-begin EXPR ...) + #'(#%module-begin + (for-each displayln (reverse (flatten (list EXPR ...)))))) +(provide (rename-out [stackerizer-module-begin #%module-begin])) + +#| +(define-macro-cases * + [(*) #'1] + [(* EXPR0) #'EXPR0] + [(* EXPR0 EXPR ...) #'(list '* EXPR0 (* EXPR ...))]) + +(define-macro-cases + + [(+) #'0] + [(+ EXPR0) #'EXPR0] + [(+ EXPR0 EXPR ...) #'(list '+ EXPR0 (+ EXPR ...))]) +|# + + +(define-macro (define-op-macro OP-NAME IDENTITY-VAL) + #'(define-macro-cases OP-NAME + [(OP-NAME) #'IDENTITY-VAL] + [(OP-NAME EXPR0) #'EXPR0] + [(OP-NAME EXPR0 EXPR (... ...)) #'(list 'OP-NAME EXPR0 (OP-NAME EXPR (... ...)))])) + +(define-op-macro * 1) +(define-op-macro + 0) \ No newline at end of file