From e571d9b37289f713995e19b25354d96702e85ee3 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Fri, 24 Feb 2017 08:34:52 -0800 Subject: [PATCH] support shell args --- beautiful-racket-demo/basic-demo-3/expander.rkt | 10 +++++++--- beautiful-racket-demo/basic-demo-3/sample-shell.rkt | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 beautiful-racket-demo/basic-demo-3/sample-shell.rkt diff --git a/beautiful-racket-demo/basic-demo-3/expander.rkt b/beautiful-racket-demo/basic-demo-3/expander.rkt index 1487b9a..9ece9e8 100644 --- a/beautiful-racket-demo/basic-demo-3/expander.rkt +++ b/beautiful-racket-demo/basic-demo-3/expander.rkt @@ -8,7 +8,10 @@ ([((b-line NUM STMT ...) ...) #'(LINE ...)] [(LINE-FUNC ...) (prefix-id "line-" #'(NUM ...))] [(VAR-ID ...) (find-property 'b-id #'(LINE ...))] - [(REQ-SPEC ...) (find-property 'b-require-spec #'(LINE ...))]) + [(REQ-SPEC ...) (find-property 'b-require-spec #'(LINE ...))] + [((SHELL-ID SHELL-VAL) ...) + (for/list ([(arg idx) (in-indexed (current-command-line-arguments))]) + (list (format-id caller-stx "arg~a" idx) arg))]) ; explain why (format-datum 'arg~a idx) won't work #'(#%module-begin (module configure-runtime br (require "runtime.rkt") @@ -17,12 +20,13 @@ (require REQ-SPEC) ... (define VAR-ID 0) ... (provide VAR-ID ...) + (set! SHELL-ID SHELL-VAL) ... LINE ... (define line-table (apply hasheqv (append (list NUM LINE-FUNC) ...))) (parameterize ([current-output-port - (or (current-basic-port) (open-output-nowhere))]) - (void (run line-table)))))) + (or (current-basic-port) (open-output-nowhere))]) + (void (run line-table)))))) (begin-for-syntax (require racket/list) diff --git a/beautiful-racket-demo/basic-demo-3/sample-shell.rkt b/beautiful-racket-demo/basic-demo-3/sample-shell.rkt new file mode 100644 index 0000000..33d077f --- /dev/null +++ b/beautiful-racket-demo/basic-demo-3/sample-shell.rkt @@ -0,0 +1,2 @@ +#lang basic-demo-3 +10 print "got shell arg" : print arg0 : print arg1 \ No newline at end of file