From 04b52e473e5692a08fbf3faae435cf3a8a289f18 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Wed, 1 Mar 2017 08:46:28 -0800 Subject: [PATCH] better exports --- beautiful-racket-demo/basic-demo-3/expander.rkt | 4 +++- beautiful-racket-demo/basic-demo-3/lexer.rkt | 2 +- beautiful-racket-demo/basic-demo-3/misc.rkt | 10 ++++++---- beautiful-racket-demo/basic-demo-3/parser.rkt | 4 +++- .../basic-demo-3/sample-export.rkt | 16 ++++++++-------- .../basic-demo-3/sample-import.rkt | 13 +++++++------ .../basic-demo-3/sample-require.rkt | 12 +++++------- 7 files changed, 33 insertions(+), 28 deletions(-) diff --git a/beautiful-racket-demo/basic-demo-3/expander.rkt b/beautiful-racket-demo/basic-demo-3/expander.rkt index 584422f..3233564 100644 --- a/beautiful-racket-demo/basic-demo-3/expander.rkt +++ b/beautiful-racket-demo/basic-demo-3/expander.rkt @@ -10,6 +10,8 @@ [(VAR-ID ...) (find-property 'b-id #'(LINE ...))] [(IMPORT-NAME ...) (find-property 'b-import-name #'(LINE ...))] + [(EXPORT-NAME ...) + (find-property 'b-export-name #'(LINE ...))] [((SHELL-ID SHELL-VAL) ...) (for/list ([(val idx) (in-indexed (current-command-line-arguments))]) (list (suffix-id #'arg idx #:context caller-stx) val))]) @@ -19,7 +21,7 @@ (configure-this!)) (require IMPORT-NAME) ... (define VAR-ID 0) ... - (provide VAR-ID ...) + (provide EXPORT-NAME ...) (set! SHELL-ID SHELL-VAL) ... LINE ... (define line-table diff --git a/beautiful-racket-demo/basic-demo-3/lexer.rkt b/beautiful-racket-demo/basic-demo-3/lexer.rkt index c43176d..e4be528 100644 --- a/beautiful-racket-demo/basic-demo-3/lexer.rkt +++ b/beautiful-racket-demo/basic-demo-3/lexer.rkt @@ -3,7 +3,7 @@ (define-lex-abbrev digits (:+ (char-set "0123456789"))) -(define-lex-abbrev reserved-terms (:or "print" "goto" "end" "+" ":" ";" "let" "=" "input" "-" "*" "/" "^" "mod" "(" ")" "def" "if" "then" "else" "<" ">" "<>" "and" "or" "not" "gosub" "return" "for" "to" "step" "next" "def" "," "import")) +(define-lex-abbrev reserved-terms (:or "print" "goto" "end" "+" ":" ";" "let" "=" "input" "-" "*" "/" "^" "mod" "(" ")" "def" "if" "then" "else" "<" ">" "<>" "and" "or" "not" "gosub" "return" "for" "to" "step" "next" "def" "," "import" "export")) (define-lex-abbrev id-kapu (:or whitespace (char-set "()[]{}\",'`;#|\\"))) diff --git a/beautiful-racket-demo/basic-demo-3/misc.rkt b/beautiful-racket-demo/basic-demo-3/misc.rkt index 409956c..da687ce 100644 --- a/beautiful-racket-demo/basic-demo-3/misc.rkt +++ b/beautiful-racket-demo/basic-demo-3/misc.rkt @@ -1,6 +1,6 @@ #lang br (require "struct.rkt" "expr.rkt") -(provide b-rem b-print b-let b-input b-repl b-import) +(provide b-rem b-print b-let b-input b-import b-export b-repl) (define (b-rem val) (void)) @@ -14,11 +14,13 @@ [num (string->number (string-trim str))]) (or num str)))) +(define-macro (b-import IMPORT-NAME) #'(void)) + +(define-macro (b-export EXPORT-NAME) #'(void)) + (define-macro (b-repl . ARGS) (with-pattern ([STMTS (pattern-case-filter #'ARGS [(b-expr . EXPR-ARGS) #'(b-print (b-expr . EXPR-ARGS))] [OTHER-STMT #'OTHER-STMT])]) - #'(begin . STMTS))) - -(define-macro (b-import VAL) #'(void)) \ No newline at end of file + #'(begin . STMTS))) \ No newline at end of file diff --git a/beautiful-racket-demo/basic-demo-3/parser.rkt b/beautiful-racket-demo/basic-demo-3/parser.rkt index 270b989..ae5af15 100644 --- a/beautiful-racket-demo/basic-demo-3/parser.rkt +++ b/beautiful-racket-demo/basic-demo-3/parser.rkt @@ -6,7 +6,7 @@ b-rem : REM @b-statement : b-end | b-print | b-goto | b-let | b-input | b-if | b-gosub | b-return | b-for | b-next - | b-def | b-import + | b-def | b-import | b-export b-end : /"end" b-print : /"print" [b-printable] (/";" [b-printable])* @b-printable : STRING | b-expr @@ -23,6 +23,8 @@ b-next : /"next" b-id b-def : /"def" b-id /"(" ID [/"," ID]* /")" /"=" b-expr b-import : /"import" b-import-name @b-import-name : ID | STRING +b-export : /"export" b-export-name +@b-export-name : ID b-expr : b-or-expr b-or-expr : [b-or-expr "or"] b-and-expr b-and-expr : [b-and-expr "and"] b-not-expr diff --git a/beautiful-racket-demo/basic-demo-3/sample-export.rkt b/beautiful-racket-demo/basic-demo-3/sample-export.rkt index 77ed7da..6a58db6 100644 --- a/beautiful-racket-demo/basic-demo-3/sample-export.rkt +++ b/beautiful-racket-demo/basic-demo-3/sample-export.rkt @@ -1,9 +1,9 @@ #lang basic-demo-3 -5 def f(x, y) = x * y -10 a = 1 : a = 5 : b = 10 -20 gosub 150 -30 a = 25 -40 gosub 150 -50 end -150 print a + a + a -160 return \ No newline at end of file +10 def div(num, denom) = num / denom +20 x = 5 : y = 10 +30 print x - 4 +40 x = 15 : y = 30 +50 print div(y, x) +60 x = 20 +70 print div((x + x + x), x) +80 export div : export x \ No newline at end of file diff --git a/beautiful-racket-demo/basic-demo-3/sample-import.rkt b/beautiful-racket-demo/basic-demo-3/sample-import.rkt index a1922cb..9799586 100644 --- a/beautiful-racket-demo/basic-demo-3/sample-import.rkt +++ b/beautiful-racket-demo/basic-demo-3/sample-import.rkt @@ -1,6 +1,7 @@ -#lang br -(require "sample-export.rkt") -f -a -b -(f a b) \ No newline at end of file +#lang basic-demo-3 +10 import math/number-theory +20 print nth-prime(15) +30 print prime?(24) +40 import racket/base +50 print max(f(1), f(2), f(5), f(4)) +60 def f(x) = x + x \ No newline at end of file diff --git a/beautiful-racket-demo/basic-demo-3/sample-require.rkt b/beautiful-racket-demo/basic-demo-3/sample-require.rkt index 9799586..639ca04 100644 --- a/beautiful-racket-demo/basic-demo-3/sample-require.rkt +++ b/beautiful-racket-demo/basic-demo-3/sample-require.rkt @@ -1,7 +1,5 @@ -#lang basic-demo-3 -10 import math/number-theory -20 print nth-prime(15) -30 print prime?(24) -40 import racket/base -50 print max(f(1), f(2), f(5), f(4)) -60 def f(x) = x + x \ No newline at end of file +#lang br +(require "sample-export.rkt") +div +x +(div x 10) \ No newline at end of file