diff --git a/beautiful-racket-demo/basic-demo-3/expander.rkt b/beautiful-racket-demo/basic-demo-3/expander.rkt index b26f2ad..a8e61b1 100644 --- a/beautiful-racket-demo/basic-demo-3/expander.rkt +++ b/beautiful-racket-demo/basic-demo-3/expander.rkt @@ -12,14 +12,18 @@ (find-property 'b-import-name #'(LINE ...))] [(EXPORT-NAME ...) (find-property 'b-export-name #'(LINE ...))] - [((SHELL-ID SHELL-VAL) ...) (handle-shell caller-stx)]) + [((SHELL-ID SHELL-VAL) ...) + (make-shell-ids-and-values caller-stx)] + [(UNIQUE-ID ...) + (unique-ids + (syntax->list #'(VAR-ID ... SHELL-ID ...)))]) #'(#%module-begin (module configure-runtime br (require basic-demo-3/setup) (do-setup!)) (require IMPORT-NAME) ... (provide EXPORT-NAME ...) - (define VAR-ID 0) ... + (define UNIQUE-ID 0) ... (set! SHELL-ID SHELL-VAL) ... LINE ... (define line-table @@ -30,17 +34,21 @@ (begin-for-syntax (require racket/list) + + (define (unique-ids stxs) + (remove-duplicates stxs #:key syntax->datum)) + (define (find-property which line-stxs) - (remove-duplicates + (unique-ids (for/list ([stx (in-list (stx-flatten line-stxs))] #:when (syntax-property stx which)) - stx) - #:key syntax->datum)) + stx))) - (define (handle-shell ctxt) - (for/list - ([(val idx) - (in-indexed (current-command-line-arguments))]) - (list (suffix-id #'arg idx #:context ctxt) - (or (string->number val) val))))) + (define (make-shell-ids-and-values ctxt) + (for/list ([idx (in-naturals)] + [val (current-command-line-arguments)]) + (with-pattern + ([SHELL-ID (suffix-id #'arg idx #:context ctxt)] + [SHELL-VALUE (or (string->number val) val)]) + #'(SHELL-ID SHELL-VALUE))))) diff --git a/beautiful-racket-demo/basic-demo-3/report-args.rkt b/beautiful-racket-demo/basic-demo-3/report-args.rkt index 0289e67..865855d 100644 --- a/beautiful-racket-demo/basic-demo-3/report-args.rkt +++ b/beautiful-racket-demo/basic-demo-3/report-args.rkt @@ -1,6 +1,5 @@ #lang basic-demo-3 10 print "arg0 is " ; arg0 20 print "arg1 + arg1 is " ; arg1 + arg1 -30 print "arg2 is " ; arg2 40 print "arg3 is " ; arg3 50 print "arg4 is " ; arg4 \ No newline at end of file