Like AWK, Perl, or any shell, Guile can interpret script files. A Guile script is simply a file of Scheme code with some extra information at the beginning which tells the operating system how to invoke Guile, and then tells Guile how to handle the Scheme code.
Here we describe Guile's command-line processing in detail. Guile processes its arguments from left to right, recognizing the switches described below. For examples, see section Scripting Examples.
-s script arg...
load function would. After loading script, exit. Any
command-line arguments arg... following script become the
script's arguments; the command-line function returns a list of
strings of the form (script arg...).
-c expr arg...
command-line function returns a list of strings of the form
(guile arg...), where guile is the path of the
Guile executable.
-- arg...
--
become command-line arguments for the interactive session; the
command-line function returns a list of strings of the form
(guile arg...), where guile is the path of the
Guile executable.
-l file
-e function
-s) or evaluating the expression (with
-c), apply function to a list containing the program name
and the command-line arguments -- the list provided by the
command-line function.
A -e switch can appear anywhere in the argument list, but Guile
always invokes the function as the last action it performs.
This is weird, but because of the way script invocation works under
POSIX, the -s option must always come last in the list.
See section Scripting Examples.
-ds
-s option as if it occurred at this point in the
command line; load the script here.
This switch is necessary because, although the POSIX script invocation
mechanism effectively requires the -s option to appear last, the
programmer may well want to run the script before other actions
requested on the command line. For examples, see section Scripting Examples.
\
--emacs
#t.
This switch is still experimental.
--use-srfi=list
--use-srfi expects a comma-separated list of numbers,
each representing a SRFI number to be loaded into the interpreter
before starting evaluating a script file or the REPL. Additionally,
the feature identifier for the loaded SRFIs is recognized by
`cond-expand' when using this option.
guile --use-srfi=8,13
--debug
-s or -c, the normal, faster evaluator is used by default.
@vnew{1.8}
--no-debug
-h, --help
-v, --version
Guile's command-line switches allow the programmer to describe reasonably complicated actions in scripts. Unfortunately, the POSIX script invocation mechanism only allows one argument to appear on the `#!' line after the path to the Guile executable, and imposes arbitrary limits on that argument's length. Suppose you wrote a script starting like this:
#!/usr/local/bin/guile -e main -s
!#
(define (main args)
(map (lambda (arg) (display arg) (display " "))
(cdr args))
(newline))
The intended meaning is clear: load the file, and then call main
on the command-line arguments. However, the system will treat
everything after the Guile path as a single argument -- the string
"-e main -s" -- which is not what we want.
As a workaround, the meta switch \ allows the Guile programmer to
specify an arbitrary number of options without patching the kernel. If
the first argument to Guile is \, Guile will open the script file
whose name follows the \, parse arguments starting from the
file's second line (according to rules described below), and substitute
them for the \ switch.
Working in concert with the meta switch, Guile treats the characters `#!' as the beginning of a comment which extends through the next line containing only the characters `!#'. This sort of comment may appear anywhere in a Guile program, but it is most useful at the top of a file, meshing magically with the POSIX script invocation mechanism.
Thus, consider a script named `/u/jimb/ekko' which starts like this:
#!/usr/local/bin/guile \
-e main -s
!#
(define (main args)
(map (lambda (arg) (display arg) (display " "))
(cdr args))
(newline))
Suppose a user invokes this script as follows:
$ /u/jimb/ekko a b c
Here's what happens:
/usr/local/bin/guile \ /u/jimb/ekko a b cThis is the usual behavior, prescribed by POSIX.
\ /u/jimb/ekko, it opens
`/u/jimb/ekko', parses the three arguments -e, main,
and -s from it, and substitutes them for the \ switch.
Thus, Guile's command line now reads:
/usr/local/bin/guile -e main -s /u/jimb/ekko a b c
(main "/u/jimb/ekko" "a" "b" "c").
When Guile sees the meta switch \, it parses command-line
argument from the script file according to the following rules:
"".
\n and
\t are also supported. These produce argument constituents; the
two-character combination \n doesn't act like a terminating
newline. The escape sequence \NNN for exactly three octal
digits reads as the character whose ASCII code is NNN. As above,
characters produced this way are argument constituents. Backslash
followed by other characters is not allowed.
Go to the first, previous, next, last section, table of contents.