diff --git a/beautiful-racket-demo/basic-demo-3/expander.rkt b/beautiful-racket-demo/basic-demo-3/expander.rkt index a451b9d..584422f 100644 --- a/beautiful-racket-demo/basic-demo-3/expander.rkt +++ b/beautiful-racket-demo/basic-demo-3/expander.rkt @@ -8,15 +8,16 @@ ([((b-line NUM STMT ...) ...) #'(LINE ...)] [(LINE-FUNC ...) (prefix-id "line-" #'(NUM ...))] [(VAR-ID ...) (find-property 'b-id #'(LINE ...))] - [(REQ-SPEC ...) (find-property 'b-import-name #'(LINE ...))] + [(IMPORT-NAME ...) + (find-property 'b-import-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))]) + (list (suffix-id #'arg idx #:context caller-stx) val))]) #'(#%module-begin (module configure-runtime br (require basic-demo-3/runtime) (configure-this!)) - (require REQ-SPEC) ... + (require IMPORT-NAME) ... (define VAR-ID 0) ... (provide VAR-ID ...) (set! SHELL-ID SHELL-VAL) ... @@ -32,6 +33,6 @@ (remove-duplicates (for/list ([stx (in-list (stx-flatten line-stxs))] #:when (syntax-property stx which)) - stx) + stx) #:key syntax->datum))) diff --git a/beautiful-racket-demo/basic-demo-3/expr.rkt b/beautiful-racket-demo/basic-demo-3/expr.rkt index 35902b2..207a27f 100644 --- a/beautiful-racket-demo/basic-demo-3/expr.rkt +++ b/beautiful-racket-demo/basic-demo-3/expr.rkt @@ -31,9 +31,13 @@ (define-macro (b-func FUNC-ID ARG ...) #'(if (procedure? FUNC-ID) (let ([result (FUNC-ID ARG ...)]) - (if (boolean? result) - (if result 1 0) - result)) + (cond + [(number? result) (b-expr result)] + [(string? result) result] + [(boolean? result) (if result 1 0)] + [else + (raise-line-error + (format "unknown data type: ~v" result))])) (raise-line-error (format "expected ~a to be a function, got ~v" 'FUNC-ID FUNC-ID)))) diff --git a/beautiful-racket-demo/basic-demo-3/parser.rkt b/beautiful-racket-demo/basic-demo-3/parser.rkt index 451282e..270b989 100644 --- a/beautiful-racket-demo/basic-demo-3/parser.rkt +++ b/beautiful-racket-demo/basic-demo-3/parser.rkt @@ -22,7 +22,7 @@ b-for : /"for" b-id /"=" b-expr /"to" b-expr [/"step" b-expr] 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-import-name : ID | STRING 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 @@ -35,4 +35,4 @@ b-expt : [b-expt ("^")] b-value @b-value : b-number | b-id | /"(" b-expr /")" | b-func b-func : ID /"(" b-expr [/"," b-expr]* /")" @b-number : INTEGER | DECIMAL -b-repl : (b-statement | b-expr) (/":" [b-repl])* \ No newline at end of file +b-repl : (b-statement | b-expr) (/":" [b-repl])*