[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[MIT-Scheme-users] Adding command-line processing to my script
From: |
Nathan Thern |
Subject: |
[MIT-Scheme-users] Adding command-line processing to my script |
Date: |
Tue, 9 Dec 2014 16:47:32 -0500 |
Using examples from http://cubbi.com/fibonacci/scheme.html as a
starting point, I created the following script named f1a.scm:
(declare (usual-integrations))
(define (fib m)
(if (< m 2)
m
(+ (fib (- m 1)) (fib (- m 2)))))
(define (main n)
(display (string-append
(number->string n)
"th Fibonacci number is "
(number->string (fib n))))
(newline))
I can compile and run it as follows:
$ echo '(cf "f1a")' | mit-scheme -batch-mode -compiler
< compiler messages >
$ mit-scheme -batch-mode -load f1a -eval "(begin (main 10) (%exit))"
Since my eventual goal is to write more complex scripts that can be
called with command-line options, I would like to call this script
with (e.g.) "10" as command line arg, not embedded in an eval string.
>From the docs, I thought this would work - I added these lines to my
script file after the declare line:
(define (calc str) (main (string->number str)))
(argument-command-line-parser "calc" #f calc)
Unfortunately, it didn't work:
$ echo '(cf "f1a")' | mit-scheme -batch-mode -compiler
< compiler messages >
$ mit-scheme -batch-mode -load f1a -calc 10
;Warning: Unhandled command line options: ("-calc" "10")
What am I missing?
NT
- [MIT-Scheme-users] Adding command-line processing to my script,
Nathan Thern <=
- Re: [MIT-Scheme-users] Adding command-line processing to my script, Nathan Thern, 2014/12/09
- Re: [MIT-Scheme-users] Adding command-line processing to my script, Matt Birkholz, 2014/12/10
- Re: [MIT-Scheme-users] Adding command-line processing to my script, Nathan Thern, 2014/12/10
- Re: [MIT-Scheme-users] Adding command-line processing to my script, Matt Birkholz, 2014/12/10
- Re: [MIT-Scheme-users] Adding command-line processing to my script, Nathan Thern, 2014/12/11
- Re: [MIT-Scheme-users] Adding command-line processing to my script, Matt Birkholz, 2014/12/12
- Re: [MIT-Scheme-users] Adding command-line processing to my script, Matt Birkholz, 2014/12/12