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 mailing list
MIT-Scheme-users@gnu.org
https://lists.gnu.org/mailman/listinfo/mit-scheme-users

Reply via email to