Go to the previous, next section.

Session Support

Repl

(require 'repl)

Here is a read-eval-print-loop which, given an eval, evaluates forms.

Procedure: repl:top-level repl:eval

reads, repl:evals and writes expressions from (current-input-port) to (current-output-port) until an end-of-file is encountered. load, slib:eval, slib:error, and repl:quit dynamically bound during repl:top-level.

Procedure: repl:quit

Exits from the invocation of repl:top-level.

The repl: procedures establish, as much as is possible to do portably, a top level environment supporting macros. repl:top-level uses dynamic-wind to catch error conditions and interrupts. If your implementation supports this you are all set.

Otherwise, if there is some way your implementation can catch error conditions and interrupts, then have them call slib:error. It will display its arguments and reenter repl:top-level. slib:error dynamically bound by repl:top-level.

To have your top level loop always use macros, add any interrupt catching lines and the following lines to your Scheme init file:

(require 'macro)
(require 'repl)
(repl:top-level macro:eval)

Debug

(require 'debug)

Procedure: print args

Print writes all its arguments, separated by spaces. Print outputs a newline at the end and returns the value of the last argument. Note that print is also defined in the yasos module (See section Yasos).

Procedure: qp args

Procedure: qpn args

Procedure: qpr args

qp writes its arguments, separated by spaces, to (current-output-port). qp compresses printing by substituting `...' for substructure it does not have sufficient room to print. qpn is like qp but outputs a newline before returning. qpr is like qpn except that it returns its last argument.

Variable: *qp-width*

*qp-width* is the largest number of characters that qp uses.

Breakpoints

Function: init-debug

Typing (init-debug) at top level sets up a continuation for break.

Function: break arg1 ...

Returns from the top level continuation and pushes the continuation from which it was called on debug:break-continuation-stack.

Function: continue

Pops the topmost continuation off of debug:break-continuation-stack and returns #f to it.

Tracing

(require 'trace)

Macro: trace proc1 ...

Traces the top-level named procedures given as arguments. Macro: trace

With no arguments, makes sure that all the currently traced identifiers are traced (even if those identifiers have been redefined) and returns a list of the traced identifiers.

Macro: untrace proc1 ...

Turns tracing off for its arguments. Macro: untrace

With no arguments, untraces all currently traced identifiers and returns a list of these formerly traced identifiers.

The following routines are the procedures which actually do the tracing when this module is supplied by SLIB, rather than natively. If macros are not natively supported by your implementation, these might be more convenient to use.

Function: tracef

Function: debug:tracef

To trace, type

(set! symbol (tracef symbol))
or
(set! symbol (tracef symbol 'symbol))
or
(define symbol (tracef function))
or
(define symbol (tracef function 'symbol))

Function: untracef

Function: debug:untracef function

To untrace, type

(set! symbol (untracef symbol))

Test

(require 'test)

Function: test expected fun . args

Compares expected to the result of applying fun to args. If they are not equal? then prints an error message. An unspecified value is returned.

Function: report-errs

Prints a summary of all error encountered by test. An unspecified value is returned.

Getopt

(require 'getopt)

This routine implements Posix command line argument parsing.

Variable: *optind*

Is the index of the current element of the command line. It is initially one.

Variable: *optarg*

Is set by getopt to the (string) option-argument of the current option.

Procedure: getopt argc argv optstring

Returns the next option letter in argv (starting from (vector-ref argv *optind*)) that matches a letter in optstring. argv is a vector or list of strings, the 0th of which getopt usually ignores. argc is the argument count, usually the length of argv. optstring is a string of recognized option characters; if a character is followed by a colon, the option takes an argument which may be immediately following it in the string or in the next element of argv.

*optind* is the index of the next element of the argv vector to be processed. It is initialized to 1 by `getopt.scm', and getopt updates it when it finishes with each element of argv.

getopt returns the next option character from argv that matches a character in optstring, if there is one that matches. If the option takes an argument, getopt sets the variable *optarg* to the option-argument as follows:

If, when getopt is called, the string (vector-ref argv *optind*) either does not begin with the character #\- or is just "-", getopt returns #f without changing *optind*. If (vector-ref argv *optind*) is the string "--", getopt returns #f after incrementing *optind*.

If getopt encounters an option character that is not contained in optstring, it returns the question-mark #\? character. If it detects a missing option argument, it returns the colon character #\: if the first character of optstring was a colon, or a question-mark character otherwise. In either case, getopt sets the variable getopt:opt to the option character that caused the error.

The special option "--" can be used to delimit the end of the options; #f is returned, and "--" is skipped.

RETURN VALUE

getopt returns the next option character specified on the command line. A colon #\: is returned if getopt detects a missing argument and the first character of optstring was a colon #\:.

A question-mark #\? is returned if getopt encounters an option character not in optstring or detects a missing argument and the first character of optstring was not a colon #\:.

Otherwise, getopt returns #f when all command line options have been parsed.

Example:

#! /usr/local/bin/scm
;;;This code is SCM specific.
(define argv (program-arguments))
(require 'getopt.scm)
(require 'debug)

(define opts ":a:b:cd")
(let loop ((opt (getopt (length argv) argv opts)))
  (case opt
    ((#\a) (print "option a: " *optarg*))
    ((#\b) (print "option b: " *optarg*))
    ((#\c) (print "option c"))
    ((#\d) (print "option d"))
    ((#\?) (print "error" getopt:opt))
    ((#\:) (print "missing arg" getopt:opt))
    ((#f) (if (< *optind* (length argv))
              (print "argv[" *optind* "]="
                     (list-ref argv *optind*)))
          (set! *optind* (+ *optind* 1))))
  (if (< *optind* (length argv))
      (loop (getopt (length argv) argv opts))))

(slib:exit)

Require

These variables and procedures are provided by all implementations.

Variable: *features*

Is a list of symbols denoting features supported in this implementation.

Variable: *modules*

Is a list of pathnames denoting files which have been loaded.

Variable: *catalog*

Is an association list of features (symbols) and pathnames which will supply those features. The pathname can be either a string or a pair. If pathname is a pair then the first element should be a macro feature symbol, source, or compiled. The cdr of the pathname should be either a string or a list.

In the following three functions if feature is not a symbol it is assumed to be a pathname.

Function: provided? feature

Returns #t if feature is a member of *features* or *modules* or if feature is supported by a file already loaded and #f otherwise.

Procedure: require feature

If (not (provided? feature)) it is loaded if feature is a pathname or if (assq feature *catalog*). Otherwise an error is signaled.

Procedure: provide feature

Assures that feature is contained in *features* if feature is a symbol and *modules* otherwise.

Function: require:feature->path feature

Returns #t if feature is a member of *features* or *modules* or if feature is supported by a file already loaded. Returns a path if one was found in *catalog* under the feature name, and #f otherwise. The path can either be a string suitable as an argument to load or a pair as described above for *catalog*.

Below is a list of features that are automatically determined by require. For each item, (provided? 'feature) will return #t if that feature is available, and #f if not.

Vicinity

A vicinity is a descriptor for a place in the file system. Vicinities hide from the programmer the concepts of host, volume, directory, and version. Vicinities express only the concept of a file environment where a file name can be resolved to a file in a system independent manner. Vicinities can even be used on `flat' file systems (which have no directory structure) by having the vicinity express constraints on the file name. On most systems a vicinity would be a string. All of these procedures are file system dependent.

These procedures are provided by all implementations.

Function: make-vicinity filename

Returns the vicinity of filename for use by in-vicinity.

Function: program-vicinity

Returns the vicinity of the currently loading Scheme code. For an interpreter this would be the directory containing source code. For a compiled system (with multiple files) this would be the directory where the object or executable files are. If no file is currently loading it the result is undefined. Warning: program-vicinity can return incorrectl values if your program escapes back into a load.

Function: library-vicinity

Returns the vicinity of the shared Scheme library.

Function: implementation-vicinity

Returns the vicinity of the underlying Scheme implementation. This vicinity will likely contain startup code and messages and a compiler.

Function: user-vicinity

Returns the vicinity of the current directory of the user. On most systems this is `""' (the empty string).

Function: in-vicinity vicinity filename

Returns a filename suitable for use by slib:load, slib:load-source, slib:load-compiled, open-input-file, open-output-file, etc. The returned filename is filename in vicinity. in-vicinity should allow filename to override vicinity when filename is an absolute pathname and vicinity is equal to the value of (user-vicinity). The behavior of in-vicinity when filename is absolute and vicinity is not equal to the value of (user-vicinity) is unspecified. For most systems in-vicinity can be string-append.

Function: sub-vicinity vicinity name

Returns the vicinity of vicinity restricted to name. This is used for large systems where names of files in subsystems could conflict. On systems with directory structure sub-vicinity will return a pathname of the subdirectory name of vicinity.

Configuration

These constants and procedures describe characteristics of the Scheme and underlying operating system. They are provided by all implementations.

Constant: char-code-limit

An integer 1 larger that the largest value which can be returned by char->integer.

Constant: most-positive-fixnum

The immediate integer closest to positive infinity.

Constant: slib:tab

The tab character.

Constant: slib:form-feed

The form-feed character.

Function: software-type

Returns a symbol denoting the generic operating system type. For instance, unix, vms, macos, amiga, or msdos.

Function: slib:report-version

Displays the versions of SLIB and the underlying Scheme implementation and the name of the operating system. An unspecified value is returned.

(slib:report-version) => slib "2a2" on scm "4e1" on unix 

Function: slib:report

Displays the information of (slib:report-version) followed by almost all the information neccessary for submitting a problem report. An unspecified value is returned.

Function: slib:report #t

provides a more verbose listing.

Function: slib:report filename

Writes the report to file `filename'.

(slib:report)
=>
slib "2a2" on scm "4e1" on unix 
(implementation-vicinity) is "/usr/local/src/scm/" 
(library-vicinity) is "/usr/local/lib/slib/" 
(scheme-file-suffix) is ".scm" 
implementation *features* : 
        bignum complex real rational
        inexact vicinity ed getenv
        tmpnam system abort transcript
        with-file ieee-p1178 rev4-report rev4-optional-procedures
        hash object-hash delay eval
        dynamic-wind multiarg-apply multiarg/and- logical
        defmacro string-port source array-for-each
        array full-continuation char-ready? line-i/o
        i/o-extensions pipe
implementation *catalog* : 
        (rev4-optional-procedures . "/usr/local/lib/slib/sc4opt")
        ... 

Input/Output

These procedures are provided by all implementations.

Procedure: file-exists? filename

Returns #t if the specified file exists. Otherwise, returns #f. If the underlying implementation does not support this feature then #f is always returned.

Procedure: delete-file filename

Deletes the file specified by filename. If filename can not be deleted, #f is returned. Otherwise, #t is returned.

Procedure: tmpnam

Returns a pathname for a file which will likely not be used by any other process. Successive calls to (tmpnam) will return different pathnames.

Procedure: current-error-port

Returns the current port to which diagnostic and error output is directed.

Procedure: force-output

Procedure: force-output port

Forces any pending output on port to be delivered to the output device and returns an unspecified value. The port argument may be omitted, in which case it defaults to the value returned by (current-output-port).

Procedure: output-port-width

Procedure: output-port-width port

Returns the width of port, which defaults to (current-output-port) if absent. If the width cannot be determined 79 is returned.

Procedure: output-port-height

Procedure: output-port-height port

Returns the height of port, which defaults to (current-output-port) if absent. If the height cannot be determined 24 is returned.

System

These procedures are provided by all implementations.

Function: identity x

identity returns its argument.

Example:

(identity 3)
   => 3
(identity '(foo bar))
   => (foo bar)
(map identity lst)
   == (copy-list lst)

Procedure: slib:load-source name

Loads a file of Scheme source code from name with the default filename extension used in SLIB. For instance if the filename extension used in SLIB is `.scm' then (slib:load-source "foo") will load from file `foo.scm'.

Procedure: slib:load-compiled name

On implementations which support separtely loadable compiled modules, loads a file of compiled code from name with the implementation's filename extension for compiled code appended.

Procedure: slib:load name

Loads a file of Scheme source or compiled code from name with the appropriate suffixes appended. If both source and compiled code are present with the appropriate names then the implementation will load just one. It is up to the implementation to choose which one will be loaded.

If an implementation does not support compiled code then slib:load will be identical to slib:load-source.

Procedure: slib:eval obj

eval returns the value of obj evaluated in the current top level environment.

Procedure: slib:eval-load filename eval

filename should be a string. If filename names an existing file, the Scheme source code expressions and definitions are read from the file and eval called with them sequentially. The slib:eval-load procedure does not affect the values returned by current-input-port and current-output-port.

Procedure: slib:error arg1 arg2 ...

Outputs an error message containing the arguments, aborts evaluation of the current form and responds in a system dependent way to the error. Typical responses are to abort the program or to enter a read-eval-print loop.

Procedure: slib:exit n

Procedure: slib:exit

Exits from the Scheme session returning status n to the system. If n is omitted or #t, a success status is returned to the system (if possible). If n is #f a failure is returned to the system (if possible). If n is an integer, then n is returned to the system (if possible). If the Scheme session cannot exit an unspecified value is returned from slib:exit.

Go to the previous, next section.