mit-scheme-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MIT-Scheme-users] Adding command-line processing to my script


From: Nathan Thern
Subject: Re: [MIT-Scheme-users] Adding command-line processing to my script
Date: Wed, 10 Dec 2014 14:41:21 -0500
User-agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0

Works!
The "command-line" procedure and the -- separator don't appear to be documented - are they new? Also, is there a way to use #! notation in a script?

After trying hard to understand the docs better, I think that the way one would use "argument-command-line-parser" is via "load" and "disk-save" and then calling mit-scheme with the --band argument. Is that right? (I haven't tried it; this is more for curiosity's sake because I don't think I would do things that way.)

On 12/10/2014 1:15 PM, Matt Birkholz wrote:
From: Nathan Thern <address@hidden>
Date: Tue, 9 Dec 2014 16:55:48 -0500

I should mention that I also tried adding a dash ("calc" => "-calc")
in the "argument-command-line-parser" line:

(argument-command-line-parser "-calc" #f calc)

Same error.
By the time your script installs your command line parser, the command
line has already been parsed.

If you separate the machine options from your script's options with
"--" you will not get the warning.  The command-line procedure will
return the words following "--" as a list of strings.

Compiling scripts is not recommended.  You probably want to do
something like the following.

     cat >fib-script.scm <<EOF
     (load "fib-program.com")
     (let ((words (command-line)))
       (if (not (= (length words) 1))
          (error "One integer argument is required..."))
       (let* ((n-str (car words))
             (n (string->number n-str))
             (fib-n-str (number->string (fib n))))
        (display (string-append n-str"th Fibonacci number is "fib-n-str"\n"))))
     (%exit)
     EOF

     cat >fib-program.scm <<EOF
     (declare (usual-integrations))
     (define (fib m)
       (if (< m 2)
          m
          (+ (fib (- m 1)) (fib (- m 2)))))
     EOF

     mit-scheme <<EOF
     (compile-file "fib-program")
     EOF

     mit-scheme --batch-mode --load fib-script -- 10




reply via email to

[Prev in Thread] Current Thread [Next in Thread]