[Scheme-reports] command-line and invocation manner
Per Bothner 18 Sep 2013 18:48 UTC
The command-line procedure doesn't distinguish between what we
might call "application arguments" (arguments meant for the
application) and "invocation arguments" (the command and argument
for starting up Scheme with a given "application").
For example, suppose I have foo.scm containing:
(format #t "c-l: ~w~%" (command-line))
One might load this file using load, run it from the command line,
or compile it and then execute it. I think one would want the application
arguments to be the same regardless. The choice I made for Kawa
was that the application arguments are (cdr (command-line))
while the invocation arguments are pasted to a single string as
the (car (command-line)). I think this is allowed by R6RS/R7RS,
and I think this is a reasonable approach.
Examples:
$ java kawa.repl ~/tmp/foo.scm abc "def ghi"
c-l: ("java kawa.repl /home/bothner/tmp/foo.scm" "abc" "def ghi")
(kawa.repl is the main "driver" application class for kawa.)
The "kawa" program is a front-end with readline support that
connects to an inferior JVM. Using it results in:
$ kawa ~/tmp/foo.scm abc "def ghi"
c-l: ("java kawa.repl --connect 44549 /home/bothner/tmp/foo.scm" "abc"
"def ghi")
Using load:
$ java kawa.repl -e '(load "/home/bothner/tmp/foo.scm")' abc "def ghi"
c-l: ("java kawa.repl -e (load \"/home/bothner/tmp/foo.scm\")" "abc"
"def ghi")
The -f flag enable line-by-line loading (rather than module-at-at-time
loading), but for many cases it works the same:
$ java kawa.repl -f ~/tmp/foo.scm abc "def ghi"
c-l: ("java kawa.repl -f /home/bothner/tmp/foo.scm" "abc" "def ghi")
Compiling as class run by the kawa.repl driver (or kawa front-end):
$ kawa -C ~/tmp/foo.scm
(compiling /home/bothner/tmp/foo.scm to foo)
$ java kawa.repl foo abc "def ghi"
c-l: ("java kawa.repl foo" "abc" "def ghi")
$ kawa foo abc "def ghi"
c-l: ("java kawa.repl --connect 45671 foo" "abc" "def ghi")
Compiling to an application (with a static "main" method):
$ kawa --main -C ~/tmp/foo.scm
(compiling /home/bothner/tmp/foo.scm to foo)
$ java foo abc "def ghi"
c-l: ("java foo" "abc" "def ghi")
All yield the same (cdr (command-line)), but the (car (command-line))
depends on how it was invoked.
--
--Per Bothner
per@bothner.com http://per.bothner.com/
_______________________________________________
Scheme-reports mailing list
Scheme-reports@scheme-reports.org
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports