Reading command-line arguments in MIT-scheme

mit-scheme, scheme

Solution

I have managed to find the following solution.

I have created a file `init.scm` with the following definitions:

(define command-line-args '())

(define parse-argument-list
  (lambda (arg-list)
    (set! command-line-args
      (if (null? arg-list)
          (list)
          (cdr arg-list)))))

(set-command-line-parser! "args" parse-argument-list)

In this way, when the command line option `--args` is found, the function `parse-argument-list` is invoked.

I have loaded this file into the `mit-scheme` interpreter and saved a world image (`init.com`) using the procedure `disk.save`.

I have then written a shell script (bash) that invokes my main Scheme script as follows:

mit-scheme --band "init.com" --interactive --batch-mode --args $* < myscript.scm

Finally, in my main script I can access the command line arguments through the variable

command-line-args

I am not sure whether this is the standard / correct way to do this but at least it works.

Problem

I am trying to run a scheme program using MIT-scheme (MIT/GNU Scheme running under GNU/Linux, Release 7.7.90.+ || Microcode 15.1 || Runtime 15.7) and I would like to access the command-line arguments. I have looked in the documentation but I haven't found anything specific. I have tried command-line, but I get an error message: ``` ;Unbound variable: command-line ``` Do I have to load some library in order to use command-line, or is there some other function for this?

Original source