From 57522a1be93616807b20803453a1acf05795bf5a Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sun, 16 Jun 2019 16:37:21 -0700 Subject: [PATCH] read, expand, conjunction --- .../conjunction-demo/main.rkt | 27 +++++++++++++++++++ .../conjunction-demo/test.rkt | 4 +++ .../expand-only-demo/main.rkt | 14 ++++++++++ .../expand-only-demo/test.rkt | 4 +++ beautiful-racket-demo/read-only-demo/main.rkt | 13 +++++++++ beautiful-racket-demo/read-only-demo/test.rkt | 4 +++ 6 files changed, 66 insertions(+) create mode 100644 beautiful-racket-demo/conjunction-demo/main.rkt create mode 100644 beautiful-racket-demo/conjunction-demo/test.rkt create mode 100644 beautiful-racket-demo/expand-only-demo/main.rkt create mode 100644 beautiful-racket-demo/expand-only-demo/test.rkt create mode 100644 beautiful-racket-demo/read-only-demo/main.rkt create mode 100644 beautiful-racket-demo/read-only-demo/test.rkt diff --git a/beautiful-racket-demo/conjunction-demo/main.rkt b/beautiful-racket-demo/conjunction-demo/main.rkt new file mode 100644 index 0000000..ec83bf1 --- /dev/null +++ b/beautiful-racket-demo/conjunction-demo/main.rkt @@ -0,0 +1,27 @@ +#lang br/quicklang + +(module reader br + (provide read-syntax) + (define (read-syntax name port) + (define s-exprs (let loop ([toks null]) + (define tok (read port)) + (if (eof-object? tok) + (reverse toks) + (loop (cons tok toks))))) + (strip-bindings + (with-syntax ([(EXPR ...) s-exprs]) + #'(module read-only-mod conjunction-demo + EXPR ...))))) + +(define (convert-expr x) + (let loop ([x x]) + (cond + [(list? x) (map loop x)] + [(number? x) 42] + [(string? x) "whee"] + [else 'kaboom]))) + +(define-macro (dsl-module-begin EXPR ...) + #'(#%module-begin + (convert-expr 'EXPR) ...)) +(provide (rename-out [dsl-module-begin #%module-begin])) diff --git a/beautiful-racket-demo/conjunction-demo/test.rkt b/beautiful-racket-demo/conjunction-demo/test.rkt new file mode 100644 index 0000000..4930d78 --- /dev/null +++ b/beautiful-racket-demo/conjunction-demo/test.rkt @@ -0,0 +1,4 @@ +#lang conjunction-demo + +"hello world" +(+ 1 (* 2 (- 3))) \ No newline at end of file diff --git a/beautiful-racket-demo/expand-only-demo/main.rkt b/beautiful-racket-demo/expand-only-demo/main.rkt new file mode 100644 index 0000000..91a4023 --- /dev/null +++ b/beautiful-racket-demo/expand-only-demo/main.rkt @@ -0,0 +1,14 @@ +#lang br + +(define (convert-expr x) + (let loop ([x x]) + (cond + [(list? x) (map loop x)] + [(number? x) 42] + [(string? x) "whee"] + [else 'kaboom]))) + +(define-macro (dsl-module-begin EXPR ...) + #'(#%module-begin + (convert-expr 'EXPR) ...)) +(provide (rename-out [dsl-module-begin #%module-begin])) diff --git a/beautiful-racket-demo/expand-only-demo/test.rkt b/beautiful-racket-demo/expand-only-demo/test.rkt new file mode 100644 index 0000000..a50e12f --- /dev/null +++ b/beautiful-racket-demo/expand-only-demo/test.rkt @@ -0,0 +1,4 @@ +#lang s-exp expand-only-demo + +"hello world" +(+ 1 (* 2 (- 3))) \ No newline at end of file diff --git a/beautiful-racket-demo/read-only-demo/main.rkt b/beautiful-racket-demo/read-only-demo/main.rkt new file mode 100644 index 0000000..73bfd14 --- /dev/null +++ b/beautiful-racket-demo/read-only-demo/main.rkt @@ -0,0 +1,13 @@ +#lang br +(module reader br + (provide read-syntax) + (define (read-syntax name port) + (define s-exprs (let loop ([toks null]) + (define tok (read port)) + (if (eof-object? tok) + (reverse toks) + (loop (cons tok toks))))) + (strip-bindings + (with-syntax ([(EXPR ...) s-exprs]) + #'(module read-only-mod racket + EXPR ...))))) \ No newline at end of file diff --git a/beautiful-racket-demo/read-only-demo/test.rkt b/beautiful-racket-demo/read-only-demo/test.rkt new file mode 100644 index 0000000..3966d68 --- /dev/null +++ b/beautiful-racket-demo/read-only-demo/test.rkt @@ -0,0 +1,4 @@ +#lang read-only-demo + +"hello world" +(+ 1 (* 2 (- 3))) \ No newline at end of file