Next: using libraries, Previous: using invoking, Up: using [Index]
Scheme scripts can be executed using the following command:
vicare --r6rs-script PROGRAM
or the shorter:
vicare PROGRAM
Vicare Scheme follows the R6RS recommendations to install a
wrapper program called scheme-script
only when the
configure
option --enable-scheme-script is used at
package configuration time; this is to avoid conflicts with other Scheme
implementations. In this scenario, it is possible to execute Scheme
scripts as follows:
scheme-script PROGRAM [program options]
where the optional program options can be retrieved with
command-line
, command-line. When using
scheme-script
it is impossible to select command arguments to
be passed to Vicare rather than to the script.
Here is a sample script (Pig Latin—“Igpay Atinlay”—is a code that was at one time popular among very young North American children).
(import (rnrs)) ;;; Convert a string to its Pig Latin equivalent. ;;; ;;; If the first character is a vowel, append "yay". ;;; "egg" -> "eggyay" ;;; ;;; If the first character is a consonant, remove it, ;;; and append it plus "ay" to the string. ;;; "foo" -> "oofay" (define pig-latin (lambda (str) (let ((first (string-ref str 0))) (if (memv first '(#\a #\e #\i #\o #\u)) (string-append str "yay") (string-append (substring str 1 (string-length str)) (string first) "ay"))))) (display (map pig-latin (cdr (command-line)))) (newline) (flush-output-port (current-output-port))
Assuming we have stored the script in the file demo.sps, we can
invoke this script via vicare
:
$ vicare --r6rs-script demo.sps ice cream after dinner (iceyay reamcay afteryay innerday)
On Unix/Linux systems, scripts generally start with a “shebang” line
(sharp plus bang) which names an interpreter for the
script. All modern systems have the env
command which
searches for a command in the user’s path.
#!/usr/bin/env vicare --r6rs-script (import (rnrs)) ...
Now we can make the file executable, and use it directly.
$ chmod +x demo.sps $ ./demo.sps ice cream after dinner (iceyay reamcay afteryay innerday)
There are a few fine points.
#!r6rs
) if they are at the very beginning of a
file.
.command
extension, then it can be executed from the Finder by double–clicking
on it. This brings up a terminal window in which the script is
executed. The .command
extension can be hidden from the
Get Info item from the Finder’s File menu.
Next: using libraries, Previous: using invoking, Up: using [Index]