SRFI 193
Introduction
This egg implements SRFI 193: Command line.
Documentation
Command
[parameter] (command-line [string-list])Like the standard command-line procedure in R7RS and R6RS, this returns the command line as list of strings. The first element (always present) is the command name and the remaining elements (if any) are command arguments. Neither the strings nor the list should be mutated.
Unlike RnRS command-line this is a parameter that can be bound to another value, e.g. for subcommand processing. If the parameter is rebound to another list, the new list may share structure with the old list.
The initial command line is more precisely specified than the value of RnRS command-line:
- When running a standalone program compiled by csc, the first element is the operating system's argv[0] and the remaining elements are argv[1] and up. However, any -: arguments that give options for the Chicken runtime system are not part of the list.
- When running a script via csi -script file.scm a b c or csi -s file.scm a b c then command-line is bound to '("file.scm" "a" "b" "c").
- When not running a command, command-line is bound to '(""). This happens when:
- Loading source files into the csi REPL via csi file.scm.
- Loading source files into the csi REPL via (load "file.scm").
- Evaluating code in the csi REPL.
Returns a simplified version of (car (command-line)), respecting the current binding of the command-line parameter.
This is typically something suitable to display as the program name. For example, /path/to/foo.scm is simplified into foo.
However, if (car (command-line)) is a zero-length string, #f is returned to signify "not a command".
[procedure] (command-args)Returns (cdr (command-line)), respecting the current binding of the command-line parameter.
Script
[parameter] (script-file [string?])If running a source file as a script via csi -script file.scm or csi -s file.scm, returns an absolute pathname of that file as a string. Otherwise returns #f.
In Chicken, this is actually a parameter object and may be set by the user.
[procedure] (script-directory)Returns (script-file) without the filename part, respecting the current binding of the script-file parameter.
The string ends with a directory separator so string-append can be used to build pathnames to refer to files in the same directory as the script.
Returns #f in any situation where (script-file) returns #f.
Version History
- 0.1.3: Add Chicken 4 egg
- 0.1.2: Fix tests
- 0.1.1: Fix bug where pre-compiled .so gave incorrect results in csi
- 0.1: First release
Author
Lassi Kortela
Repository
https://github.com/lassik/chicken-srfi-193
License
Copyright 2020 Lassi Kortela Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.