Copyright © 2000-2005, Felix L. Winkelmann All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
CHICKEN - A practical and portable Scheme system User's manual (Version 2, Build 228)
(c) 2000-2005, Felix L. Winkelmann All rights reserved. Translated to LaTeX by Peter Keller. Translated to texinfo by Linh Dang.
--- The Detailed Node Listing ---
Using the compiler
Using the interpreter
Supported language
Non-standard macros and special forms
Unit library
Unit eval
Unit extras
Unit posix
Unit utils
Unit lolevel
Unit tinyclos
Interface to external functions and variables
The Easy Foreign Function Interface
chicken-setup
Additional files
CHICKEN is a compiler that translates Scheme source files into C, which in turn can be fed to a C-compiler to generate a standalone executable. This principle, which is used by several existing compilers, achieves high portability because C is implemented on nearly all available platforms.
This package is distributed under the BSD license and as such is free to use and modify. An interpreter is also available and can be used as a scripting environment or for testing programs before compilation.
The method of compilation and the design of the runtime-system follow
closely Henry Baker's CONS Should Not CONS Its Arguments, Part II:
Cheney on the M.T.A. paper and expose a number of interesting
properties: consing (creation of data on the heap) is relatively
inexpensive, because a generational garbage collection scheme is used,
in which short-lived data structures are reclaimed extremely quickly.
Moreover, call-with-current-continuation is practically for free
and CHICKEN does not suffer under any performance penalties if
first-class continuations are used in complex ways. The generated C
code is fully tail-recursive.
Some of the features supported by CHICKEN:
match package
This manual is merely a reference for the CHICKEN system and assumes a working knowledge of Scheme.
The compiler translates Scheme source code into fairly portable C that can be compiled and linked with most available C compilers. CHICKEN supports the generation of executables and libraries, linked either statically or dynamically. Compiled Scheme code can be loaded dynamically, or can be embedded in applications written in other languages. Separate compilation of modules is fully supported.
The most portable way of creating separately linkable entities is supported by so-called units. A unit is a single compiled object module that contains a number of toplevel expressions that are executed either when the unit is the main unit or if the unit is used. To use a unit, the unit has to be declareed as used, like this:
(declare (uses UNITNAME))
The toplevel expressions of used units are executed in the order in which the units appear in the uses declaration. Units may be used multiple times and uses declarations may be circular (the unit is initialized at most once). To compile a file as a unit, add a unit declaration:
(declare (unit UNITNAME))
When compiling different object modules, make sure to have one main unit. This unit is called initially and initializes all used units before executing its toplevel expressions. The main-unit has no unit declaration.
Another method of using definitions in separate source files is to include them. This simply inserts the code in a given file into the current file:
(include "FILENAME")
Macro definitions are only available when processed
by include. Macro definitions in separate units are not available, since
they are defined at compile time, i.e the time when that other unit
was compiled (macros can optionally be
available at runtime, see define-macro in Substitution forms and macros).
On platforms that support dynamic loading of compiled code (like Windows and most ELF based
systems like Linux or BSD) code can be compiled into a shared object (.so) and loaded
dynamically into a running application.
The interface to chicken is intentionally simple. System
dependent makefiles, shell-scripts or batch-files should perform
any necessary steps before and after invocation of chicken.
A program named csc provides a much simpler
interface to the Scheme- and C-compilers and linker. Enter
csc -help
on the command line for more information.
chicken FILENAME {OPTION}
FILENAME is the complete pathname of the source file that is to
be translated into C. A filename argument of “-” specifies that
the source text should be read from standard input. Note that the filename
has to be the first argument to chicken.
Possible options are:
-analyze-only-benchmark-mode-no-trace -no-lambda-info -optimize-level 3
-fixnum-arithmetic -disable-interrupts -block -lambda-lift.
-blockeval and unused toplevel bindings are removed.
-case-insensitivecase-insensitive
feature identifier.
-check-syntax-compress-literals THRESHOLDTHRESHOLD as strings
and parse the strings at run-time. This reduces the size of the code and
speeds up compile-times of the host C compiler, but has a small run-time
performance penalty. The size of a literal is computed by counting recursively the objects
in the literal, so a vector counts as 1 plus the count of the elements,
a pair counts as the counts of the car and the cdr, respectively.
All other objects count 1.
-debug MODESMODES is a string
of characters that select debugging information about the compiler that
will be printed to standard output.
-debug-level LEVELLEVEL should be an integer.
-debug-level 0 is equivalent to -no-trace -no-lambda-info
-debug-level 1 is equivalent to -no-trace
-debug-level 2 does nothing (the default)
-disable-c-syntax-checks-disable-interrupts(disable-interrupts) declaration. No
interrupt-checks are generated for compiled programs.
-disable-stack-overflow-checks-:o runtime option.
-dynamic-epilogue FILENAMEFILENAME at the end of the compiled source file. The include-path
is not searched. This option may be given multiple times.
-emit-external-prototypes-firstdefine-external before any
other foreign declarations. This is sometimes useful, when C/C++ code embedded into
the a Scheme program has to access the callbacks. By default the prototypes are emitted
after foreign declarations.
-explicit-uselibrary, eval and extras.
Use this option if compiling a library unit instead of an application
unit.
-extend FILENAME-extension-prelude '(define-extension <NAME>)', where
<NAME> is the basename of the currently compiled file.
-feature SYMBOLSYMBOL to be a valid feature identifier for
cond-expand.
-ffi#>! ... <#.
-ffi-parse#>? ... <#.
-ffi-define SYMBOLforeign-parse
declarations.
-ffi-include-path PATH-ffi-no-include-fixnum-arithmetic(fixnum-arithmetic) declaration. Assume all
mathematical operations use small integer arguments.
-heap-size NUMBERNUMBER
bytes. The parameter may be followed by a
M (m) or K (k)
suffix which stand for mega- and kilobytes, respectively. The default
heap size is 5 kilobytes. Note that only half of it is in use at every
given time.
-heap-initial-size NUMBER-heap-growth PERCENTAGE-:hg).
-heap-shrinkage PERCENTAGE-:hs).
-help-include-path PATHNAMEinclude special form. This option may be given multiple times. If
the environment variable CHICKEN_INCLUDE_PATH is set, it
should contain a list of alternative include pathnames separated by
“;”. The environment variable CHICKEN_HOME is also
considered as a search path.
-inline-inline-limit option).
-inline-limit THRESHOLD-inline option.
The default threshold is 10.
-keyword-style STYLESTYLE may be either
prefix (as in Common Lisp), suffix (as in DSSSL) or none.
Any other value is ignored. The default is suffix.
-lambda-lift-no-lambda-infolambda expression (currently the argument-list,
after alpha-conversion/renaming).
-no-trace-no-trace
is specified. With this option the generated
code is slightly faster.
-no-warnings-nursery NUMBER-stack-size NUMBERNUMBER bytes. The parameter may be followed by a M
(m) or K (k) suffix. The default stack-size
depends on the target platform.
-optimize-leaf-routines-optimize-level LEVELLEVEL should be
an integer.
-optimize-level 0 does nothing.
-optimize-level 1 is equivalent to
-optimize-leaf-routines
-optimize-level 2 is currently the same as -optimize-level 1
-optimize-level 3 is equivalent to
-optimize-leaf-routines -unsafe
-output-file FILENAMEFILENAME.c.
-postlude EXPRESSIONSEXPRESSIONS after all other toplevel expressions in the
compiled file. This option may be given multiple times. Processing of
this option takes place after processing of -epilogue.
-prelude EXPRESSIONSEXPRESSIONS before all other toplevel expressions in the
compiled file. This option may be given multiple times. Processing of
this option takes place before processing of -prologue.
-profile-accumulate-profileexit
or implicitly), profiling statistics are written to a file named
PROFILE. Each line of the generated file contains a list with
the procedure name, the number of calls and the time spent executing
it. Use the chicken-profile program to display the profiling
information in a more user-friendly form. Enter chicken-profile
with no arguments at the command line to get a list of available options.
The -accumulate-profile option is similar to -profile, but
the resulting profile information will be appended to any existing
PROFILE file. chicken-profile will merge and sum up the accumulated
timing information, if several entries for the same procedure calls exist.
-profile-name FILENAMEPROFILE. Implies -profile.
-prologue FILENAMEFILENAME at the start of the compiled
source file. The include-path is not searched. This option may be given
multiple times.
-quiet-rawruntime.c and chicken.h).
-require-extension NAMENAME before the compilation process
commences. This is identical to adding (require-extension NAME) at the start of
the compiled program.
-run-time-macros-split NUMBERfilename0, ..., filename<NUMBER-1> with as many
files as given in NUMBER.
-split-level NUMBER-to-stdout.c file.
-unit NAME
-prelude "(declare (unit NAME))"
-unsafe-unsafe-libraries-uses NAMENAME. This is equivalent to
-prelude "(declare (uses NAME))"
-no-usual-integrations(not usual-integrations).
-version-verboseThe environment variable CHICKEN_OPTIONS can be set to a string
with default command-line options for the compiler.
After successful compilation a C source file is generated and can be compiled with a C compiler. Executables generated with CHICKEN (and the compiler itself) accept a small set of runtime options:
-:?-:b-:ccsi) to force output of the #;N> prompt even if stdin
is not a terminal (for example if running in an emacs buffer
under Windows).
-:d-:hNUMBER-:hiNUMBER-:hgPERCENTAGEPERCENTAGE.
The default is 200.
-:hmNUMBER-:hsPERCENTAGEPERCENTAGE of the heap is used, then it will shrink to
PERCENTAGE. The default is 50. Note: If you want to make sure
that the heap never shrinks, specify a value of 0. (this can
be useful in situations where an optimal heap-size is known in advance).
-:o-:sNUMBER-:tNUMBER-:fNUMBER-:aNUMBER-:w-:r-no-trace
options.
-:x-:x is not given, a warning will be shown, though.
-:BThe argument values may be given in bytes, in kilobytes (suffixed with
K or k), in megabytes (suffixed with M
or m), or in gigabytes (suffixed with G
or g). Runtime options may be combined, like -:dc,
but everything following a NUMBER argument is ignored. So
-:wh64m is OK, but -:h64mw will not enable GC of
unused symbols.
To compile a Scheme program (assuming a UNIX-like environment) perform the following steps:
foo.scm
;;; foo.scm
(define (fac n)
(if (zero? n)
1
(* n (fac (- n 1))) ) )
(write (fac 10))
(newline)
foo.scm
% csc foo.scm
% foo
3628800
If multiple bodies of Scheme code are to be combined into a single executable, then we have to compile each file and link the resulting object files together with the runtime system:
foo.scm
and bar.scm
;;; foo.scm
(declare (uses bar))
(write (fac 10)) (newline)
;;; bar.scm
(declare (unit bar))
(define (fac n)
(if (zero? n)
1
(* n (fac (- n 1))) ) )
foo.scm and bar.scm
% csc -c bar.scm
% csc foo.scm bar.o -o foo
% foo
3628800
The declarations specify which of the compiled files is the main
module, and which is the library module. An executable can only have
one main module, since a program has only a single entry-point. In this
case foo.scm is the main module, because it doesn't have a
unit declaration.
The compiler supplies a couple of hooks to add user-level passes to the
compilation process. Before compilation commences any Scheme source files
or compiled code specified using the -extend option are loaded
and evaluated. The parameters user-options-pass, user-read-pass,
user-preprocessor-pass, user-pass, user-pass-2 and user-post-analysis-pass can be set
to procedures that are called to perform certain compilation passes
instead of the usual processing (for more information about parameters
see: Parameters.
Holds a procedure that will be called with a list of command-line arguments and should return two values: the source filename and the actual list of options, where compiler switches have their leading
-(hyphen) removed and are converted to symbols. Note that this parameter is invoked before processing of the-extendoption, and so can only be changed in compiled user passes.
Holds a procedure of three arguments. The first argument is a list of strings with the code passed to the compiler via
-preludeoptions. The second argument is a list of source files including any files specified by-prologueand-epilogue. The third argument is a list of strings specified using-postludeoptions. The procedure should return a list of toplevel Scheme expressions.
Holds a procedure of one argument. This procedure is applied to each toplevel expression in the source file before macro-expansion. The result is macro-expanded and compiled in place of the original expression.
Holds a procedure of one argument. This procedure is applied to each toplevel expression after macro-expansion. The result of the procedure is then compiled in place of the original expression.
Holds a procedure of three arguments, which is called with the canonicalized node-graph as its sole argument. The result is ignored, so this pass has to mutate the node-structure to cause any effect.
Holds a procedure that will be called after the last performed program analysis. The procedure (when defined) will be called with three arguments: the program database, a getter and a setter-procedure which can be used to access and manipulate the program database, which holds various information about the compiled program. The getter procedure should be called with two arguments: a symbol representing the binding for which information should be retrieved, and a symbol that specifies the database-entry. The current value of the database entry will be returned or
#f, if no such entry is available. The setter procedure is called with three arguments: the symbol and key and the new value.For information about the contents of the program database contact the author.
Loaded code (via the -extend option) has access to the library
units extras, srfi-1, srfi-4, utils, regex and the pattern matching macros.
Multithreading is not available.
Note that the macroexpansion/canonicalization phase of the compiler adds
certain forms to the source program. These extra expressions are not
seen by user-preprocessor-pass but by user-pass.
It is relatively easy to create distributions of Scheme projects that
have been compiled to C. The runtime system of CHICKEN consists of only
two handcoded C files (runtime.c and chicken.h), plus
the file chicken-config.h, which is generated by the build process. All
other modules of the runtime system and the extension libraries are just
compiled Scheme code. The following example shows a minimal application, which
should run without changes on the most frequent operating systems, like Windows,
Linux or FreeBSD:
Let's take a simple “Hello, world!”:
; hello.scm (print "Hello, world!")
Compiled to C, we get hello.c. We need the files chicken.h and
runtime.c, which contain the basic runtime system, plus the three basic library
files library.c, eval.c and extras.c which contain the same functionality as the
library linked into a plain CHICKEN-compiled application, or which is available by default in the
iinterpreter, csi:
% csc hello.scm -O2 -d1
A simple makefile is needed as well:
# Makefile for UNIX systems
hello: hello.o runtime.o library.o eval.o extras.o
$(CC) -o hello hello.o runtime.o library.o eval.o extras.o -lm
hello.o: chicken.h
runtime.o: chicken.h
library.o: chicken.h
eval.o: chicken.h
extras.o: chicken.h
Now we have all files together, and can create an tarball containing all the files:
% tar cf hello.tar Makefile hello.c runtime.c library.c eval.c extras.c chicken.h % gzip hello.tar
This is of naturally rather simplistic. Things like enabling dynamic loading, estimating the optimal stack-size and selecting supported features of the host system would need more configuration- and build-time support. All this can be addressed using more elaborate build-scripts, makefiles or by using autoconf/automake/libtool.
Note also that the size of the application can still be reduced by removing extras and
eval and compiling hello.scm with the -explicit-use option.
For more information, study the CHICKEN source code and/or get in contact with the author.
CHICKEN provides an interpreter named csi for evaluating Scheme programs
and expressions interactively.
csi {FILENAME|OPTION}
where FILENAME specifies a file with Scheme source-code. If the
extension of the source file is .scm, it may be omitted. The
runtime options described in Compiler command line format are also available
for the interpreter. If the environment variable CSI_OPTIONS
is set to a list of options, then these options are additionally passed
to every direct or indirect invocation of csi. Please note that
runtime options (like -:...) can not be passed using this method.
The options recognized by the interpreter are:
---:...”) are still recognized.
-i -case-insensitivecase-insensitive
feature identifier.
-b -batch-e -eval EXPRESSIONSEXPRESSIONS. This option implies -batch and -quiet,
so no startup message will be printed and the interpreter exits after processing
all -eval options and/or loading files given on the command-line.
-D -feature SYMBOLSYMBOL to be a valid feature identifier for
cond-expand.
-h -help-I -include-path PATHNAMEinclude special form. This option may be given multiple times. If
the environment variable CHICKEN_INCLUDE_PATH is set, it
should contain a list of alternative include pathnames separated by
“;”. The environment variable CHICKEN_HOME is also
considered as a search path.
-k -keyword-style STYLESTYLE may be either
prefix (as in Common Lisp) or suffix (as in DSSSL).
Any other value is ignored.
-n -no-init-w -no-warnings-q -quiet-s -script PATHNAME-batch -quiet -no-init
PATHNAME. Arguments following PATHNAME are available by using
command-line-arguments and are not processed as interpreter
options. Extra options in the environment variable CSI_OPTIONS
are ignored.
-R -require-extension NAME(require-extension NAME).
-v -version#! notation for starting scripts,
anything following the characters #! is ignored, with the exception of the special
symbols #!optional, #!key, #!rest and #!eof.
The easiest way is to use the -script option like this:
% cat foo
#! /usr/local/bin/csi -script
(print (eval (with-input-from-string
(car (command-line-arguments))
read)))
% chmod +x foo
% foo "(+ 3 4)"
7
The parameter command-line-arguments is set to a list of the
parameters that were passed to the Scheme script. Scripts can be compiled
to standalone executables (don't forget to declare used library units).
CHICKEN supports writing shell scripts in Scheme for these platforms as well, using a slightly different approach. The first example would look like this on Windows:
C:>type foo.bat
@;csibatch %0 %1 %2 %3 %4 %5 %6 %7 %8 %9
(print (eval (with-input-from-string
(car (command-line-arguments))
read)))
C:>foo "(+ 3 4)"
7
Like UNIX scripts, batch files can be compiled. Windows batch scripts do not accept more than 8 arguments.
The toplevel loop understands a number of special commands:
,?,l FILENAME ...FILENAMEs
,ln FILENAME ...,p EXPEXP.
,d EXPEXP.
,du EXPEXP.
,dur EXP NN bytes of the result of evaluated expression EXP.
,q,r,s TEXT ...,t EXP,tr SYMBOL ...
#;1> (fac 10) ==> 3628800
#;2> ,tr fac
#;3> (fac 3)
|(fac 3)
| (fac 2)
| (fac 1)
| (fac 0)
| fac -> 1
| fac -> 1
| fac -> 2
|fac -> 6 ==> 6
#;4> ,utr fac
#;5> (fac 3) ==> 6
,utr SYMBOL ...
,utr<SPACE><ENTER>
restores all currently traced procedures to their original behaviour.
,x EXPEXP (the expression is
not evaluated).
You can define your own toplevel commands using the toplevel-command
procedure:
(toplevel-command SYMBOL PROC [HELPSTRING])Defines or defines a toplevel interpreter command the can be invoked by entering
,SYMBOL.PROCwill be invoked when the command is entered and may read any required argument viaread(orread-line). If the optional argumentHELPSTRINGis given, it will be listed by the,?command.
Additional macros and procedures available in the interpreter are:
# #INDEXReturns the result of entry number
INDEXin the history list. If the expression for that entry resulted in multiple values, the first result (or an unspecified value for no values) is returned. If noINDEXis given (and if a whitespace or closing paranthesis character follows the#, then the result of the last expression is returned. Note that this facility is a reader macro and is implicitly quoted.
[2] Identifiers are by default case-sensitive.
[4.1.4] Extended DSSSL style lambda lists are supported. DSSSL formal argument lists are defined by the following grammar:
<formal-argument-list> ==> <required-formal-argument>*
[(#!optional <optional-formal-argument>*)]
[(#!rest <rest-formal-argument>)]
[(#!key <key-formal-argument>*)]
<required-formal-argument> ==> <ident>
<optional-formal-argument> ==> <ident>
| (<ident> <initializer>)
<rest-formal-argument> ==> <ident>
<key-formal-argument> ==> <ident>
| (<ident> <initializer>)
<initializer> ==> <expr>
When a procedure is applied to a list of actual arguments, the formal and actual arguments are processed from left to right as follows:
#f. The initializer is evaluated in an environment in which all previous formal arguments have been bound.
#!key was specified in the formal-argument-list, there shall be an even number of remaining actual arguments. These are interpreted as a series of pairs, where the first member of each pair is a keyword specifying the argument name, and the second is the corresponding value. It shall be an error if the first member of a pair is not a keyword. It shall be an error if the argument name is not the same as a variable in a keyword-formal-argument, unless there is a rest-formal-argument. If the same argument name occurs more than once in the list of actual arguments, then the first value is used. If there is no actual argument for a particular keyword-formal-argument, then the variable is bound to the result of evaluating initializer if one was specified, and otherwise #f. The initializer is evaluated in an environment in which all previous formal arguments have been bound.
It shall be an error for an <ident> to appear more than once in a formal-argument-list.
Example:
((lambda x x) 3 4 5 6) => (3 4 5 6)
((lambda (x y #!rest z) z)
3 4 5 6) => (5 6)
((lambda (x y #!optional z #!rest r #!key i (j 1))
(list x y z i: i j: j))
3 4 5 i: 6 i: 7) => (3 4 5 i: 6 j: 1)
[4.1.6] set! for unbound toplevel variables is allowed. set! (PROCEDURE ...) ...)
is supported, as CHICKEN implements SRFI-17.
[4.3] syntax-rules macros are not provided but available separately.
[5.2] define with a single argument is allowed and initializes the toplevel or local binding
to an unspecified value. CHICKEN supports “curried” definitions, where the the variable name
may also be a list specifying a name and a nested lambda list. So
(define ((make-adder x) y) (+ x y))
is equivalent to
(define (make-adder x) (lambda (y) (+ x y)))
[6.2.4] The runtime system uses the numerical string-conversion routines of the underlying C library and so does only understand standard (C-library) syntax for floating-point constants.
[6.2.5] The routines complex?, real?
and rational? are identical to the standard procedure
number?. The procedures numerator, denominator
and rationalize are not implemented. Also not implemented are
all procedures related to complex numbers.
[6.2.6] The procedure string->number does not obey read/write
invariance on inexact numbers.
[6.5] Code evaluated in scheme-report-environment or
null-environment still sees non-standard syntax.
[6.6.2] The procedure char-ready? always returns
#t for terminal ports. The procedure read does not obey read/write
invariance on inexact numbers.
[6.6.3] The procedures write and display do not obey
read/write invariance to inexact numbers.
[6.6.4] The transcript-on and transcript-off procedures are
not implemented.
[2.1] Identifiers may contain special characters if delimited with
| ... |.
[2.3] The brackets [ ... ] are provided as an alternative syntax
for ( ... ). A number of reader extensions is provided. See
Non standard read syntax.
[4] Numerous non-standard macros are provided. See Non-standard macros and special forms for more information.
[4.2.2] It is allowed for initialization values of bindings in a letrec
construct to refer to previous variables in the same set of bindings, so
(letrec ([foo 123]
[bar foo] )
bar)
is allowed and returns 123.
[4.2.3] (begin) is allowed in non-toplevel contexts and evaluates
to an unspecified value.
[4.2.5] Delayed expressions may return multiple values.
[5.2.2] CHICKEN extends standard semantics by allowing internal definitions
everywhere, and not only at the beginning of a body. A set of internal definitions
is equivalent to a letrec form enclosing all following expressions
in the body:
(let ([foo 123]) (bar) (define foo 456) (baz foo) )
expands into
(let ([foo 123])
(bar)
(letrec ([foo 456])
(baz foo) ) )
[6] CHICKEN provides numerous non-standard procedures. See the manual sections on library units for more information.
[6.2.4] The special IEEE floating-point numbers “+nan”, “+inf” and “-inf” are supported, as is negative zero.
[6.3.4] User defined character names are supported. See
char-name in User-defined named characters. Characters can be given
in hexadecimal notation using the “#\xXX” syntax where “XX” specifies the
character code. Character codes above 255 are supported and can be read (and are
written) using the “#\uXXXX” and “#\UXXXXXXXX” notations.
Non-standard characters names supported are #\tab, #\linefeed, #\return, #\alarm,
#\vtab, #\nul, #\page, #\esc, #\delete and #\backspace.
[6.3.5] CHICKEN supports special characters preceded with
a backslash “\” in quoted string
constants. “\n” denotes the newline-character,
“\r” carriage return, “\b”
backspace, “\t” TAB, “\v” vertical TAB, “\a” alarm, “\f” formfeed,
“\xXX” a character with the code XX in hex and
“\uXXXX” (and “\UXXXXXXXX”) a unicode character with the code XXXX.
The latter is encoded in UTF-8 format.
The third argument to substring is optional and defaults to the length
of the string.
[6.4] force called with an argument that is not a promise returns
that object unchanged. Captured continuations can be safely invoked
inside before- and after-thunks of a dynamic-wind form and
execute in the outer dynamic context of the dynamic-wind form.
Implicit non-multival continuations accept multiple values by discarding all
but the first result. Zero values result in the continuation receiving an
unspecified value. Note that this slight relaxation of the behaviour of
returning mulitple values to non-multival continuations does not apply to
explicit continuations (created with call-with-current-continuation).
[6.5] The second argument to eval is optional and
defaults to the value of (interaction-environment).
scheme-report-environment and null-environment accept
an optional 2nd parameter: if not #f (which is the default),
toplevel bindings to standard procedures are mutable and new toplevel
bindings may be introduced.
[6.6] The “tilde” character (~) is automatically expanded in pathnames.
Additionally, if a pathname starts with $VARIABLE..., then the prefix is replaced
by the value of the given environment variable.
[6.6.1] if the procedures current-input-port and
current-output-port are called with an argument (which should
be a port), then that argument is selected as the new current input- and
output-port, respectively. The procedures open-input-file,
open-output-file, with-input-from-file,
with-output-to-file, call-with-input-file and
call-with-output-file accept an optional second (or third)
argument which should be one or more keywords, if supplied. These
arguments specify the mode in which the file is opened. Possible
values are the keywords #:text, #:binary or
#:append.
Allows user-defined extension of external representations. (For more information see the documentation for SRFI-10)
Syntax for keywords. Keywords are symbols that evaluate to themselves, and as such don't have to be quoted.
Specifies a multiline string constant. Anything up to a line equal to
TAG(or end of file) will be returned as a single string:(define msg #<<END "Hello, world!", she said. END )is equivalent to
(define msg "\"Hello, world!\", she said.")
Similar to
#<<, but allows substitution of embedded Scheme expressions prefixed with#and optionally enclosed in{ ... }. Two consecutive#s are translated to a single#:(define three 3) (display #<#EOF This is a simple string with an embedded `##' character and substituted expressions: (+ three 99) ==> #(+ three 99) (three is "#{three}") EOF )prints
This is a simple string with an embedded `#' character and substituted expressions: (+ three 99) ==> 102 (three is "3")
Treated as a commment and ignores everything up the end of the current line. The keywords
#!optional, #!restand#!keyare handled separately and returned as normal symbols. The special (self-evaluating) symbol#!eofis read as the end-of-file object. Note that if this constant appears at top-level in a loaded file, it is indistiguishable from normal end-of-file.
Read the next expression in case-sensitive mode (regardless of the current global setting).
Read the next expression in case-insensitive mode (regardless of the current global setting).
(require-extension ID ...) (use ID ...)This form does all necessary steps to make the libraries or extensions given in
ID ...available. It loads syntactic extension, if needed and generates code for loading/linking with core library modules or separately installed extensions.useis just a shorter alias forrequire-extension. This implementation ofrequire-extensionis compliant to SRFI-55 (see SRFI-55 for more information).During interpretation/evaluation
require-extensionperforms one of the following:
- If
IDnames a built in featureschicken srfi-23 srfi-30 srfi-39 srfi-8 srfi-6 srfi-2 srfi-0 srfi-10 srfi-9 srfi-17 srfi-55, then nothing is done.- If
IDnames one of syntactic extensionschicken-match-macros chicken-more-macros chicken-ffi-macros, then this extension will be loaded.- If
IDnames one of the core library units shipped with CHICKEN, then a(load-library 'ID)will be performed. If one of those libraries define specific syntax (match srfi-13), then the required source file defining the syntax will be loaded.- If
IDnames an installed extension with thesyntaxorrequire-at-runtimeattribute, then the equivalent of(require-for-syntax 'ID)is performed.- Otherwise
(require-extension ID)is equivalent to(require 'ID).During compilation one of the following happens instead:
- If
IDnames a built in featureschicken srfi-23 srfi-30 srfi-39 srfi-8 srfi-6 srfi-2 srfi-0 srfi-10 srfi-9 srfi-17 srfi-55, then nothing is done.- If
IDnames one of syntactic extensionschicken-match-macros chicken-more-macros chicken-ffi-macros, then this extension will be loaded at compile-time, making the syntactic extensions available in compiled code.- If
IDnames one of the core library units shipped with CHICKEN, then a(declare (uses ID))is generated. If one of those libraries define specific syntax (match srfi-13), then the required source file defining the syntax will be loaded at compile-time, making the syntactic extension available in compiled code.- If
IDnames an installed extension with thesyntaxorrequire-at-runtimeattribute, then the equivalent of(require-for-syntax 'ID)is performed.- Otherwise
(require-extension ID)is equivalent to(require 'ID).To make long matters short - just use
require-extensionand it will normally figure everything out for dynamically loadable extensions and core library units.
IDshould be a pure extension name and should not contain any path prefixes (for exampledir/lib...) is illegal).
IDmay also be a list that designates an extension-specifier. Currently the following extension specifiers are defined:
(srfi NUMBER ...)is required for SRFI-55 compatibility and is fully implemented(version ID NUMBER)is equivalent toID, but checks at compile-time whether the extension namedIDis installed and whether its version is equal or higher thanNUMBER.NUMBERmay be a string or a number, the comparison is done lexicographically (usingstring>=?).See also:
set-extension-specifier!
(define-extension NAME CLAUSE ...)This macro simplifies the task of writing extensions that can be linked both statically and dynamically. If encountered in interpreted code or code that is compiled into a shared object (specifically if compiled with the feature
chicken-compile-shared, done automatically bycscwhen compiling with the-sharedor-dynamicoption) then the code given by clauses if the form(dynamic EXPRESSION ...)is inserted into the output as a
beginform.If compiled statically (specifically if the feature
chicken-compiled-sharedhas not been given), then this form expands into the following:(declare (unit NAME)) (provide 'NAME)and all clauses of the form
(static EXPRESSION ...)all additionally inserted into the expansion.
As a convenience, the clause
(export IDENTIFIER ...)is also allowed and is identical to
(declare (export IDENTIFIER ...))(unless thedefine-extensionform occurs in interpreted code, in with it is simply ignored).Note that the compiler option
-extension NAMEis equivalent to prefixing the compiled file with(define-extension NAME)
(:optional ARGS DEFAULT)Use this form for procedures that take a single optional argument. If
ARGSis the empty listDEFAULTis evaluated and returned, otherwise the first element of the listARGS. It is an error ifARGScontains more than one value.(define (incr x . i) (+ x (:optional i 1))) (incr 10) ==> 11 (incr 12 5) ==> 17
(case-lambda (LAMBDA-LIST1 EXP1 ...) ...)SRFI-16. Expands into a lambda that invokes the body following the first matching lambda-list.
(define plus (case-lambda (() 0) ((x) x) ((x y) (+ x y)) ((x y z) (+ (+ x y) z)) (args (apply + args)))) (plus) ==> 9 (plus 1) ==> 1 (plus 1 2 3) ==> 6For more information see the documentation for SRFI-16
(let-optionals ARGS ((VAR1 DEFAULT1) ...) BODY ...) (let-optionals* ARGS ((VAR1 DEFAULT1) ... [RESTVAR]) BODY ...)Binding constructs for optional procedure arguments.
ARGSshould be a rest-parameter taken from a lambda-list.let-optionalsbindsVAR1 ...to available arguments in parallel, or toDEFAULT1 ...if not enough arguments were provided.let-optionals*bindsVAR1 ...sequentially, so every variable sees the previous ones. If a single variableRESTVARis given, then it is bound to any remaining arguments, otherwise it is an error if any excess arguments are provided.(let-optionals '(one two) ((a 1) (b 2) (c 3)) (list a b c) ) ==> (one two 3) (let-optionals* '(one two) ((a 1) (b 2) (c a)) (list a b c) ) ==> (one two one)
(and-let* (BINDING ...) EXP1 EXP2 ...)SRFI-2. Bind sequentially and execute body.
BINDINGcan be a list of a variable and an expression, a list with a single expression, or a single variable. If the value of an expression bound to a variable is#f, theand-let*form evaluates to#f(and the subsequent bindings and the body are not executed). Otherwise the next binding is performed. If all bindings/expressions evaluate to a true result, the body is executed normally and the result of the last expression is the result of theand-let*form. See also the documentation for SRFI-2.
(rec NAME EXPRESSION) (rec (NAME VARIABLE ...) BODY ...)Allows simple definition of recursive definitions.
(rec NAME EXPRESSION)is equivalent to(letrec ((NAME EXPRESSION)) NAME)and(rec (NAME VARIABLE ...) BODY ...)is the same as(letrec ((NAME (lambda (VARIABLE ...) BODY ...))) NAME).
(define-values (NAME ...) EXP)Defines several variables at once, with the result values of expression
EXP.
(fluid-let ((VAR1 X1) ...) BODY ...)Binds the variables
VAR1 ...dynamically to the valuesX1 ...during execution ofBODY ....
(let-values (((NAME ...) EXP) ...) BODY ...)Binds multiple variables to the result values of
EXP .... All variables are bound simultaneously.
(let*-values (((NAME ...) EXP) ...) BODY ...)Binds multiple variables to the result values of
EXP .... The variables are bound sequentially.(let*-values (((a b) (values 2 3)) ((p) (+ a b)) ) p) ==> 5
(letrec-values (((NAME ...) EXP) ...) BODY ...)Binds the result values of
EXP ...to multiple variables at once. All variables are mutually recursive.(letrec-values (((odd even) (values (lambda (n) (if (zero? n) #f (even (sub1 n)))) (lambda (n) (if (zero? n) #t (odd (sub1 n)))) ) ) ) (odd 17) ) ==> #t
(parameterize ((PARAMETER1 X1) ...) BODY ...)Binds the parameters
PARAMETER1 ...dynamically to the valuesX1 ...during execution ofBODY .... (see also:make-parameterin Parameters). Note thatPARAMETERmay be any expression that evaluates to a parameter procedure.
(receive (NAME1 ... [. NAMEn]) VALUEEXP BODY ...) (receive VALUEEXP)SRFI-8. Syntactic sugar for
call-with-values. Binds variables to the result values ofVALUEEXPand evaluatesBODY ....The syntax
(receive VALUEEXP)is equivalent to
(receive _ VALUEEXP _)
(set!-values (NAME ...) EXP)Assigns the result values of expression
EXPto multiple variables.
(define-constant NAME CONST)Define a variable with a constant value, evaluated at compile-time. Any reference to such a constant should appear textually after its definition. This construct is equivalent to
definewhen evaluated or interpreted. Constant definitions should only appear at toplevel. Note that constants are local to the current compilation unit and are not available outside of the source file in which they are defined. Names of constants still exist in the Scheme namespace and can be lexically shadowed. If the value is mutable, then the compiler is careful to preserve its identity.CONSTmay be any constant expression, and may also refer to constants defined viadefine-constantpreviously. This for should only be used at top-level.
(define-inline (NAME VAR ... [. VAR]) BODY ...) (define-inline NAME EXP)Defines an inline procedure. Any occurrence of
NAMEwill be replaced byEXPor(lambda (VAR ... [. VAR]) BODY ...). This is similar to a macro, but variable-names and -scope will be correctly handled. Inline substitutions take place after macro-expansion.EXPshould be a lambda-expression. Any reference toNAMEshould appear textually after its definition. Note that inline procedures are local to the current compilation unit and are not available outside of the source file in which they are defined. Names of inline procedures still exist in the Scheme namespace and can be lexically shadowed. This construct is equivalent todefinewhen evaluated or interpreted. Inline definitions should only appear at toplevel.
(define-macro (NAME VAR ... [. VAR]) EXP1 ...) (define-macro NAME (lambda (VAR ... [. VAR]) EXP1 ...)) (define-macro NAME1 NAME2)Define a globally visible macro special form. The macro is available as soon as it is defined, i.e. it is registered at compile-time. If the file containing this definition invokes
evaland the declarationrun-time-macros(or the command line option-run-time-macros) has been used, then the macro is visible in evaluated expressions during runtime. The second possible syntax fordefine-macrois allowed for portability purposes only. In this case the second argument must be a lambda-expression or a macro name. Only global macros can be defined using this form.(define-macro NAME1 NAME2)simply copies the macro definition fromNAME2toNAME1, creating an alias.Extended lambda list syntax (
#!optional, etc.) can be used but note that arguments are source expressions and thus default values for optional or keyword arguments should take this into consideration.
(define-for-syntax (NAME VAR ... [. VAR]) EXP1 ...) (define-for-syntax NAME [VALUE])Defines the toplevel variable
NAMEat macro-expansion time. This can be helpful when you want to define support procedures for use in macro-transformers, for example.
(switch EXP (KEY EXP1 ...) ... [(else EXPn ...)])This is similar to
case, but a) only a single key is allowed, and b) the key is evaluated.
(define-record NAME SLOTNAME ...)Defines a record type. Call
make-NAMEto create an instance of the structure (with one initialization-argument for each slot).(NAME? STRUCT)tests any object for being an instance of this structure. Slots are accessed via(NAME-SLOTNAME STRUCT)and updated using(NAME-SLOTNAME-set!STRUCTVALUE).(define-record point x y) (define p1 (make-point 123 456)) (point? p1) ==> #t (point-x p1) ==> 123 (point-y-set! p1 99) (point-y p1) ==> 99
(define-record-printer (NAME RECORDVAR PORTVAR) BODY ...) (define-record-printer NAME PROCEDURE)Defines a printing method for record of the type
NAMEby associating a procedure with the record type. When a record of this type is written usingdisplay, writeor(define-record foo x y z) (define f (make-foo 1 2 3)) (define-record-printer (foo x out) (fprintf out "#,(foo ~S ~S ~S)" (foo-x x) (foo-y x) (foo-z x)) ) (define-reader-ctor 'foo make-foo) (define s (with-output-to-string (lambda () (write f)))) s ==> "#,(foo 1 2 3)" (equal? f (with-input-from-string s read))) ==> #t
define-record-printerworks also with SRFI-9 record types.
(define-record-type NAME (CONSTRUCTOR TAG ...) PREDICATE (FIELD ACCESSOR [MODIFIER]) ...)SRFI-9 record types. For more information see the documentation for SRFI-9.
(assert EXP [STRING ARG ...])Signals an error if
EXPevaluates to false. An optional messageSTRINGand argumentsARG ...may be supplied to give a more informative error-message. If compiled in unsafe mode (either by specifying the-unsafecompiler option or by declaring(unsafe)), then this expression expands to an unspecified value. The result is the value ofEXP.
(cond-expand FEATURE-CLAUSE ...)SRFI-0. Expands by selecting feature clauses. Predefined feature-identifiers are
srfi-0,srfi-2,srfi-6,srfi-8,srfi-9,srfi-10, andchicken. If the source file containing this form is currently compiled, the featurecompilingis defined. For further information, see the documentation for SRFI-0 This form is allowed to appear in non-toplevel expressions.
(critical-section BODY ...)Evaluate
BODY ...with timer-interrupts temporarily disabled.
(ensure PREDICATE EXP [ARGUMENTS ...])Evaluates the expression
EXPand applies the one-argument procedurePREDICATEto the result. If the predicate returns#fan error is signaled, otherwise the result ofEXPis returned. If compiled in unsafe mode (either by specifying the-unsafecompiler option or by declaring(unsafe)), then this expression expands to an unspecified value. If specified, the optionalARGUMENTSare used as arguments to the invocation of the error-signalling code, as in(error ARGUMENTS ...). If noARGUMENTSare given, a generic error message is displayed with the offending value andPREDICATEexpression.
(eval-when (SITUATION ...) EXP ...)Controls evaluation/compilation of subforms.
SITUATIONshould be one of the symbolseval,compileorload. When encountered in the evaluator, and the situation specifierevalis not given, then this form is not evaluated and an unspecified value is returned. When encountered while compiling code, and the situation specifiercompileis given, then this form is evaluated at compile-time. When encountered while compiling code, and the situation specifierloadis not given, then this form is ignored and an expression resulting into an unspecified value is compiled instead.The following table should make this clearer:
in compiled code In interpreted code evalignore evaluate compileevaluate at compile time ignore loadcompile as normal ignore The situation specifiers
compile-timeandrun-timeare also defined and have the same meaning ascompileandload, respectively.
(include STRING)Include toplevel-expressions from the given source file in the currently compiled/interpreted program. If the included file has the extension
.scm, then it may be omitted. The file is searched in the current directory and, if not found, in all directories specified in the-include-pathoption.
(nth-value N EXP)Returns the
Nth value (counting from zero) of the values returned by expressionEXP.
(time EXP1 ...)Evaluates
EXP1 ...and prints elapsed time and some values about GC use, like time spent in major GCs, number of minor and major GCs.
(This description has been taken mostly from Andrew Wright's postscript document)
Pattern matching allows complicated control decisions based on data
structure to be expressed in a concise manner. Pattern matching is
found in several modern languages, notably Standard ML, Haskell and
Miranda. These syntactic extensions internally use the match-support
library unit.
The basic form of pattern matching expression is:
(match exp [pat body] ...)
where exp is an expression, pat is a pattern, and
body is one or more expressions
(like the body of a lambda-expression).
The match form matches its first subexpression against a sequence
of patterns, and branches to the body
corresponding to the first pattern successfully matched.
For example, the following code defines the usual map function:
(define map
(lambda (f l)
(match l
[() ()]
[(x . y) (cons (f x) (map f y))])))
The first pattern () matches the empty list. The second pattern
(x . y) matches a pair, binding x to the first component of
the pair and y to the second component of the pair.
The complete syntax of the pattern matching expressions follows:
exp ::= (match exp clause ...)
| (match-lambda clause ...)
| (match-lambda* clause ...)
| (match-let ([pat exp] ...) body)
| (match-let* ([pat exp] ...) body)
| (match-letrec ([pat exp] ...) body)
| (match-let var ([pat exp] ...) body)
| (match-define pat exp)
clause ::= [pat body]
| [pat (=> identifier) body]
pat ::= identifier matches anything, and binds identifier as a variable
| _ anything
| () itself (the empty list)
| #t itself
| #f itself
| string an `equal?' string
| number an `equal?' number
| character an `equal?' character
| 's-expression an `equal?' s-expression
| (pat-1 ... pat-n) a proper list of n elements
| (pat-1 ... pat-n . pat-n+1)
a list of n or more elements
| (pat-1 ... pat-n pat-n+1 ..k)
a proper list of n+k or more elements [1]
| #(pat-1 ... pat-n) a vector of n elements
| #(pat-1 ... pat-n pat-n+1 ..k)
a vector of n+k or more elements
| ($ struct pat-1 ... pat-n)
a structure
| (= field pat) a field of a structure
| (and pat-1 ... pat-n)
if all of pat-1 through pat-n match
| (or pat-1 ... pat-n)
if any of pat-1 through pat-n match
| (not pat-1 ... pat-n)
if none of pat-1 through pat-n match
| (? predicate pat-1 ... pat-n)
if predicate true and pat-1 through pat-n all match
| (set! identifier) anything, and binds identifier as a setter
| (get! identifier) anything, and binds identifier as a getter
| `qp a quasipattern
qp ::= () itself (the empty list)
| #t itself
| #f itself
| string an `equal?' string
| number an `equal?' number
| character an `equal?' character
| symbol an `equal?' symbol
| (qp-1 ... qp-n) a proper list of n elements
| (qp-1 ... qp-n . qp-n+1)
a list of n or more elements
| (qp-1 ... qp-n qp-n+1 ..k)
a proper list of n+k or more elements
| #(qp-1 ... qp-n) a vector of n elements
| #(qp-1 ... qp-n qp-n+1 ..k)
a vector of n+k or more elements
| ,pat a pattern
| ,@pat a pattern, spliced
The notation ..k denotes a keyword consisting of
three consecutive dots (ie., “...”),
or two dots and an non-negative integer (eg., “..1”, “..2”),
or three consecutive underscores (ie., “___”),
or two underscores and a non-negative integer.
The keywords “..k” and “__ k” are equivalent.
The keywords “...”, “___”, “..0”, and “__0”
are equivalent.
The next subsection describes the various patterns.
The match-lambda and match-lambda* forms are convenient
combinations of match and lambda, and can be explained
as follows:
(match-lambda [pat body] ...) = (lambda (x) (match x [pat body] ...))
(match-lambda* [pat body] ...) = (lambda x (match x [pat body] ...))
where x is a unique variable.
The match-lambda form is convenient when defining a single argument
function that immediately destructures its argument.
The match-lambda* form constructs a function that accepts any number
of arguments; the patterns of match-lambda* should be lists.
The match-let, match-let*, match-letrec,
and match-define forms generalize
Scheme's let, let*, letrec, and define
expressions to allow
patterns in the binding position rather than just variables.
For example, the following expression:
(match-let ([(x y z) (list 1 2 3)]) body ...)
binds x to 1, y to 2, and z to 3 in body ....
These forms are convenient for destructuring the result
of a function that returns multiple values as a list or vector.
As usual for letrec and define,
pattern variables bound by match-letrec and match-define
should not be used in computing the bound value.
The match, match-lambda, and match-lambda* forms
allow the optional syntax (=> identifier) between the pattern
and the body of a clause. When the pattern match for such a clause
succeeds, the identifier is bound to a `failure
procedure' of zero arguments within the body. If this
procedure is invoked, it jumps back to the pattern matching
expression, and resumes the matching process as if the pattern had
failed to match. The body must not mutate the object being
matched, otherwise unpredictable behavior may result.
identifier: (excluding the reserved names
?, ,, =, _, and, or, not, set!, get!, ..., and
..k for non-negative integers k)
matches anything, and binds a variable of this name to
the matching value in the body.
_:
matches anything, without binding any variables.
(), #t, #f, string, number,
character, 's-expression:
These constant patterns match themselves, i.e.,
the corresponding value must be equal? to the pattern.
(pat-1 ... pat-n):
matches a proper list of n elements
that match pat-1 through pat-n.
(pat-1 ... pat-n . pat-n+1):
matches a (possibly improper) list of at least n
elements that ends in
something matching pat-n+1.
(pat-1 ... pat-n pat-n+1 ...):
matches a proper list of n or more elements, where
each element of the tail matches pat-n+1. Each pattern variable in
pat-n+1 is bound to a list of the matching values. For example,
the expression:
(match '(let ([x 1][y 2]) z)
[('let ((binding values) ...) exp) body])
binds binding to the list '(x y),
values to the list \'(1 2),
and exp to 'z
in the body of the match-expression.
For the special case where pat-n+1 is a pattern variable, the list
bound to that variable may share with the matched value.
(pat-1 ... pat-n pat-n+1 ___):
This pattern means the same thing as the previous pattern.
(pat-1 ... pat-n pat-n+1 ..k):
This pattern is similar to the previous pattern, but the tail must be
at least k elements long.
The pattern keywords ..0 and ... are equivalent.
(pat-1 ... pat-n ~ pat-n+1 __k):
This pattern means the same thing as the previous pattern.
#(pat-1 ... pat-n):
matches a vector of length n, whose elements match
pat-1 through pat-n.
#(pat-1 ... pat-n pat-n+1 ...):
matches a vector of length n or more, where each element
beyond n matches pat-n+1.
#(pat-1 ... pat-n pat-n+1 ..k):
matches a vector of length n+k or more, where each element
beyond n matches pat-n+1.
($ struct pat-1 ... pat-n):
matches a structure
declared with define-record or define-record-type.
(= field pat):
is intended for selecting a field from a structure. “field” may be
any expression; it is applied to the value being matched, and the
result of this application is matched against pat.
(and pat-1 ... pat-n):
matches if all of the subpatterns match.
At least one subpattern must be present.
This pattern is often used as (and x pat) to bind x to
to the entire value that matches pat
(cf. “as-patterns” in ML or Haskell).
(or pat-1 ... pat-n):
matches if any of the subpatterns match.
At least one subpattern must be present.
All subpatterns must bind the same set of pattern variables.
(not pat-1 ... pat-n):
matches if none of the subpatterns match.
At least one subpattern must be present.
The subpatterns may not bind any pattern variables.
(? predicate pat-1 ... pat-n):
In this pattern,
predicate must be an expression evaluating to a single argument
function.
This pattern matches if predicate applied to the corresponding value
is true, and the subpatterns pat-1 ... pat-n all match.
The predicate should not have side effects, as
the code generated by the pattern matcher may invoke predicates repeatedly
in any order.
The predicate expression is bound in the same scope as the
match expression, i.e.,
free variables in predicate are not bound by pattern variables.
(set! identifier):
matches anything, and binds identifier
to a procedure of one argument that mutates the corresponding field of
the matching value.
This pattern must be nested within a pair, vector, box, or structure
pattern. For example, the expression:
(define x (list 1 (list 2 3)))
(match x [(_ (_ (set! setit))) (setit 4)])
mutates the cadadr of x to 4, so that x is
'(1 (2 4)).
(get! identifier):
matches anything, and binds identifier
to a procedure of zero arguments that accesses the corresponding field of
the matching value. This pattern is the complement to set!.
As with set!,
this pattern must be nested within a pair, vector, box, or structure
pattern.
Quasipatterns:
Quasiquote introduces a quasipattern, in which identifiers are considered
to be symbolic constants. Like Scheme's quasiquote for data,
unquote (,) and unquote-splicing (,@) escape back to
normal patterns.
If no clause matches the value, the default action
is to invoke the procedure ##sys#match-error
with the value that did not match. The default definition of
##sys#match-error calls error with an appropriate message:
#;1> (match 1 (2 2)) Failed match: Error: no matching clause for : 1
For most situations, this behavior is adequate, but it can be changed
by altering the value of the parameter match-error-control:
(match-error-control [MODE])Selects a mode that specifies how
match...macro forms are to be expanded. With no argument this procedure returns the current mode. A single argument specifies the new mode that decides what should happen if no match-clause applies. The following modes are supported:
#:error- Signal an error. This is the default.
#:match- Signal an error and output the offending form.
#:fail- Omits
pair?tests when the consequence is to fail incarorcdrrather than to signal an error.#:unspecified- Non-matching expressions will either fail in
carorcdror return an unspecified value. This mode applies to files compiled with theunsafeoption or declaration.When an error is signalled, the raised exception will be of kind
(exn match).
Note: the $ pattern handles native record structures and SRFI-9 records transparently.
Currently it is required that SRFI-9 record predicates are named exactly like the record type
name, followed by a ? (question mark) character.
Pattern matching macros are compiled into if-expressions
that decompose the value being matched with standard
Scheme procedures, and test the components with standard predicates.
Rebinding or lexically shadowing the names of any of these procedures
will change the
semantics of the match macros. The names that should not be
rebound or shadowed are:
null? pair? number? string? symbol? boolean? char? procedure? vector? list?
equal?
car cdr cadr cdddr ...
vector-length vector-ref
reverse length call/cc
Additionally, the code generated to match a structure pattern like
($ Foo pat-1 ... pat-n)
refers to the name Foo?.
This name also should not be shadowed.
(declare DECLSPEC ...)Process declaration specifiers. Declarations always override any command-line settings. Declarations are valid for the whole compilation-unit (source file), the position of the declaration in the source file can be arbitrary. Declarations are ignored in the interpreter but not in code evaluated at compile-time (by
eval-whenor in syntax extensions loaded viarequire-extensionorrequire-for-syntax.DECLSPECmay be any of the following:— declaration specifier: always-bound
(always-bound SYMBOL ...)Declares that the given variables are always bound and accesses to those have not to be checked.
— declaration specifier: block
(block)Assume global variables are never redefined. This is the same as specifying the
-blockoption.— declaration specifier: block-global
— declaration specifier: hide
(block-global SYMBOL ...) (hide SYMBOL ...)Declares that the toplevel bindings for
SYMBOL ...should not be accessible from code in other compilation units or byeval. Access to toplevel bindings declared as block global is also more efficient.— declaration specifier: bound-to-procedure
(bound-to-procedure SYMBOL ...)Declares that the given identifiers are always bound to procedure values.
— declaration specifier: c-options
(c-options STRING ...)Declares additional C/C++ compiler options that are to be passed to the subsequent compilation pass that translates C to machine code. This declaration will only work if the source file is compiled with the
csccompiler driver.— declaration specifier: check-c-syntax
(check-c-syntax) (not check-c-syntax)Enables or disables syntax-checking of embedded C/C++ code fragments. Checking C syntax is the default.
— declaration specifier: compress-literals
(compress-literals [THRESHOLD [INITIALIZER]])The same as the
-compress-literalscompiler option. The threshold argument defaults to 50. If the optional argumentINITIALIZERis given, then the literals will not be created at module startup, but when the procedure with this name will be called.— declaration specifier: export
(export SYMBOL ...)The opposite of
hide. All given identifiers will be exported and all toplevel variables not listed will be hidden and not be accessible outside of this compilation unit.— declaration specifier: emit-external-prototypes-first
(emit-external-prototypes-first)Emit prototypes for callbacks defined with
define-externalbefore any other foreign declarations. Equivalent to giving the-emit-external-prototypes-firstoption to the compiler.— declaration specifier: disable-interrupts
(disable-interrupts) (not interrupts-enabled)Disable timer-interrupts checks in the compiled program. Threads can not be preempted in main- or library-units that contain this declaration.
— declaration specifier: inline
(inline) (not inline) (inline IDENTIFIER ...) (not inline IDENTIFIER ...)If given without an identifier-list, inlining of known procedures is enabled (this is equivalent to the
-inlinecompiler option). When an identifier-list is given, then inlining is enabled only for the specified global procedures. The negated forms(not inline)and(not inline IDENTIFIER)disable global inlining, or inlining for the given global procedures only, respectively.— declaration specifier: inline-limit
(inline-limit THRESHOLD)Sets the maximum size of procedures which may potentially be inlined. The default threshold is
10.— declaration specifier: interrupts-enabled
(interrupts-enabled)Enable timer-interrupts checks in the compiled program (the default).
— declaration specifier: lambda-lift
(lambda-lift)Enables lambda-lifting (equivalent to the
-lambda-liftoption).— declaration specifier: link-options
(link-options STRING ...)Declares additional linker compiler options that are to be passed to the subsequent compilation pass that links the generated code into an executable or library. This declaration will only work if the source file is compiled with the
csccompiler driver.— declaration specifier: no-bound-checks
(no-bound-checks)Disables the bound-checking of toplevel bindings.
— declaration specifier: no-procedure-checks
(no-procedure-checks)Disables checking of values in operator position for being of procedure type.
— declaration specifier: post-process
(post-process STRING ...)Arranges for the shell commands
STRING ...to be invoked after the current file has been translated to C. Any occurrences of the substring$@in the strings given for this declaration will be replaced by the pathname of the currently compiled file, without the file-extension. This declaration will only work if the source file is compiled with thecsccompiler driver.— declaration specifier: TYPE
— declaration specifier: fixnum-arithmetic
([number-type] TYPE) (fixnum-arithmetic)Declares that only numbers of the given type are used.
TYPEmay befixnumorgeneric(which is the default).— declaration specifier: run-time-macros
(run-time-macros)Equivalent to the compiler option of the same name - macros defined in the compiled code are also made available at runtime.
— declaration specifier: standard-bindings
(standard-bindings SYMBOL ...) (not standard-bindings SYMBOL ...)Declares that all given standard procedures (or all if no symbols are specified) are never globally redefined. If
notis specified, then all but the given standard bindings are assumed to be never redefined.— declaration specifier: extended-bindings
(extended-bindings SYMBOL ...) (not extended-bindings SYMBOL ...)Declares that all given non-standard and CHICKEN-specific procedures (or all if no symbols are specified) are never globally redefined. If
notis specified, then all but the given extended bindings are assumed to be never redefined.— declaration specifier: usual-integrations
(usual-integrations SYMBOL ...) (not usual-integrations SYMBOL ...)Declares that all given standard and extended bindings (or all if no symbols are specified) are never globally redefined. If
notis specified, then all but the given standard and extended bindings are assumed to be never redefined. Note that this is the default behaviour, unless the-no-usual-integrationsoption has been given.— declaration specifier: unsafe
(unsafe) (not safe)Do not generate safety-checks. This is the same as specifying the
-unsafeoption. Also implies(declare (no-bound-checks) (no-procedure-checks) (no-argc-checks))— declaration specifier: uses
(uses SYMBOL ...)Gives a list of used library-units. Before the toplevel-expressions of the main-module are executed, all used units evaluate their toplevel-expressions in the order in which they appear in this declaration. If a library unit A uses another unit B, then B's toplevel expressions are evaluated before A's. Furthermore, the used symbols are registered as features during compile-time, so
cond-expandknows about them.
Certain behavior of the interpreter and compiled programs can be customized via 'parameters', where a parameter is a procedure of zero or one arguments. To retrieve the value of a parameter call the parameter-procedure with zero arguments. To change the setting of the parameter, call the parameter-procedure with the new value as argument:
(define foo (make-parameter 123)) (foo) ==> 123 (foo 99) (foo) ==> 99
Parameters are fully thread-local, each thread of execution owns a local copy of a parameters' value.
CHICKEN implements SRFI-39
(make-parameter VALUE [GUARD])Returns a procedure that accepts zero or one argument. Invoking the procedure with zero arguments returns
VALUE. Invoking the procedure with one argument changes its value to the value of that argument (subsequent invocations with zero parameters return the new value).GUARDshould be a procedure of a single argument. Any new values of the parameter (even the initial value) are passed to this procedure. The guard procedure should check the value and/or convert it to an appropriate form.
If true, then
readreads symbols and identifiers in case-sensitive mode and uppercase characters in symbols are printed escaped. Defaults to#t.
A list of strings containing shared libraries that should be checked for explicitly loaded library units (this facility is not available on all platforms). See
load-library.
Contains the list of arguments passed to this program, with the name of the program and any runtime options (all options starting with
-:) removed.
A read-table object that holds read-procedures for special non-standard read-syntax (see
set-read-syntax!for more information).
A procedure of a single optional argument. When
exitis called, then this procedure will be invoked with the exit-code as argument. The default behavior is to terminate the program.
A procedure of one or two arguments. When
evalis invoked, it calls the value of this parameter with the same arguments. The default behavior is to evaluate the argument expression and to ignore the second parameter.
If true, force and execute all pending finalizers before exiting the program (either explicitly by
exitor implicitly when the last toplevel expression has been executed). Default is#t.
A procedure of no arguments. When the last toplevel expression of the program has executed, then the value of this parameter is called. The default behaviour is to invoke all pending finalizers.
Enables alternative keyword syntax, where
STYLEmay be either#:prefix(as in Common Lisp) or#:suffix(as in DSSSL). Any other value disables the alternative syntaxes.
A boolean indicating whether loading of source files, compiled code (if available) and compiled libraries should display a message.
A procedure that should evaluate to a string that will be printed before reading interactive input from the user in a read-eval-print loop. Defaults to
(lambda () "#;N> ").
A procedure of zero arguments that is called via
reset. The default behavior in compiled code is to invoke the value of(exit-handler). The default behavior in the interpreter is to abort the current computation and to restart the read-eval-print loop.
This unit contains basic Scheme definitions. This unit is used by default, unless the program
is compiled with the -explicit-use option.
(bitwise-and N1 ...) (bitwise-ior N1 ...) (bitwise-xor N1 ...) (bitwise-not N) (arithmetic-shift N1 N2)Binary integer operations.
arithmetic-shiftshifts the argumentN1byN2bits to the left. IfN2is negative, thanN1is shifted to the right. These operations only accept exact integers or inexact integers in word range (32 bit signed on 32-bit platforms, or 64 bit signed on 64-bit platforms).
(fx+ N1 N2) (fx- N1 N2) (fx* N1 N2) (fx/ N1 N2) (fxmod N1 N2) (fxneg N) (fxmin N1 N2) (fxmax N1 N2) (fx= N1 N2) (fx> N1 N2) (fx< N1 N2) (fx>= N1 N2) (fx<= N1 N2) (fxand N1 N2) (fxior N1 N2) (fxxor N1 N2) (fxnot N) (fxshl N1 N2) (fxshr N1 N2)Arithmetic fixnum operations. These procedures do not check their arguments, so non-fixnum parameters will result in incorrect results.
fxnegnegates its argument.On division by zero,
fx/andfxmodsignal a condition of kind(exn arithmetic).
fxshlandfxshrperform arithmetic shift left and right, respectively.
(fp+ N1 N2) (fp- N1 N2) (fp* N1 N2) (fp/ N1 N2) (fpneg N) (fpmin N1 N2) (fpmax N1 N2) (fp= N1 N2) (fp> N1 N2) (fp< N1 N2) (fp>= N1 N2) (fp<= N1 N2)Arithmetic floating-point operations. These procedures do not check their arguments, so non-flonum parameters will result in incorrect results. On division by zero,
fp/signals a condition of kind(exn arithmetic).
(signum N)Returns
1ifNis positive,-1ifNis negative or0ifNis zero.signumis exactness preserving.
(current-error-port [PORT])Returns default error output port. If
PORTis given, then that port is selected as the new current error output port.
(flush-output [PORT])Write buffered output to the given output-port.
PORTdefaults to the value of(current-output-port).
(port-name PORT)Fetch filename from
PORT. This returns the filename that was used to open this file. Returns a special tag string, enclosed into parentheses for non-file ports.
(port-position PORT)Returns the current position of
PORTas two values: row and column number. If the port does not support such an operation an error is signaled. This procedure is currently only available for input ports.
(delete-file STRING)Deletes the file with the pathname
STRING. If the file does not exist, an error is signaled.
(file-exists? STRING)Returns
STRINGif a file with the given pathname exists, or#fotherwise.
(rename-file OLD NEW)Renames the file or directory with the pathname
OLDtoNEW. If the operation does not succeed, an error is signaled.
(get-output-string PORT)Returns accumulated output of a port created with
(open-output-string).
(open-output-string)Returns a port for accumulating output in a string.
CHICKEN maintains a global list of “features” naming functionality available
int the current system. Additionally the cond-expand form accesses this
feature list to infer what features are provided. Predefined features are
chicken, and the SRFIs (Scheme Request For Implementation) provided by the
base system: srfi-23, srfi-30, srfi-39. If the eval unit
is used (the default), the features srfi-0, srfi-2, srfi-6, srfi-8, srfi-9
and srfi-10 are defined. When compiling code (during compile-time) the
feature compiling is registered. When evaluating code in the interpreter
(csi), the feature csi is registered.
(features)Returns a list of all registered features that will be accepted as valid feature-identifiers by
cond-expand.
(test-feature? ID ...)Returns
#tif all features with the given feature-identifiersID ...are registered.
(register-feature! FEATURE ...)Register one or more features that will be accepted as valid feature-identifiers by
cond-expand.FEATURE ...may be a keyword, string or symbol.
(unregister-feature! FEATURE ...)Unregisters the specified feature-identifiers.
FEATURE ...may be a keyword, string or symbol.
Keywords are special symbols prefixed with #: that evaluate
to themselves. Procedures can use keywords to accept optional named
parameters in addition to normal required parameters. Assignment to
and bindings of keyword symbols is not allowed.
The parameter keyword-style and the compiler/interpreter option
-keyword-style can be used to allow an additional keyword
syntax, either compatible to Common LISP, or to DSSSL.
(get-keyword KEYWORD ARGLIST [THUNK])Returns the argument from
ARGLISTspecified under the keywordKEYWORD. If the keyword is not found, then the zero-argument procedureTHUNKis invoked and the result value is returned. IfTHUNKis not given,#fis returned.(define (increase x . args) (+ x (get-keyword #:amount args (lambda () 1))) ) (increase 123) ==> 124 (increase 123 #:amount 10) ==> 133Note: the
KEYWORDmay actually be any kind of object.
CHICKEN implements the (currently withdrawn) SRFI-12 exception system. For more information, see the SRFI-12 document
(condition-case EXPRESSION CLAUSE ...)Evaluates
EXPRESSIONand handles any exceptions that are covered byCLAUSE ..., whereCLAUSEshould be of the following form:CLAUSE = ([VARIABLE] (KIND ...) BODY ...)If provided,
VARIABLEwill be bound to the signalled exception object.BODY ...is executed when the exception is a property- or composite condition with the kinds givenKIND ...(unevaluated). If no clause applies, the exception is re-signalled in the same dynamic context as thecondition-caseform.(define (check thunk) (condition-case (thunk) [(exn file) (print "file error")] [(exn) (print "other error")] [var () (print "something else")] ) ) (check (lambda () (open-input-file ""))) ; -> "file error" (check (lambda () some-unbound-variable)) ; -> "othererror" (check (lambda () (signal 99))) ; -> "something else" (condition-case some-unbound-variable [(exn file) (print "ignored)] ) ; -> signals error
All error-conditions signalled by the system are of kind exn.
The following composite conditions are additionally defined:
(exn arity)(exn type)(exn arithmetic)(exn i/o)(exn i/o file)(exn i/o net)(exn bounds)(exn runtime)(exn runtime limit)(exn match)match).
(exn syntax)Notes:
exn) are non-continuable.
exn kind have additional
arguments and location properties that contain the
arguments passed to the error-handler and the name of the procedure
where the error occurred (if available).
posix unit is available and used, then a
user-interrupt (signal/int) signals an exception of the kind
user-interrupt.
condition-property-accessor accepts an optional
third argument. If the condition does not have a value for the desired property
and if the optional argument is given, no error is signalled and
the accessor returns the third argument.
(argv)Return a list of all supplied command-line arguments. The first item in the list is a string containing the name of the executing program. The other items are the arguments passed to the application. This list is freshly created on every invocation of
(argv). It depends on the host-shell whether arguments are expanded ('globbed') or not.
(exit [CODE])Exit the running process and return exit-code, which defaults to 0 (Invokes
exit-handler).
(build-platform)Returns a symbol specifying the toolset which has been used for building the executing system, which is one of the following:
cygwin msvc mingw32 gnu metrowerks intel watcom unknown
(chicken-version [FULL])Returns a string containing the version number of the CHICKEN runtime system. If the optional argument
FULLis given and true, then a full version string is returned.
(getenv STRING)Returns the value of the environment variable
STRINGor#fif that variable is not defined.
(machine-type)Returns a symbol specifying the processor on which this process is currently running, which is one of the following:
alpha mips hppa ultrasparc sparc ppc ppc64 ia64 x86 x86-64 unknown
(software-type)Returns a symbol specifying the operating system on which this process is currently running, which is one of the following:
windows unix macos ecos unknown
(software-version)Returns a symbol specifying the operating system version on which this process is currently running, which is one of the following:
linux freebsd netbsd openbsd macosx hpux solaris sunos unknown
(c-runtime)Returns a symbol that designates what kind of C runtime library has been linked with this version of the Chicken libraries. Possible return values are
static,dynamicorunknown. On systems not compiled with the Microsoft C compiler,c-runtimealways returnsunknown.
(chicken-home)Returns a string given the installation directory (usually
/usr/local/share/chickenon UNIX-like systems). If the environment variableCHICKEN_HOMEis set, then its value will be returned.
(system STRING)Execute shell command. The functionality offered by this procedure depends on the capabilities of the host shell.
(cpu-time)Returns the used CPU time of the current process in milliseconds as two values: the time spent in user code, and the time spent in system code. On platforms where user and system time can not be differentiated, system time will be always be 0.
(current-milliseconds)Returns the number of milliseconds since process- or machine startup.
(current-seconds)Returns the number of seconds since midnight, Jan. 1, 1970.
(current-gc-milliseconds)Returns the number of milliseconds spent in major garbage collections since the last call of
current-gc-millisecondsand returns an exact integer.
(enable-interrupts) (disable-interrupts)Enables/disables processing of timer-interrupts and interrupts caused by signals.
(disable-interrupts) (disable-interrupts) (enable-interrupts) ; <interrupts still disabled - call enable-interrupts once more>
(enable-warnings [BOOL])Enables or disables warnings, depending on wether
BOOLis true or false. If called with no arguments, this procedure returns#tif warnings are currently enabled, or#fotherwise. Note that this is not a parameter. The current state (wether warnings are enabled or disabled) is global and not thread-local.
(error [LOCATION] STRING EXP ...)Prints error message, writes all extra arguments to the value of
(current-error-port)and invokes the current value of(error-handler). This conforms to SRFI-23. IfLOCATIONis given and a symbol, it specifies the “location” (the name of the procedure) where the error occurred.
(get-call-chain [START [THREAD]])Returns a list with the call history. Backtrace information is only generated in code compiled without
-no-traceand evaluated code. If the optional argumentSTARTis given, the backtrace starts at this offset, i.e. whenSTARTis 1, the next to last trace-entry is printed, and so on. If the optional argumentTHREADis given, then the call-chain will only be constructed for calls performed by this thread.
(print-call-chain [PORT [START [THREAD]]])Prints a backtrace of the procedure call history to
PORT, which defaults to(current-error-port).
(print-error-message EXN [PORT [STRING]])Prints an appropriate error message to
PORT(which defaults to the value of(current-output-port)for the objectEXN.EXNmay be a condition, a string or any other object. If the optional argumentSTRINGis given, it is printed before the error-message.STRINGdefaults to"Error:".
(procedure-information PROC)Returns an s-expression with debug information for the procedure
PROC, or#f, ifPROChas no associated debug information.
(warning STRING EXP ...)Displays a warning message (if warnings are enabled with
enable-warnings) and continues execution.
(gc [FLAG])Invokes a garbage-collection and returns the number of free bytes in the heap. The flag specifies whether a minor (
#f) or major (#t) GC is to be triggered. If no argument is given,#tis assumed. When the argument is#t, all pending finalizers are executed.
(memory-statistics)Performs a major garbage collection and returns a three element vector containing the total heap size in bytes, the number of bytes currently used and the size of the nursery (the first heap generation). Note that the actual heap is actually twice the size given in the heap size, because CHICKEN uses a copying semi-space collector.
(set-finalizer! X PROC)Registers a procedure of one argument
PROC, that will be called as soon as the non-immediate data objectXis about to be garbage-collected (with that object as its argument). Note that the finalizer will not be called when interrupts are disabled. This procedure returnsX.
(set-gc-report! FLAG)Print statistics after every GC, depending on
FLAG. A value of#tshows statistics after every major GC. A true value different from#tshows statistics after every minor GC.#fswitches statistics off.
(andmap PROC LIST1 ...)Repeatedly calls
PROCwith arguments taken fromLIST1 .... If any invocation should return#f, the result ofandmapis#f. If all invocations return a true result, then the result ofandmapis#t.
(ormap PROC LIST1 ...)Repeatedly calls
PROCwith arguments taken fromLIST1 .... If any invocation should return a value different from#f, then this value is returned as the result oformap. If all invocations return #f, then the result oformapis#f.
(reverse-list->string LIST)Returns a string with the characters in
LISTin reverse order. This is equivalent to(list->string (reverse LIST)), but much more efficient.
(gensym [STRING-OR-SYMBOL])Returns a newly created uninterned symbol. If an argument is provided, the new symbol is prefixed with that argument.
(string->uninterned-symbol STRING)Returns a newly created, unique symbol with the name
STRING.
(print EXP1 EXP2 ...)Outputs the arguments
EXP1 EXP2 ...usingdisplayand writes a newline character to the port that is the value of(current-output-port). Returns its first argument.
(print* EXP1 ...)Similar to
flush-outoutafter writing its arguments.
(char-name SYMBOL-OR-CHAR [CHAR])This procedure can be used to inquire about character names or to define new ones. With a single argument the behavior is as follows: If
SYMBOL-OR-CHARis a symbol, thenchar-namereturns the character with this name, or#fif no character is defined under this name. IfSYMBOL-OR-CHARis a character, then the name of the character is returned as a symbol, or#fif the character has no associated name.If the optional argument
CHARis provided, thenSYMBOL-OR-CHARshould be a symbol that will be the new name of the given character. If multiple names designate the same character, then thewritewill use the character name that was defined last.(char-name 'space) ==> #\space (char-name #\space) ==> space (char-name 'bell) ==> #f (char-name (integer->char 7)) ==> #f (char-name 'bell (integer->char 7)) (char-name 'bell) ==> #\bell (char->integer (char-name 'bell)) ==> 7
(vector-copy! VECTOR1 VECTOR2 [COUNT])Copies contents of
VECTOR1intoVECTOR2. If the argumentCOUNTis given, it specifies the maximal number of elements to be copied. If not given, the minimum of the lengths of the argument vectors is copied.Exceptions:
(exn bounds)
(vector-resize VECTOR N [INIT])Creates and returns a new vector with the contents of
VECTORand lengthN. IfNis greater than the original length ofVECTOR, then all additional items are initialized toINIT. IfINITis not specified, the contents are initialized to some unspecified value.
(continuation-capture PROCEDURE)Creates a continuation object representing the current continuation and tail-calls
PROCEDUREwith this continuation as the single argument.More information about this continuation API can be found in the paper http://repository.readscheme.org/ftp/papers/sw2001/feeley.pdf “A Better API for first class Continuations” by marc Feeley.
(continuation? X)Returns
#tifXis a continuation object, or#fotherwise.
(continuation-graft CONT THUNK)Calls the procedure
THUNKwith no arguments and the implicit continuationCONT.
(continuation-return CONT VALUE ...)Returns the value(s) to the continuation
CONT.continuation-resultcould be implemented like this:(define (continuation-return k . vals) (continuation-graft k (lambda () (apply values vals)) ) )
SRFI-17 is fully implemented. For more information see: SRFI-17
(setter PROCEDURE)Returns the setter-procedure of
PROCEDURE, or signals an error ifPROCEDUREhas no associated setter-procedure.Note that
(set! (setter PROC) ...)for a procedure that has no associated setter procedure yet is a very slow operation (the old procedure is replaced by a modified copy, which involves a garbage collection).
(getter-with-setter GETTER SETTER)Returns a copy of the procedure
GETTERwith the associated setter procedureSETTER. Contrary to the SRFI specification, the setter of the returned procedure may be changed.
This unit has support for evaluation and macro-handling. This unit is used
by default, unless the program is compiled with the -explicit-use
option.
(load FILE [EVALPROC])Loads and evaluates expressions from the given source file, which may be either a string or an input port. Each expression read is passed to
EVALPROC(which defaults toeval). On platforms that support it (currently native Windows, Linux ELF and Solaris),loadcan be used to load compiled programs:% cat x.scm (define (hello) (print "Hello!")) % csc -s x.scm % csi -q #;1> (load "x.so") ; loading x.so ... #;2> (hello) Hello! #;3>The second argument to
loadis ignored when loading compiled code. If source code is loaded from a port, then that port is closed after all expressions have been read.Compiled code can be re-loaded, but care has to be taken, if code from the replaced dynamically loaded module is still executing (i.e. if an active continuation refers to compiled code in the old module).
Support for realoding compiled code dynamically is still experimental.
(load-library UNIT [LIBRARYFILE])On platforms that support dynamic loading,
load-libraryloads the compiled library unitUNIT(which should be a symbol). If the stringLIBRARYFILEis given, then the given shared library will be loaded and the toplevel code of the contained unit will be executed. If noLIBRARYFILEargument is given, then the following libraries are checked for the required unit:
- a file named “
<UNIT>.so”- the files given in the parameter
dynamic-load-librariesIf the unit is not found, an error is signaled. When the library unit can be successfully loaded, a feature-identifier named
UNITis registered. If the feature is already registered before loading, theload-librarydoes nothing.
(load-noisily FILE #!key EVALUATOR TIME PRINTER)As
loadbut the result(s) of each evaluated toplevel-expression is written to standard output. IfEVALUATORis given and not#f, then each expression is evaluated by calling this argument with the read expression as argument. IfTIMEis given and not false, then the execution time of each expression is shown (as with thetimemacro). IfPRINTERis given and not false, then each expression is printed before evaluation by applying the expression to the value of this argument, which should be a one-argument procedure.
(set-dynamic-load-mode! MODELIST)On systems that support dynamic loading of compiled code via the
dlopen(3)interface (for example Linux and Solaris), some options can be specified to fine-tune the behaviour of the dynamic linker.MODEshould be a list of symbols (or a single symbol) taken from the following set:
localIflocalis given, then any C/C++ symbols defined in the dynamically loaded file are not available for subsequently loaded files and libraries. Use this if you have linked foreign code into your dynamically loadable file and if you don't want to export them (for example because you want to load another file that defines the same symbols).globalThe default isglobal, which means all C/C++ symbols are available to code loaded at a later stage.nowIfnowis specified, all symbols are resolved immediately.lazyUnresolved symbols are resolved as code from the file is executed. This is the default.Note that this procedure does not control the way Scheme variables are handled - this facility is mainly of interest when accessing foreign code.
(repl)Start a new read-eval-print loop. Sets the
reset-handlerso that any invocation ofresetrestarts the read-eval-print loop. Also changes the currenterror-handlerto display a message, write any arguments to the value of(current-error-port)and reset.
(get-line-number EXPR)If
EXPRis a pair with the car being a symbol, and line-number information is available for this expression, then this procedure returns the associated line number. If line-number information is not available, then#fis returned. Note that line-number information for expressions is only available in the compiler.
(macroexpand X)If
Xis a macro-form, expand the macro (and repeat expansion until expression is a non-macro form). Returns the resulting expression.
(macroexpand-1 X)If
Xis a macro-form, expand the macro. Returns the resulting expression.
(undefine-macro! SYMBOL)Remove the current macro-definition of the macro named
SYMBOL.
(syntax-error [LOCATION] MESSAGE ARGUMENT ...)Signals an exception of the kind
(exn syntax). Otherwise identical toerror.
This functionality is only available on platforms that support dynamic loading of compiled code. Currently Linux, BSD, Solaris, Windows (with Cygwin) and HP/UX are supported.
Contains a string naming the path to the extension repository, which defaults to either the value of the environment variable
CHICKEN_REPOSITORY, the value of the environment variableCHICKEN_HOMEor the default library path (usually/usr/local/lib/chickenon UNIX systems).
(extension-information ID)If an extension with the name
IDis installed and if it has a setup-information list registered in the extension repository, then the info-list is returned. Otherwiseextension-informationreturns#f.
(provide ID ...)Registers the extension IDs
ID ...as loaded. This is mainly intended to provide aliases for certain extension identifiers.
(provided? ID ...)Returns
#tif the extension with the IDsID ...are currently loaded, or#fotherwise. Works also for feature-ids.
(require ID ...) (require-for-syntax ID ...)If the extension library
IDis not already loaded into the system, thenrequirewill lookup the location of the shared extension library and load it. IfIDnames a library-unit of the base system, then it is loaded viaload-library. If no extension library is available for the given ID, then an attempt is made to load the fileID.soorID.scm(in that order) from one of the following locations:
- the current include path, which defaults to the pathnames given in
CHICKEN_INCLUDE_PATHandCHICKEN_HOME.- the current directory
IDshould be a string or a symbol. The difference betweenrequireandrequire-for-syntaxis the the latter loads the extension library at compile-time (the argument is still evaluated), while the former loads it at run-time.
(set-extension-specifier! SYMBOL PROC)Registers the handler-procedure
PROCas a extension-specifier with the nameSYMBOL. This facility allows extending the set of valid extension specifiers to be used withrequire-extension. Whenregister-extensionis called with an extension specifier of the form(SPEC ...)andSPEChas been registered withset-extension-specifier!, thenPROCwill be called with two arguments: the specifier and the previously installed handler (or#fif no such handler was defined). The handler should return a new specifier that will be processed recursively. If the handler returns a vector, then each element of the vector will be processed recursively. Alternatively the handler may return a string which specifies a file to be loaded:(eval-when (compile eval) (set-extension-specifier! 'my-package (lambda (spec old) (make-pathname my-package-directory (->string (cadr spec))) ) ) ) (require-extension (my-package stuff)) ; --> expands into '(load "my-package-dir/stuff")Note that the handler has to be registered at compile time, if it is to be visible in compiled code.
(define-reader-ctor SYMBOL PROC)Define new read-time constructor for
#,read syntax. For further information, see the documentation for SRFI-10.
(set-read-syntax! CHAR PROC)When the reader is encounting the non-whitespace character
CHARwhile reading an expression from a given port, then the procedurePROCwill be called with that port as its argument. The procedure should return a value that will be returned to the reader:; A simple RGB color syntax: (set-read-syntax! #\% (lambda (port) (apply vector (map (cut string->number <> 16) (string-chop (read-string 6 port) 2) ) ) ) ) (with-input-from-string "(1 2 %f0f0f0 3)" read) ; ==> (1 2 #(240 240 240) 3)You can undo special handling of read-syntax by passing
#fas the second argument (if the syntax was previously defined viaset-read-syntax!).Note that all of CHICKEN's special non-standard read-syntax is handled directly by the reader to disable built-in read-syntax, define a handler that triggers an error (for example).
(set-sharp-read-syntax! CHAR PROC)Similar to
set-read-syntax!, but allows defining new#<CHAR> ...reader syntax.
(copy-read-table READ-TABLE)Returns a copy of the given read-table. You can access the currently active read-table with
(current-read-table).
(eval EXP [ENVIRONMENT])Evaluates
EXPand returns the result of the evaluation. The second argument is optional and defaults to the value of(interaction-environment).
This unit contains a collection of useful utility definitions.
This unit is used by default, unless the program
is compiled with the -explicit-use option.
(alist-ref KEY ALIST [TEST [DEFAULT]])Looks up
KEYinALISTusingTESTas the comparison function (oreqv?if no test was given) and returns the cdr of the found pair, orDEFAULT(which defaults to#f).
(alist-update! KEY VALUE ALIST [TEST])If the list
ALISTcontains a pair of the form(KEY . X), then this procedure replacesXwithVALUEand returnsALIST. IfALISTcontains no such item, thenalist-update!returns((KEY . VALUE) . ALIST). The optional argumentTESTspecifies the comparison procedure to search a matching pair inALISTand defaults toeqv?.
(rassoc KEY LIST [TEST])Similar to
assoc, but comparesKEYwith thecdrof each pair inLISTusingTESTas the comparison procedures (which defaults toeqv?.
(chop LIST N)Returns a new list of sublists, where each sublist contains
Nelements ofLIST. IfLISThas a length that is not a multiple ofN, then the last sublist contains the remaining elements.(chop '(1 2 3 4 5 6) 2) ==> ((1 2) (3 4) (5 6)) (chop '(a b c d) 3) ==> ((a b c) (d))
(compress BLIST LIST)Returns a new list with elements taken from
LISTwith corresponding true values in the listBLIST.(define nums '(99 100 110 401 1234)) (compress (map odd? nums) nums) ==> (99 401)
(flatten LIST1 ...)Returns
LIST1 ...concatenated together, with nested lists removed (flattened).
(intersperse LIST X)Returns a new list with
Xplaced between each element.
(join LISTOFLISTS [LIST])Concatenates the lists in
LISTOFLISTSwithLISTplaced between each sublist.LISTdefaults to the empty list.(join '((a b) (c d) (e)) '(x y)) ==> (a b x y c d x y e) (join '((p q) () (r (s) t)) '(-)) ==> (p q - - r (s) t)
joincould be implemented as follows:(define (join lstoflsts #!optional (lst '())) (apply append (intersperse lstoflists lst)) )
(call-with-input-string STRING PROC)Calls the procedure
PROCwith a single argument that is a string-input-port with the contents ofSTRING.
(call-with-output-string PROC)Calls the procedure
PROCwith a single argument that is a string-output-port. Returns the accumulated output-string.
(with-input-from-string STRING THUNK)Call procedure
THUNKwith the current input-port temporarily bound to an input-string-port with the contents ofSTRING.
(with-output-to-string THUNK)Call procedure
THUNKwith the current output-port temporarily bound to a string-output-port and return the accumulated output string.
(fprintf PORT FORMATSTRING ARG ...) (printf FORMATSTRING ARG) (sprintf FORMATSTRING ARG ...) (format FORMATSTRING ARG ...)Simple formatted output to a given port (
fprintf), the value of(current-output-port)(printf) or a string (sprintf/format). TheFORMATSTRINGcan contain any sequence of characters. The character `~' prefixes special formatting directives:
~%- write newline character
~N- the same as
~%~S- write the next argument
~A- display the next argument
~\n- skip all whitespace in the format-string until the next non-whitespace character
~B- write the next argument as a binary number
~O- write the next argument as an octal number
~X- write the next argument as a hexadecimal number
~C- write the next argument as a character
~~- display `~'
~!- flush all pending output
~?- invoke formatted output routine recursively with the next two arguments as format-string and list of parameters
CHICKEN implements SRFI-69. For more information, see SRFI-69.
A setter for hash-table-ref is defined, so
(set! (hash-table-ref HT KEY) VAL)
is equivalent to
(hash-table-set! HT KEY VAL)
(list->queue LIST)Returns
LISTconverted into a queue, where the first element of the list is the same as the first element of the queue. The resulting queue may share memory with the list and the list should not be modified after this operation.
(queue->list QUEUE)Returns
QUEUEconverted into a list, where the first element of the list is the same as the first element of the queue. The resulting list may share memory with the queue object and should not be modified.
(queue-first QUEUE)Returns the first element of
QUEUE. IfQUEUEis empty an error is signaled
(queue-last QUEUE)Returns the last element of
QUEUE. IfQUEUEis empty an error is signaled
(queue-remove! QUEUE)Removes and returns the first element of
QUEUE. IfQUEUEis empty an error is signaled
(merge LIST1 LIST2 LESS?) (merge! LIST1 LIST2 LESS?)Joins two lists in sorted order.
merge!is the destructive version of merge.LESS?should be a procedure of two arguments, that returns true if the first argument is to be ordered before the second argument.
(sort SEQUENCE LESS?) (sort! SEQUENCE LESS?)Sort
SEQUENCE, which should be a list or a vector.sort!is the destructive version of sort.
(sorted? SEQUENCE LESS?)Returns true if the list or vector
SEQUENCEis already sorted.
(randomize [X])Set random-number seed. If
Xis not supplied, the current time is used. On startup (when theextrasunit is initialized), the random number generator is initialized with the current time.
(make-input-port READ READY? CLOSE [PEEK])Returns a custom input port. Common operations on this port are handled by the given parameters, which should be procedures of no arguments.
READis called when the next character is to be read and should return a character or#!eof.READY?is called whenchar-ready?is called on this port and should return#tor#f.CLOSEis called when the port is closed.PEEKis called whenpeek-charis called on this port and should return a character or#!eof. if the argumentPEEKis not given, thenREADis used instead and the created port object handles peeking automatically (by callingREADand buffering the character).
(make-output-port WRITE CLOSE [FLUSH])Returns a custom output port. Common operations on this port are handled by the given parameters, which should be procedures.
WRITEis called when output is sent to the port and receives a single argument, a string.CLOSEis called when the port is closed and should be a procedure of no arguments.FLUSH(if provided) is called for flushing the output port.
(pretty-print EXP [PORT]) (pp EXP [PORT])Print expression nicely formatted.
PORTdefaults to the value of(current-output-port).
Specifies the maximal line-width for pretty printing, after which line wrap will occur.
(read-file [FILE-OR-PORT [READER [MAXCOUNT]]])Returns a list containing all toplevel expressions read from the file or port
FILE-OR-PORT. If no argument is given, input is read from the port that is the current value of(current-input-port). After all expressions are read, and if the argument is a port, then the port will not be closed. TheREADERargument specifies the procedure used to read expressions from the given file or port and defaults toread. The reader procedure will be called with a single argument (an input port). IfMAXCOUNTis given then only up toMAXCOUNTexpressions will be read in.
(read-line [PORT [LIMIT]]) (write-line STRING [PORT])Line-input and -output.
PORTdefaults to the value of(current-input-port)and(current-output-port), respectively. if the optional argumentLIMITis given and not#f, thenread-linereads at mostLIMITcharacters per line.
(read-lines [PORT [MAX]])Read
MAXor fewer lines fromPORT.PORTdefaults to the value of(current-input-port).PORTmay optionally be a string naming a file.
(read-string [NUM [PORT]]) (write-string STRING [NUM [PORT]]Read or write
NUMcharacters from/toPORT, which defaults to the value of(current-input-port)or(current-output-port), respectively. IfNUMis#for not given, then all data up to the end-of-file is read, or, in the case ofwrite-stringthe whole string is written. If no more input is available,read-stringreturns the empty string.
(read-token PREDICATE [PORT])Reads characters from
PORT(which defaults to the value of(current-input-port)) and calls the procedurePREDICATEwith each character untilPREDICATEreturns false. Returns a string with the accumulated characters.
(with-error-output-to-port PORT THUNK)Call procedure
THUNKwith the current error output-port temporarily bound toPORT.
(with-input-from-port PORT THUNK)Call procedure
THUNKwith the current input-port temporarily bound toPORT.
(with-output-to-port PORT THUNK)Call procedure
THUNKwith the current output-port temporarily bound toPORT.
(conc X ...)Returns a string with the string-represenation of all arguments concatenated together.
conccould be implemented as(define (conc . args) (apply string-append (map ->string args)) )
(string-chop STRING LENGTH)Returns a list of substrings taken by “chopping”
STRINGeveryLENGTHcharacters:(string-chop "one two three" 4) ==> ("one " "two " "thre" "e")
(string-compare3-ci STRING1 STRING2)Perform a three-way comparison between the
STRING1andSTRING2, returning either-1ifSTRING1is lexicographically less thanSTRING2,0if it is equal, or1if it s greater.string-compare3-ciperforms a case-insensitive comparison.
(string-intersperse LIST [STRING])Returns a string that contains all strings in
LISTconcatenated together.STRINGis placed between each concatenated string and defaults to" ".(string-intersperse '("one" "two") "three")is equivalent to
(apply string-append (intersperse '("one" "two") "three"))
(string-split STRING [DELIMITER-STRING [KEEPEMPTY]])Split string into substrings separated by the given delimiters. If no delimiters are specified, a string comprising the tab, newline and space characters is assumed. If the parameter
KEEPEMPTYis given and not#f, then empty substrings are retained:(string-split "one two three") ==> ("one" "two" "three") (string-split "foo:bar::baz:" ":" #t) ==> ("foo" "bar" "" "baz" "")
(string-translate STRING FROM [TO])Returns a fresh copy of
STRINGwith characters matchingFROMtranslated toTO. IfTOis omitted, then matching characters are removed.FROMandTOmay be a character, a string or a list. If bothFROMandTOare strings, then the character at the same position inTOas the matching character inFROMis substituted.
(string-translate* STRING SMAP)Substitutes elements of
STRINGaccording toSMAP.SMAPshould be an association-list where each element of the list is a pair of the form(MATCH \. REPLACEMENT). Every occurrence of the stringMATCHinSTRINGwill be replaced by the stringREPLACEMENT:(string-translate* "<h1>this is a \"string\"</h1>" '(("<" . "<:") (">" . ">") ("\"" . """)) ) ==> "<h1>this is a "string"</ht>"
(substring=? STRING1 STRING2 [START1 [START2 [LENGTH]]]) (substring-ci=? STRING1 STRING2 [START1 [START2 [LENGTH]]])Returns
#tif the stringsSTRING1andSTRING2are equal, or#fotherwise. The comparison starts at the positionsSTART1andSTART2(which default to 0), comparingLENGTHcharacters (which defaults to the minimum of the remaining length of both strings).
(substring-index WHICH WHERE [START]) (substring-index-ci WHICH WHERE [START])Searches for first index in string
WHEREwhere stringWHICHoccurs. If the optional argumentSTARTis given, then the search starts at that index.substring-index-ciis a case-insensitive version ofsubstring-index.
(constantly X ...)Returns a procedure that always returns the values
X ...regardless of the number and value of its arguments.(constantly X) <=> (lambda args X)
(complement PROC)Returns a procedure that returns the boolean inverse of
PROC.(complement PROC) <=> (lambda (x) (not (PROC x)))
(compose PROC1 PROC2 ...)Returns a procedure that represents the composition of the argument-procedures
PROC1 PROC2 ....(compose F G) <=> (lambda args (call-with-values (lambda () (apply G args)) F))
(conjoin PRED ...)Returns a procedure that returns
#tif its argument satisfies the predicatesPRED ....((conjoin odd? positive?) 33) ==> #t ((conjoin odd? positive?) -33) ==> #f
(disjoin PRED ...)Returns a procedure that returns
#tif its argument satisfies any predicatePRED ....((disjoin odd? positive?) 32) ==> #t ((disjoin odd? positive?) -32) ==> #f
(each PROC ...)Returns a procedure that applies
PROC ...to its arguments, and returns the result(s) of the last procedure application. For example(each pp eval)is equivalent to
(lambda args (apply pp args) (apply eval args) )
(each PROC)is equivalent toPROCand(each)is equivalent tonoop.
(flip PROC)Returns a two-argument procedure that calls
PROCwith its arguments swapped:(flip PROC) <=> (lambda (x y) (PROC y x))
(project N)Returns a procedure that returns its
Nth argument (starting from 0).
(list-of PRED)Returns a procedure of one argument that returns
#twhen applied to a list of elements that all satisfy the predicate procedurePRED, or#fotherwise.((list-of even?) '(1 2 3)) ==> #f ((list-of number?) '(1 2 3)) ==> #t
(noop X ...)Ignores it's arguments, does nothing and returns an unspecified value.
(binary-search SEQUENCE PROC)Performs a binary search in
SEQUENCE, which should be a sorted list or vector.PROCis called to compare items in the sequence, should accept a single argument and return an exact integer: zero if the searched value is equal to the current item, negative if the searched value is “less” than the current item, and positive otherwise.
List library, see the documentation for SRFI-1
Homogeneous numeric vectors, see the documentation for SRFI-4.
64-bit integer vectors (u64vector and s64vector are not supported.
The basic constructor procedures for number vectors are extended to allow allocating the storage in non garbage collected memory:
(make-XXXvector SIZE [INIT NONGC FINALIZE])Creates a SRFI-4 homogenous number vector of length
SIZE. IfINITis given, it specifies the initial value for each slot in the vector. The optional argumentsNONGCandFINALIZEdefine whether the vector should be allocated in a memory area not subject to garbage collection and whether the associated storage should be automatically freed (using finalization) when there are no references from Scheme variables and data.NONGCdefaults to#f(the vector will be located in normal garbage collected memory) andFINALIZEdefaults to#t. Note that theFINALIZEargument is only used whenNONGCis true.
Additionally, the following procedures are provided:
(u8vector->byte-vector U8VECTOR) (s8vector->byte-vector S8VECTOR) (u16vector->byte-vector U16VECTOR) (s16vector->byte-vector S16VECTOR) (u32vector->byte-vector U32VECTOR) (s32vector->byte-vector S32VECTOR) (f32vector->byte-vector F32VECTOR) (f64vector->byte-vector F64VECTOR)Each of these procedures return the contents of the given vector as a 'packed' byte-vector. The byte order in that vector is platform-dependent (for example little-endian on an Intel processor). The returned byte-vector shares memory with the contents of the vector.
(byte-vector->u8vector BYTE-VECTOR) (byte-vector->s8vector BYTE-VECTOR) (byte-vector->u16vector BYTE-VECTOR) (byte-vector->s16vector BYTE-VECTOR) (byte-vector->u32vector BYTE-VECTOR) (byte-vector->s32vector BYTE-VECTOR) (byte-vector->f32vector BYTE-VECTOR) (byte-vector->f64vector BYTE-VECTOR)Each of these procedures return a vector where the argument
BYTE-VECTORis taken as a 'packed' representation of the contents of the vector. The argument-byte-vector shares memory with the contents of the vector.
(subu8vector U8VECTOR FROM TO) (subu16vector U16VECTOR FROM TO) (subu32vector U32VECTOR FROM TO) (subs8vector S8VECTOR FROM TO) (subs16vector S16VECTOR FROM TO) (subs32vector S32VECTOR FROM TO) (subf32vector F32VECTOR FROM TO) (subf64vector F64VECTOR FROM TO)Creates a number vector of the same type as the argument vector with the elements at the positions
FROMup to but not includingTO.SRFI-17 Setters for
XXXvector-refare defined.
String library, see the documentation for SRFI-13
On systems that support dynamic loading, the srfi-13 unit can
be made available in the interpreter (csi) by entering
(require-extension srfi-13)
Character set library, see the documentation for SRFI-14
On systems that support dynamic loading, the srfi-14 unit can
be made available in the interpreter (csi) by entering
(require-extension srfi-14)
The runtime-support code for the Pattern Matching extensions. Note that to use the macros in normal compiled code it is not required to declare this unit as used. Only if forms containing these macros are to be expanded at runtime, this is needed.
This library unit provides support for regular expressions. The flavor depends on the particular installation platform:
pregexp library is used.
(grep REGEX LIST)Returns all items of
LISTthat match the regular expressionREGEX. This procedure could be defined as follows:(define (grep regex lst) (filter (lambda (x) (string-search regex x)) lst) )
(glob->regexp PATTERN)Converts the file-pattern
PATTERNinto a regular expression.(glob->regexp "foo.*") ==> "foo\..*"
(regexp STRING [IGNORECASE [IGNORESPACE [UTF8]]])Returns a precompiled regular expression object for
string. The optional argumentsIGNORECASE,IGNORESPACEandUTF8specify whether the regular expression should be matched with case- or whitespace-differences ignored, or whether the string should be treated as containing UTF-8 encoded characters, respectively.Notes:
- regex doesn't allow (?: ) cloisters (non-capturing groups) Currently this means if you use utf8 matching, individual "." matching will return extra submatches.
- pregexp doesn't allow a # comment w/o a trailing newline.
(regexp? X)Returns
#tifXis a precompiled regular expression, or#fotherwise.
(string-match REGEXP STRING [START]) (string-match-positions REGEXP STRING [START])Matches the regular expression in
REGEXP(a string or a precompiled regular expression) withSTRINGand returns either#fif the match failed, or a list of matching groups, where the first element is the complete match. If the optional argumentSTARTis supplied, it specifies the starting position inSTRING. For each matching group the result-list contains either:#ffor a non-matching but optional group; a list of start- and end-position of the match inSTRING(in the case ofstring-match-positions); or the matching substring (in the case ofstring-match). Note that the exact string is matched. For searching a pattern inside a string, see below. Note also thatstring-matchis implemented by callingstring-searchwith the regular expression wrapped in^ ... $.
(string-search REGEXP STRING [START [RANGE]]) (string-search-positions REGEXP STRING [START [RANGE]])Searches for the first match of the regular expression in
REGEXPwithSTRING. The search can be limited toRANGEcharacters.
(string-split-fields REGEXP STRING [MODE [START]])Splits
STRINGinto a list of fields according toMODE, whereMODEcan be the keyword#:infix(REGEXPmatches field separator), the keyword#:suffix(REGEXPmatches field terminator) or#t(REGEXPmatches field), which is the default.(define s "this is a string 1, 2, 3,") (string-split-fields "[^ ]+" s) => ("this" "is" "a" "string" "1," "2," "3,") (string-split-fields " " s #:infix) => ("this" "is" "a" "string" "1," "2," "3,") (string-split-fields "," s #:suffix)) => ("this is a string 1" " 2" " 3")
(string-substitute REGEXP SUBST STRING [INDEX])Searches substrings in
STRINGthat matchREGEXPand substitutes them with the stringSUBST. The substitution can contain references to subexpressions inREGEXPwith the\NUMnotation, whereNUMrefers to the NUMth parenthesized expression. The optional argumentINDEXdefaults to 1 and specifies the number of the match to be substituted. Any non-numeric index specifies that all matches are to be substituted.(string-substitute "([0-9]+) (eggs|chicks)" "\\2 (\\1)" "99 eggs or 99 chicks" 2) ==> "99 eggs or chicks (99)"
(string-substitute* STRING SMAP)Substitutes elements of
STRINGaccording toSMAP.SMAPshould be an association-list where each element of the list is a pair of the form(MATCH . REPLACEMENT). Every occurrence of the regular expressionMATCHinSTRINGwill be replaced by the stringREPLACEMENT(string-substitute* "<h1>Hello, world!</h1>" '(("<[/A-Za-z0-9]+>" . "")))) ==> "Hello, world!"Note that back-references like
\NUMare currently not supported.
(regexp-escape STRING)Escapes all special characters in
STRINGwith\, so that the string can be embedded into a regular expression.(regexp-escape "^[0-9]+:.*$") ==> "\\^\\[0-9\\]\\+:.\n.\\*\\$"
Platform-specific notes:
pregexp library, character classes enclosed in [ ... ]
may not begin with a hyphen (-). A workaround is either to precede the hyphen with a slash
or use the range ---.
A simple multithreading package. This threading package follows largely the specification of SRFI-18. For more information see the documentation for SRFI-18
Notes:
thread-start! accepts a thunk (a zero argument procedure) as argument, which is
equivalent to (thread-start! (make-thread THUNK)).
enable-warnings, then a warning
message is written to the port that is the value of (current-error-port).
tcp unit). An exception is the read-eval-print loop on
UNIX platforms: waiting for input will not block other threads, provided the current input
port reads input from a console.
dynamic-wind
is involved.
make-parameter)
dynamic-wind thunks.
The following procedures are provided, in addition to the procedures defined in SRFI-18:
(thread-deliver-signal! THREAD X)This will cause
THREADto signal the conditionXonce it is scheduled for execution. After signalling the condition, the thread continues with its normal execution.
(thread-quantum THREAD)Returns the quantum of
THREAD, which is an exact integer specifying the approximate time-slice of the thread.
(thread-quantum-set! THREAD QUANTUM)Sets the quantum of
THREADtoQUANTUM.
This unit provides services as used on many UNIX-like systems. Note that the following definitions are not all available on non-UNIX systems like Windows. See below for Windows specific notes.
This unit uses the regex, scheduler, extras and utils units.
All errors related to failing file-operations will signal a condition
of kind (exn i/o file).
(change-directory NAME)Changes the current working directory to
NAME.
(current-directory [DIR])Returns the name of the current working directory. If the optional argument
DIRis given, then(current-directory DIR)is equivalent to(change-directory DIR).
(delete-directory NAME)Deletes the directory with the pathname
NAME. The directory has to be empty.
(directory [PATHNAME [SHOW-DOTFILES?]])Returns a list with all files that are contained in the directory with the name
PATHNAME(which defaults to the value of(current-directory)). IfSHOW-DOTFILES?is given and not#f, then files beginning with “.” are not included in the directory listing.
(directory? NAME)Returns
#tif there exists a file with the nameNAMEand if that file is a directory, or#fotherwise.
(glob PATTERN1 ...)Returns a list of the pathnames of all existing files matching
PATTERN1 ..., which should be strings containing the usual file-patterns (with*matching zero or more characters and?matching zero or one character).
(set-root-directory! STRING)Sets the root directory for the current process to the path given in
STRING(using thechrootfunction). If the current process has no root permissions, the operation will fail.
(call-with-input-pipe CMDLINE PROC [MODE]) (call-with-output-pipe CMDLINE PROC [MODE])Call
PROCwith a single argument: a input- or output port for a pipe connected to the subprocess named inCMDLINE. IfPROCreturns normally, the pipe is closed and any result values are returned.
(close-input-pipe PORT) (close-output-pipe PORT)Closes the pipe given in
PORTand waits until the connected subprocess finishes. The exit-status code of the invoked process is returned.
(create-pipe)The fundamental pipe-creation operator. Calls the C function
pipe()and returns 2 values: the file-descriptors of the input- and output-ends of the pipe.
(open-input-pipe CMDLINE [MODE])Spawns a subprocess with the command-line string
CMDLINEand returns a port, from which the output of the process can be read. IfMODEis specified, it should be the keyword#:text(the default) or#:binary.
(open-output-pipe CMDLINE [MODE])Spawns a subprocess with the command-line string
CMDLINEand returns a port. Anything written to that port is treated as the input for the process. IfMODEis specified, it should be the keyword#:text(the default) or#:binary.
This variable contains the maximal number of bytes that can be written atomically into a pipe or FIFO.
(with-input-from-pipe CMDLINE THUNK [MODE]) (with-output-to-pipe CMDLINE THUNK [MODE])Temporarily set the value of
current-input-port/current-output-portto a port for a pipe connected to the subprocess named inCMDLINEand call the procedureTHUNKwith no arguments. AfterTHUNKreturns normally the pipe is closed and the standard input-/output port is restored to its previous value and any result values are returned.(with-output-to-pipe "gs -dNOPAUSE -sDEVICE=jpeg -dBATCH -sOutputFile=signballs.jpg -g600x600 -q -" (lambda () (print #<<EOF %!IOPSC-1993 %%Creator: HAYAKAWA Takashi<xxxxxxxx@xx.xxxxxx.xx.xx> /C/neg/d/mul/R/rlineto/E/exp/H{{cvx def}repeat}def/T/dup/g/gt/r/roll/J/ifelse 8 H/A/copy(z&v4QX&93r9AxYQOZomQalxS2w!!O&vMYa43d6r93rMYvx2dca!D&cjSnjSnjjS3o!v&6A X&55SAxM1CD7AjYxTTd62rmxCnTdSST0g&12wECST!&!J0g&D1!&xM0!J0g!l&544dC2Ac96ra!m&3A F&&vGoGSnCT0g&wDmlvGoS8wpn6wpS2wTCpS1Sd7ov7Uk7o4Qkdw!&Mvlx1S7oZES3w!J!J!Q&7185d Z&lx1CS9d9nE4!k&X&MY7!&1!J!x&jdnjdS3odS!N&mmx1C2wEc!G&150Nx4!n&2o!j&43r!U&0777d ]&2AY2A776ddT4oS3oSnMVC00VV0RRR45E42063rNz&v7UX&UOzF!F!J![&44ETCnVn!a&1CDN!Y&0M V1c&j2AYdjmMdjjd!o&1r!M){( )T 0 4 3 r put T(/)g{T(9)g{cvn}{cvi}J}{($)g[]J}J cvx}forall/moveto/p/floor/w/div/S/add 29 H[{[{]setgray fill}for Y}for showpage EOF ) ) )
(create-fifo FILENAME [MODE])Creates a FIFO with the name
FILENAMEand the permission bitsMODE, which defaults to(+ perm/irwxu perm/irwxg perm/irwxo)
(duplicate-fileno OLD [NEW])If
NEWis given, then the file-descriptorNEWis opened to access the file with the file-descriptorOLD. Otherwise a fresh file-descriptor accessing the same file asOLDis returned.
(file-close FILENO)Closes the input/output file with the file-descriptor
FILENO.
(file-open FILENAME FLAGS [MODE])Opens the file specified with the string
FILENAMEand open-flagsFLAGSusing the C functionopen(). On success a file-descriptor for the opened file is returned.FLAGSshould be a bitmask containing one or more of theopen/...values ored together usingbitwise-ior(or simply added together). The optionalMODEshould be a bitmask composed of one or more permission values likeperm/irusrand is only relevant when a new file is created. The default mode isperm/irwxu | perm/irgrp | perm/iroth.
(file-mkstemp TEMPLATE-FILENAME)Create a file based on the given
TEMPLATE-FILENAME, in which the six last characters must be “XXXXXX”. These will be replaced with a string that makes the filename unique. The file descriptor of the created file and the generated filename is returned. See themkstemp(3)manual page for details on how this function works. The template string given is not modified.Example usage:
(let-values (((fd temp-path) (file-mkstemp "/tmp/mytemporary.XXXXXX"))) (let ((temp-port (open-output-file* fd))) (format temp-port "This file is ~A.~%" temp-path) (close-output-port temp-port)))
(file-read FILENO SIZE [BUFFER])Reads
SIZEbytes from the file with the file-descriptorFILENO. If a string or bytevector is passed in the optional argumentBUFFER, then this string will be destructively modified to contain the read data. This procedure returns a list with two values: the buffer containing the data and the number of bytes read.
(file-select READFDLIST WRITEFDLIST [TIMEOUT])Waits until any of the file-descriptors given in the lists
READFDLISTandWRITEFDLISTis ready for input or output, respectively. If the optional argumentTIMEOUTis given and not false, then it should specify the number of seconds after which the wait is to be aborted. This procedure returns two values: the lists of file-descriptors ready for input and output, respectively.READFDLISTand WRITEFDLIST may also by file-descriptors instead of lists. In this case the returned values are booleans indicating whether input/output is ready by#tor#fotherwise. You can also pass#fasREADFDLISTorWRITEFDLISTargument, which is equivalent to().
(file-write FILENO BUFFER [SIZE])Writes the contents of the string or bytevector
BUFFERinto the file with the file-descriptorFILENO. If the optional argumentSIZEis given, then only the specified number of bytes are written.
These variables contain file-descriptors for the standard I/O files.
Flags for use with
file-open.
(open-input-file* FILENO [OPENMODE]) (open-output-file* FILENO [OPENMODE])Opens file for the file-descriptor
FILENOfor input or output and returns a port.FILENOshould be a positive exact integer.OPENMODEspecifies an additional mode for opening the file (currently only the keyword#:appendis supported, which opens an output-file for appending).
(port->fileno PORT)If
PORTis a file- or tcp-port, then a file-descriptor is returned for this port. Otherwise an error is signaled.
(file-access-time FILE) (file-change-time FILE) (file-modification-time FILE)Returns time (in seconds) of the last acces, modification or change of
FILE.FILEmay be a filename or a file-descriptor. If the file does not exist, an error is signaled.
(file-stat FILE [LINK])Returns a 9-element vector with the following contents: inode-number, mode (as with
file-permissions), number of hard links, uid of owner (as withfile-owner), gid of owner, size (as withfile-size) and access-, change- and modification-time (as withfile-access-time,file-change-timeandfile-modification-time). If the optional argumentLINKis given and not#f, then the file-statistics vector will be resolved for symbolic links (otherwise symbolic links are resolved).
(file-position FILE)Returns the current file position of
FILE, which should be a port or a file-descriptor.
(file-size FILENAME)Returns the size of the file designated by
FILE.FILEmay be a filename or a file-descriptor. If the file does not exist, an error is signaled.
(regular-file? FILENAME)Returns true, if
FILENAMEnames a regular file (not a directory or symbolic link).
(file-truncate FILE OFFSET)Truncates the file
FILEto the lengthOFFSET, which should be an integer. If the file-size is smaller or equal toOFFSETthen nothing is done.FILEshould be a filename or a file-descriptor.
(set-file-position! FILE POSITION [WHENCE])Sets the current read/write position of
FILEtoPOSITION, which should be an exact integer.FILEshould be a port or a file-descriptor.WHENCEspecifies how the position is to interpreted and should be one of the valuesseek/set, seek/curandseek/end. It defaults toseek/set.Exceptions:
(exn bounds),(exn i/o file)
(parent-process-id)Returns the process ID of the parent of the current process.
(process-execute PATHNAME [ARGUMENT-LIST [ENVIRONMENT-LIST]])Creates a new child process and replaces the running process with it using the C library function
execvp(3). If the optional argumentARGUMENT-LISTis given, then it should contain a list of strings which are passed as arguments to the subprocess. If the optional argumentENVIRONMENT-LISTis spplied, then the library functionexecve(2)is used, and the environment passed inENVIRONMENT-LIST(which should be of the form("<NAME>=<VALUE>" ...)is given to the invoked process. Note thatexecvp(3)respects the current setting of thePATHenvironment variable whileexecve(3)does not.On native Windows,
process-executeignores theENVIRONMENT-LISTarguments.
(process-fork [THUNK])Creates a new child process with the UNIX system call
fork(). Returns either the PID of the child process or 0. IfTHUNKis given, then the child process calls it as a procedure with no arguments and terminates.
(process-run PATHNAME [LIST])Creates a new child process using the UNIX system call
fork()that executes the program given by the stringPATHNAMEusing the UNIX system callexecv(). The PID of the new process is returned. IfLISTis not specified, thenPATHNAMEis passed to a program named by the environment variableSHELL(or/bin/sh, if the variable is not defined), so usual argument expansion can take place.
(process-signal PID [SIGNAL])Sends
SIGNALto the process with the idPIDusing the UNIX system callkill().SIGNALdefaults to the value of the variablesignal/term.
(process-wait [PID [NOHANG]])Suspends the current process until the child process with the id
PIDhas terminated using the UNIX system callwaitpid(). IfPIDis not given, then this procedure waits for any child process. IfNOHANGis given and not#fthen the current process is not suspended. This procedure returns three values:
PID or 0, if NOHANG is true and the child process
has not terminated yet;
#t if the process exited normally or #f
otherwise;
(process COMMANDLINE [ARGUMENTLIST [ENVIRONMENT]])Passes the string
COMMANDLINEto the host-system's shell that is invoked as a subprocess and returns three values: an input port from which data written by the sub-process can be read, an output port from which any data written to will be received as input in the sub-process and the process-id of the started sub-process. Blocking reads and writes to or from the ports returned byprocessonly block the current thread, not other threads executing concurrently.If
ARGUMENTLISTis given, then the invocation of the subprocess is not done via the shell, but directly. The arguments are directly passed toprocess-execute(as isENVIRONMENT). Not using the shell may be preferrable for security reasons.On native Windows the
ARGUMENTLISTandENVIRONMENTarguments are ignored.
(sleep SECONDS)Puts the process to sleep for
SECONDS. Returns either 0 if the time has completely elapsed, or the number of remaining seconds, if a signal occurred.
(symbolic-link? FILENAME)Returns true, if
FILENAMEnames a symbolic link.
(create-symbolic-link OLDNAME NEWNAME)Creates a symbolic link with the filename
NEWNAMEthat points to the file namedOLDNAME.
(read-symbolic-link FILENAME)Returns the filename to which the symbolic link
FILENAMEpoints.
(file-link OLDNAME NEWNAME)Creates a hard link from
OLDNAMEtoNEWNAME(both strings).
(file-owner FILE)Returns the user-id of
FILE.FILEmay be a filename or a file-descriptor.
(file-permissions FILE)Returns the permission bits for
FILE. You can test this value by performing bitwise operations on the result and theperm/...values.FILEmay be a filename or a file-descriptor.
(file-read-access? FILENAME) (file-write-access? FILENAME) (file-execute-access? FILENAME)These procedures return
#tif the current user has read, write or execute permissions on the file namedFILENAME.
(change-file-mode FILENAME MODE)Changes the current file mode of the file named
FILENAMEtoMODEusing thechmod()system call. Theperm/...variables contain the various permission bits and can be combinded with thebitwise-iorprocedure.
(change-file-owner FILENAME UID GID)Changes the owner information of the file named
FILENAMEto the user- and group-idsUIDandGID(which should be exact integers) using thechown()system call.
(current-user-id) (current-group-id) (current-effective-user-id) (current-effective-group-id)Return the user- and group-ids of the current process.
(group-information GROUP)If
GROUPspecifies a valid group-name or group-id, then this procedure returns a list of four values: the group-name, the encrypted group password, the group ID and a list of the names of all group members. If no group with the given name or ID exists, then#fis returned.
(get-groups)Returns a list with the supplementary group IDs of the current user.
(set-groups! GIDLIST)Sets the supplementrary group IDs of the current user to the IDs given in the list
GIDLIST.Only the superuser may invoke this procedure.
(initialize-groups USERNAME BASEGID)Sets the supplementrary group IDs of the current user to the IDs from the user with name
USERNAME(a string), includingBASEGID.Only the superuser may invoke this procedure.
These variables contain permission bits as used in
change-file-mode.
(set-user-id! UID)Sets the effective user id of the current process to
UID, which should be a positive integer.
(set-group-id! GID)Sets the effective group id of the current process to
GID, which should be a positive integer.
(set-user-id! PID PGID)Sets the process group ID of the process specifed by
PIDtoPGID.
(user-information USER)If
USERspecifes a valid username (as a string) or user ID, then the user database is consulted and a list of 7 values are returned: the user-name, the encrypted password, the user ID, the group ID, a user-specific string, the home directory and the default shell. If no user with this name or ID can be found, then#fis returned.
(create-session)Creates a new session if the calling process is not a process group leader and returns the session ID.
(file-lock PORT [START [LEN]])Locks the file associated with
PORTfor reading or writing (according to whetherPORTis an input- or output-port).STARTspecifies the starting position in the file to be locked and defaults to 0.LENspecifies the length of the portion to be locked and defaults to#t, which means the complete file.file-lockreturns a “lock”-object.
(file-lock/blocking PORT [START [LEN]])Similar to
file-lock, but if a lock is held on the file, the current process blocks (including all threads) until the lock is released.
(file-test-lock PORT [START [LEN]])Tests whether the file associated with
PORTis locked for reading or writing (according to whetherPORTis an input- or output-port) and returns either#for the process-id of the locking process.
(file-unlock LOCK)Unlocks the previously locked portion of a file given in
LOCK.
(set-alarm! SECONDS)Sets an internal timer to raise the
signal/alrmafterSECONDSare elapsed. You can use theset-signal-handler!procedure to write a handler for this signal.
(set-signal-handler! SIGNUM PROC)Establishes the procedure of one argument
PROCas the handler for the signal with the codeSIGNAL.PROCis called with the signal number as its sole argument. If the argumentPROCis#fthen this signal will be ignored. Note that is is unspecified in which thread of execution the signal handler will be invoked.
(set-signal-mask! SIGLIST)Sets the signal mask of the current process to block all signals given in the list
SIGLIST. Signals masked in that way will not be delivered to the current process.
These variables contain signal codes for use with
process-signalorset-signal-handler!.
(current-environment)Returns a association list of the environment variables and their current values.
(setenv VARIABLE VALUE)Sets the environment variable named
VARIABLEtoVALUE. Both arguments should be strings. If the variable is not defined in the environment, a new definition is created.
(unsetenv VARIABLE)Removes the definition of the environment variable
VARIABLEfrom the environment of the current process. If the variable is not defined, nothing happens.
(memory-mapped-file? X)Returns
#t, ifXis an object representing a memory mapped file, or#fotherwise.
(map-file-to-memory ADDRESS LEN PROTECTION FLAG FILENO [OFFSET])Maps a section of a file to memory using the C function
mmap().ADDRESSshould be a foreign pointer object or#f;LENspecifies the size of the section to be mapped;PROTECTIONshould be one or more of the flagsprot/read, prot/write, prot/execorprot/nonebitwise-iored together;FLAGshould be one or more of the flagsmap/fixed, map/shared, map/private, map/anonymousormap/file;FILENOshould be the file-descriptor of the mapped file. The optional argumentOFFSETgives the offset of the section of the file to be mapped and defaults to 0. This procedure returns an object representing the mapped file section. The proceduremove-memory!can be used to access the mapped memory.
(memory-mapped-file-pointer MMAP)Returns a machine pointer to the start of the memory region to which the file is mapped.
(unmap-file-from-memory MMAP [LEN])Unmaps the section of a file mapped to memory using the C function
munmap().MMAPshould be a mapped file as returned by the proceduremap-file-to-memory. The optional argumentLENspecifies the length of the section to be unmapped and defaults to the complete length given when the file was mapped.
(seconds->local-time SECONDS)Breaks down the time value represented in
SECONDSinto a 10 element vector of the form#(seconds minutes hours mday month year wday yday dstflag timezone), in the following format:
- seconds: the number of seconds after the minute (0 - 59)
- minutes: the number of minutes after the hour (0 - 59)
- hours: the number of hours past midnight (0 - 23)
- mday: the day of the month (1 - 31)
- month: the number of months since january (0 - 11)
- year: the number of years since 1900
- wday: the number of days since Sunday (0 - 6)
- yday: the number of days since January 1 (0 - 365)
- dstflag: a flag that is true if Daylight Saving Time is in effect at the time described.
- timezone: the difference between UTC and the latest local standard time, in seconds west of UTC.
(local-time->seconds VECTOR)Converts the ten-element vector
VECTORrepresenting the time value relative to the current timezone into the number of seconds since the first of January, 1970 UTC.
(local-timezone-abbrevtiation)Returns the abbreviation for the local timezone as a string.
(seconds->string SECONDS)Converts the local time represented in
SECONDSinto a string of the form"Tue May 21 13:46:22 1991\n".
(seconds->utc-time SECONDS)Similar to
seconds->local-time, but interpretesSECONDSas UTC time.
(utc-time->seconds VECTOR)Converts the ten-element vector
VECTORrepresenting the UTC time value into the number of seconds since the first of January, 1970 UTC.
(time->string VECTOR)Converts the broken down time represented in the 10 element vector
VECTORinto a string of the form"Tue May 21 13:46:22 1991\n".
(_exit [CODE])Exits the current process without flushing any buffered output (using the C function
_exit). Note that theexit-handleris not called when this procedure is invoked. The optional return-codeCODEdefaults to0.
These variables contain error codes as returned by
errno.
(find-files DIRECTORY PREDICATE [ACTION [IDENTITY [LIMIT]]])Recursively traverses the contents of
DIRECTORY(which should be a string) and invokes the procedureACTIONfor all files for which the procedurePREDICATEis true.PREDICATEmay me a procedure of one argument or a regular-expression string.ACTIONshould be a procedure of two arguments: the currently encountered file and the result of the previous invocation ofACTION, or, if this is the first invocation, the value ofIDENTITY.ACTIONdefaults tocons,IDENTITYdefaults to().LIMITshould a procedure of one argument that is called for each nested directory and which should return true, if that directory is to be traversed recursively.LIMITmay also be an exact integer that gives the maximum recursion depth. A depth of0means the files in the specified directory are traversed but not any nested directories.LIMITmay also be#f(the default), which is equivalent to(constantly #t).Note that
ACTIONis called with the full pathname of each file, including the directory prefix.
(get-host-name)Returns the hostname of the machine that this process is running on.
(system-information)Invokes the UNIX system call
uname()and returns a list of 5 values: system-name, node-name, OS release, OS version and machine.
(set-buffering-mode! PORT MODE [BUFSIZE])Sets the buffering-mode for the file associated with
PORTtoMODE, which should be one of the keywords#:full, #:lineor#:none. IfBUFSIZEis specified it determines the size of the buffer to be used (if any).
(terminal-name PORT)Returns the name of the terminal that is connected to
PORT.
(terminal-port? PORT)Returns
#tifPORTis connected to a terminal and#fotherwise.
change-directorychange-file-modechange-file-ownercreate-directorycreate-fifocreate-pipecreate-sessioncreate-symbolic-linkcurrent-directorycurrent-effective-groupd-idcurrent-effective-user-idcurrent-group-idcurrent-parent-idcurrent-process-idcurrent-user-iddelete-directoryduplicate-fileno_exitfile-closefile-access-timefile-change-timefile-modification-timefile-execute-access?file-openfile-lockfile-positionfile-readfile-read-access?file-selectfile-statfile-test-lockfile-truncatefile-unlockfile-writefile-write-access?get-groupsget-host-nameinitialize-groupslocal-time->secondslocal-timezone-abbreviationmap-file-to-memoryopen-input-file*open-output-file*open-input-pipeopen-output-pipeport->filenoprocess-executeprocess-forkprocess-group-idprocess-signalprocess-waitclose-input-pipeclose-output-piperead-symbolic-linkseconds->local-timeseconds->stringseconds->utc-timeset-alarm!set-buffering-mode!set-file-position!set-groups!set-signal-mask!set-group-id!set-process-group-id!set-user-id!set-root-directory!setenvsleepsystem-informationterminal-nameterminal-port?time->stringunsetenvunmap-file-from-memoryuser-informationutc-time->secondsThe following definitions are not supported for native Windows builds (compiled with the Microsoft tools or with MingW):
open/noctty open/nonblock open/fsync open/sync perm/isvtx perm/isuid perm/isgid file-select signal/... set-signal-handler! set-signal-mask! user-information group-information get-groups set-groups! initialize-groups errno/wouldblock change-file-owner current-user-id current-group-id current-effective-user-id current-effective-groupd-id set-user-id! set-group-id! create-session process-group-id set-process-group-id! create-symbolic-link read-symbolic-link file-truncate file-lock file-lock/blocking file-unlock file-test-lock create-fifo fifo? prot/... map/... map-file-to-memory unmap-file-from-memory memory-mapped-file-pointer memory-mapped-file? set-alarm! terminal-port? terminal-name process-fork process-signal parent-process-id set-root-directory! utc-time->seconds local-timezone-abbreviation
Additionally, the following definitions are only available for Windows:
These variables contains special flags that specify the exact semantics of
process-spawn:spawn/overlayreplaces the current process with the new one.spawn/waitsuspends execution of the current process until the spawned process returns.spawn/nowaitdoes the opposite (spawn/nowaitois identical, according to the Microsoft documentation) and runs the process asynchronously.spawn/detachruns the new process in the background, without being attached to a console.
(process-spawn MODE FILENAME ARGUMENT ...)Creates and runs a new process with the given filename and command-line arguments.
MODEspecifies how exactly the process should be executed and must be one or more of thespawn/...flags defined above.
This unit contains some utility procedures for Shell scripting and for some file operations.
This unit uses the extras and regex units.
(absolute-pathname? PATHNAME)Returns
#tif the stringPATHNAMEnames an absolute pathname, and returns#fotherwise.
(decompose-pathname PATHNAME)Returns three values: the directory-, filename- and extension-components of the file named by the string
PATHNAME. For any component that is not contained inPATHNAME,#fis returned.
(make-pathname DIRECTORY FILENAME [EXTENSION]) (make-absolute-pathname DIRECTORY FILENAME [EXTENSION])Returns a string that names the file with the components
DIRECTORY, FILENAMEand (optionally)EXTENSION.DIRECTORYcan be#f(meaning no directory component), a string or a list of strings.FILENAMEandEXTENSIONshould be strings or#f.make-absolute-pathnamereturns always an absolute pathname.
(pathname-extension PATHNAME)Accessors for the components of
PATHNAME. If the pathname does not contain the accessed component, then#fis returned.
(pathname-replace-extension PATHNAME EXTENSION)Return a new pathname with the specified component of
PATHNAMEreplaced by a new value.
(pathname-strip-extension PATHNAME)Return a new pathname with the specified component of
PATHNAMEstripped.
(create-temporary-file [EXTENSION])Creates an empty temporary file and returns its pathname. If
EXTENSIONis not given, then.tmpis used. If the environment variableTMPDIR, TEMPorTMPis set, then the pathname names a file in that directory.
(delete-file* FILENAME)If the file
FILENAMEexists, it is deleted and#tis returned. If the file does not exist, nothing happens and#fis returned.
(for-each-line PROCEDURE [PORT])Calls
PROCEDUREfor each line read fromPORT(which defaults to the value of(current-input-port). The argument passed toPORCEDUREis a string with the contents of the line, excluding any line-terminators. When all input has been read from the port,for-each-linereturns some unspecified value.
(for-each-argv-line PROCEDURE)Opens each file listed on the command line in order, passing one line at a time into
PROCEDURE. The filename-is interpreted as(current-input-port). If no arguments are given on the command line it again uses the value of(current-input-port). During execution ofPROCEDURE, the current input port will be correctly bound to the current input source.This code will act as a simple Unix cat(1) command:
(for-each-argv-line print)
(port-for-each FN THUNK) (port-map FN THUNK)Apply
FNto successive results of calling the zero argument procedureTHUNKuntil it returns#!eof.port-for-eachdiscards the results, whileport-mapreturns a list of the collected results.
(system* FORMATSTRING ARGUMENT1 ...)Similar to
(system (sprintf FORMATSTRING ARGUMENT1 ...)), but signals an error if the invoked program should return a nonzero exit status.
(read-all [FILE-OR-PORT])If
FILE-OR-PORTis a string, then this procedure returns the contents of the file as a string. IfFILE-OR-PORTis a port, all remaining input is read and returned as a string. The port is not closed. If no argument is provided, input will be read from the port that is the current value of(current-input-port).
(shift! LIST [DEFAULT])Returns the car of
LIST(orDEFAULTifLISTis empty) and replaces the car ofLISTwith it's cadr and the cdr with the cddr. IfDEFAULTis not given, and the list is empty,#fis returned. An example might be clearer, here:(define lst '(1 2 3)) (shift! lst) ==> 1, lst is now (2 3)The list must at least contain 2 elements.
(unshift! X PAIR)Sets the car of
PAIRtoXand the cdr to its cddr. ReturnsPAIR:(define lst '(2)) (unshift! 99 lst) ; lst is now (99 2)
This unit provides basic facilities for communicating over TCP sockets. The socket interface should be mostly compatible to the one found in PLT Scheme.
This unit uses the extras unit.
All errors related to failing network operations will raise a condition
of kind (exn i/o network).
(tcp-listen TCPPORT [BACKLOG [HOST]])Creates and returns a TCP listener object that listens for connections on
TCPPORT, which should be an exact integer.BACKLOGspecifies the number of maximally pending connections (and defaults to 4). If the optional argumentHOSTis given and not#f, then only incoming connections for the given host (or IP) are accepted.
(tcp-listener? X)Returns
#tifXis a TCP listener object, or#fotherwise.
(tcp-accept LISTENER)Waits until a connection is established on the port on which
LISTENERis listening and returns two values: an input- and output-port that can be used to communicate with the remote process.Note: this operation and any I/O on the ports returned will not block other running threads.
(tcp-accept-ready? LISTENER)Returns
#tif there are any connections pending onLISTENER, or#fotherwise.
(tcp-listener-port LISTENER)Returns the port number assigned to
LISTENER(If you pass0totcp-listen, then the system will choose a port-number for you).
(tcp-listener-port LISTENER)Returns the file-descriptor associated with
LISTENER.
(tcp-connect HOSTNAME [TCPPORT])Establishes a client-side TCP connection to the machine with the name
HOSTNAME(a string) atTCPPORT(an exact integer) and returns two values: an input- and output-port for communicating with the remote process.Note: any I/O on the ports returned will not block other running threads.
(tcp-addresses PORT)Returns two values for the input- or output-port
PORT(which should be a port returned by eithertcp-acceptortcp-connect): the IP address of the local and the remote machine that are connected over the socket associated withPORT. The returned addresses are strings inXXX.XXX.XXX.XXXnotation.
(tcp-port-numbers PORT)Returns two values for the input- or output-port
PORT(which should be a port returned by eithertcp-acceptortcp-connect): the TCP port numbers of the local and the remote machine that are connected over the socket associated withPORT.
(tcp-abandon-port PORT)Marks the socket port
PORTas abandoned. This is mainly useful to close down a port without breaking the connection.
A very simple example follows. Say we have the two files client.scm
and server.scm:
; client.scm (define-values (i o) (tcp-connect "localhost" 4242)) (write-line "Good Bye!" o) (print (read-line i))
; server.scm (define l (tcp-listen 4242)) (define-values (i o) (tcp-accept l)) (write-line "Hello!" o) (print (read-line i)) (close-input-port i) (close-output-port o) % csi -script server.scm & [1] 1409 % csi -script client.scm Good Bye! Hello!
This unit provides a number of handy low-level operations. Use at your own risk.
This unit uses the srfi-4 and extras units.
(address->pointer ADDRESS)Creates a new foreign pointer object initialized to point to the address given in the integer
ADDRESS.
(allocate BYTES)Returns a pointer to a freshly allocated region of static memory. This procedure could be defined as follows:
(define allocate (foreign-lambda c-pointer "malloc" integer))
(free POINTER)Frees the memory pointed to by
POINTER. This procedure could be defined as follows:(define free (foreign-lambda c-pointer "free" integer))
(null-pointer? PTR)Returns
#tifPTRcontains aNULLpointer, or#fotherwise.
(object->pointer X)Returns a pointer pointing to the Scheme object X, which should be a non-immediate object. Note that data in the garbage collected heap moves during garbage collection.
(pointer->address PTR)Returns the address, to which the pointer
PTRpoints.
(pointer->object PTR)Returns the Scheme object pointed to by the pointer
PTR.
(pointer-offset PTR N)Returns a new pointer representing the pointer
PTRincreased byN.
(pointer-u8-ref PTR)Returns the unsigned byte at the address designated by
PTR.
(pointer-s8-ref PTR)Returns the signed byte at the address designated by
PTR.
(pointer-u16-ref PTR)Returns the unsigned 16-bit integer at the address designated by
PTR.
(pointer-s16-ref PTR)Returns the signed 16-bit integer at the address designated by
PTR.
(pointer-u32-ref PTR)Returns the unsigned 32-bit integer at the address designated by
PTR.
(pointer-s32-ref PTR)Returns the signed 32-bit integer at the address designated by
PTR.
(pointer-f32-ref PTR)Returns the 32-bit float at the address designated by
PTR.
(pointer-f64-ref PTR)Returns the 64-bit double at the address designated by
PTR.
(pointer-u8-set! PTR N) (set! (pointer-u8-ref PTR) N)Stores the unsigned byte
Nat the address designated byPTR.
(pointer-s8-set! PTR N) (set! (pointer-s8-ref PTR) N)Stores the signed byte
Nat the address designated byPTR.
(pointer-u16-set! PTR N) (set! (pointer-u16-ref PTR) N)Stores the unsigned 16-bit integer
Nat the address designated byPTR.
(pointer-s16-set! PTR N) (set! (pointer-s16-ref PTR) N)Stores the signed 16-bit integer
Nat the address designated byPTR.
(pointer-u32-set! PTR N) (set! (pointer-u32-ref PTR) N)Stores the unsigned 32-bit integer
Nat the address designated byPTR.
(pointer-s32-set! PTR N) (set! (pointer-s32-ref PTR) N)Stores the 32-bit integer
Nat the address designated byPTR.
(pointer-f32-set! PTR N) (set! (pointer-f32-ref PTR) N)Stores the 32-bit floating-point number
Nat the address designated byPTR.
(pointer-f64-set! PTR N) (set! (pointer-f64-ref PTR) N)Stores the 64-bit floating-point number
Nat the address designated byPTR.
(align-to-word PTR-OR-INT)Accepts either a machine pointer or an integer as argument and returns a new pointer or integer aligned to the native word size of the host platform.
“Tagged” pointers are foreign pointer objects with an extra tag object.
(tag-pointer PTR TAG)Creates a new tagged pointer object from the foreign pointer
PTRwith the tagTAG, which may an arbitrary Scheme object.
(tagged-pointer? X TAG)Returns
#t, ifXis a tagged pointer object with the tagTAG(using aneq?comparison), or#fotherwise.
(pointer-tag PTR)If
PTRis a tagged pointer object, its tag is returned. IfPTRis a normal, untagged foreign pointer object#fis returned. Otherwise an error is signalled.
(extend-procedure PROCEDURE X)Returns a copy of the procedure
PROCEDUREwhich contains an additional data slot initialized toX. IfPROCEDUREis already an extended procedure, then its data slot is changed to containXand the same procedure is returned.
(extended-procedure? PROCEDURE)Returns
#tifPROCEDUREis an extended procedure, or#fotherwise.
(procedure-data PROCEDURE)Returns the data object contained in the extended procedure
PROCEDURE, or#fif it is not an extended procedure.
(set-procedure-data! PROCEDURE X)Changes the data object contained in the extended procedure
PROCEDUREtoX.(define foo (letrec ((f (lambda () (procedure-data x))) (x #f) ) (set! x (extend-procedure f 123)) x) ) (foo) ==> 123 (set-procedure-data! foo 'hello) (foo) ==> hello
(byte-vector FIXNUM ...)Returns a freshly allocated byte-vector with
FIXNUM ...as its initial contents.
(byte-vector? X)Returns
#tifXis a byte-vector object, or#fotherwise.
(byte-vector-fill! BYTE-VECTOR N)Sets each element of
BYTE-VECTORtoN, which should be an exact integer.
(byte-vector->list BYTE-VECTOR)Returns a list with elements taken from
BYTE-VECTOR.
(byte-vector->string BYTE-VECTOR)Returns a string with the contents of
BYTE-VECTOR.
(byte-vector-length BYTE-VECTOR)Returns the number of elements in
BYTE-VECTOR.
(byte-vector-ref BYTE-VECTOR INDEX)Returns the byte at the
INDEXth position ofBYTE-VECTOR.
(byte-vector-set! BYTE-VECTOR INDEX N) (set! (byte-vector-ref BYTE-VECTOR INDEX) N)Sets the byte at the
INDEXth position ofBYTE-VECTORto the value of the exact integern.
(list->byte-vector LIST)Returns a byte-vector with elements taken from
LIST, where the elements ofLISTshould be exact integers.
(make-byte-vector SIZE [INIT])Creates a new byte-vector of size
SIZE. IfINITis given, then it should be an exact integer with which every element of the byte-vector is initialized.
(make-static-byte-vector SIZE [INIT])As
make-byte-vector, but allocates the byte-vector in storage that is not subject to garbage collection. To free the allocated memory, one has to callobject-releaseexplicitly.Exceptions:
(exn bounds),(exn runtime)
(static-byte-vector->pointer PBYTE-VECTOR)Returns a pointer object pointing to the data in the statically allocated byte-vector
PBYTE-VECTOR.
(string->byte-vector STRING)Returns a byte-vector with the contents of
STRING.
(object-evict X [ALLOCATOR])Copies the object
Xrecursively into the memory pointed to by the foreign pointer object returned byALLOCATOR, which should be a procedure of a single argument (the number of bytes to allocate). The freshly copied object is returned. This facility allows moving arbitrary objects into static memory, but care should be taken when mutating evicted data: setting slots in evicted vector-like objects to non-evicted data is not allowed. It is possible to set characters/bytes in evicted strings or byte-vectors, though. It is advisable not to evict ports, because they might be mutated by certain file-operations.object-evictis able to handle circular and shared structures, but evicted symbols are no longer unique: a fresh copy of the symbol is created, so(define x 'foo) (define y (object-evict 'foo)) y ==> foo (eq? x y) ==> #f (define z (object-evict '(bar bar))) (eq? (car z) (cadr z)) ==> #tThe
ALLOCATORdefaults toallocate.
(object-evict-to-location X PTR [LIMIT])As
object-evictbut moves the object at the address pointed to by the machine pointerPTR. If the number of copied bytes exceeds the optionalLIMITthen an error is signalled (specifically a composite condition of typesexnandevict. The latter provides alimitproperty which holds the exceeded limit. Two values are returned: the evicted object and a new pointer pointing to the first free address after the evicted object.
(object-evicted? X)Returns
#tifXis a non-immediate evicted data object, or#fotherwise.
(object-size X)Returns the number of bytes that would be needed to evict the data object
X.
(object-release X [RELEASER])Frees memory occupied by the evicted object
Xrecursively.RELEASERshould be a procedure of a single argument (a foreign pointer object to the static memory to be freed) and defaults tofree.
(object-unevict X [FULL])Copies the object
Xand nested objects back into the normal Scheme heap. Symbols are re-interned into the symbol table. Strings and byte-vectors are not copied, unlessFULLis given and not#f.
A locative is an object that points to an element of a containing object,
much like a “pointer” in low-level, imperative programming languages like “C”. The element can
be accessed and changed indirectly, by performing access or change operations
on the locative. The container object can be computed by calling the
location->object procedure.
Locatives may be passed to foreign procedures that expect pointer arguments.
The effect of creating locatives for evicted data (see object-evict) is undefined.
(make-locative EXP [INDEX])Creates a locative that refers to the element of the non-immediate object
EXPat positionINDEX.EXPmay be a vector, symbol, pair, string, byte-vector, SRFI-4 number-vector, or record.INDEXshould be a fixnum.INDEXdefaults to 0.
(make-weak-locative EXP [INDEX])Creates a “weak” locative. Even though the locative refers to an element of a container object, the container object will still be reclaimed by garbage collection if no other references to it exist.
(locative-ref LOC)Returns the element to which the locative
LOCrefers. If the containing object has been reclaimed by garbage collection, an error is signalled.
(locative-set! LOC X) (set! (locative-ref LOC) X)Changes the element to which the locative
LOCrefers toX. If the containing object has been reclaimed by garbage collection, an error is signalled.
(locative->object LOC)Returns the object that contains the element referred to by
LOCor#fif the container has been reclaimed by garbage collection.
(global-bound? SYMBOL)Returns
#t, if the global (“toplevel”) variable with the nameSYMBOLis bound to a value, or#fotherwise.
(global-ref SYMBOL)Returns the value of the global variable
SYMBOL. If no variable under that name is bound, an error is signalled.Note that it is not possible to access a toplevel binding with
global-reforglobal-set!if it has been hidden in compiled code via(declare (hide ...)), or if the code has been compiled inblockmode.
(global-set! SYMBOL X) (set! (global-ref SYMBOL) X)Sets the global variable named
SYMBOLto the valueX.
(block-ref BLOCK INDEX)Returns the contents of the
INDEXth slot of the objectBLOCK.BLOCKmay be a vector, record structure, pair or symbol.
(block-set! BLOCK INDEX X) (set! (block-ref BLOCK INDEX) X)Sets the contents of the
INDEXth slot of the objectBLOCKto the value ofX.BLOCKmay be a vector, record structure, pair or symbol.
(object-copy X)Copies
Xrecursively and returns the fresh copy. Objects allocated in static memory are copied back into garbage collected storage.
(make-record-instance SYMBOL ARG1 ...)Returns a new instance of the record type
SYMBOL, with its slots initialized toARG1 .... To illustrate:(define-record point x y)expands into something quite similar to:
(begin (define (make-point x y) (make-record-instance 'point x y) ) (define (point? x) (and (record-instance? x) (eq? 'point (block-ref x 0)) ) ) (define (point-x p) (block-ref p 1)) (define (point-x-set! p x) (block-set! p 1 x)) (define (point-y p) (block-ref p 2)) (define (point-y-set! p y) (block-set! p 1 y)) )
(move-memory! FROM TO [BYTES])Copies
BYTESbytes of memory fromFROMtoTO.FROMandTOmay be strings, primitive byte-vectors, SRFI-4 byte-vectors (see: Unit srfi-4), memory mapped files, foreign pointers (as obtained from a call toforeign-lambda, for example) or locatives. ifBYTESis not given and the size of the source or destination operand is known then the maximal number of bytes will be copied. Moving memory to the storage returned by locatives will cause havoc, if the locative refers to containers of non-immediate data, like vectors or pairs.
(number-of-bytes BLOCK)Returns the number of bytes that the object
BLOCKcontains.BLOCKmay be any non-immediate value.
(number-of-slots BLOCK)Returns the number of slots that the object
BLOCKcontains.BLOCKmay be a vector, record structure, pair or symbol.
(record-instance? X)Returns
#tifXis an instance of a record type. See also:make-record-instance.
(record->vector BLOCK)Returns a new vector with the type and the elements of the record
BLOCK.
(invalid-procedure-call-handler PROC)Sets an internal hook that is invoked when a call to an object other than a procedure is executed at runtime. The procedure
PROCwill in that case be called with two arguments: the object being called and a list of the passed arguments.;;; Access sequence-elements as in ARC: (invalid-procedure-call-handler (lambda (proc args) (cond [(string? proc) (apply string-ref proc args)] [(vector? proc) (apply vector-ref proc args)] [else (error "call of non-procedure" proc)] ) ) ) ("hello" 4) ==> #\oThis facility does not work in code compiled with the “unsafe” setting.
(unbound-variable-value [X])Defines the value that is returned for unbound variables. Normally an error is signalled, use this procedure to override the check and return
Xinstead. To set the default behavior (of signalling an error), callunbound-variable-valuewith no arguments.This facility does not work in code compiled with the “unsafe” setting.
(object-become! ALIST)Changes the identity of the value of the car of each pair in
ALISTto the value of the cdr. Both values may not be immediate (i.e. exact integers, characters, booleans or the empty list).(define x "i used to be a string") (define y '#(and now i am a vector)) (object-become! (list (cons x y))) x ==> #(and now i am a vector) y ==> #(and now i am a vector) (eq? x y) ==> #tNote: this operation invokes a major garbage collection.
The effect of using
object-become!on evicted data (seeobject-evict) is undefined.
This unit is a port of Gregor Kiczales TinyCLOS with numerous modifications.
This unit uses the extras unit.
(define-class NAME (SUPERCLASS1 ...) (SLOTNAME1 ...) [METACLASS])Sets the variable
NAMEto a new class (a new instance of the class<class>).SUPERCLASS1 ...is a list of superclasses of the newly created class. If no superclasses are given, then<object>is assumed.SLOTNAME1 ...are the names of the direct slots of the class. ifMETACLASSis provided, then the new class-instance is an instance ofMETACLASSinstead of<class>.(define-class NAME (SUPER) (SLOT1 SLOT2) META)is equivalent to
(define NAME (make META 'name 'NAME 'direct-supers (list SUPER) 'direct-slots (list 'SLOT1 'SLOT2)) )Note that slots-names are not required to be symbols, so the following is perfectly valid:
(define hidden-slot (list 'hidden)) (define <myclass> (make <class> 'direct-supers (list <object>) 'direct-slots (list hidden-slot) ) ) (define x1 (make <myclass>) (slot-set! x1 hidden-slot 99)
(define-generic NAME [CLASS])Sets the variable
NAMEto contain a fresh generic function object without associated methods. If the optional argumentCLASSis given, then the generic function will be an instance of that class.
(define-method (NAME (VARIABLE1 CLASS1) ... PARAMETERS ...) BODY ...)Adds a new method with the code
BODY ...to the generic function that was assigned to the variablename.CLASS1 ...is a list if classes that specialize this particular method. The method can have additional parametersPARAMETERS, which do not specialize the method any further. Extended lambda-lists are allowed (#!optional, #!keyor#!restargument lists), but can not be specialized. Inside the body of the method the identifiercall-next-methodnames a procedure of zero arguments that can be invoked to call the next applicable method with the same arguments. If no generic function is defined under this name, then a fresh generic function object is created and assigned toNAME.Note that only
define-genericexpands into a valid definition, so for internal lexically scoped definitions usedefine-generic.Currently methods defined with
define-methodshould not be hidden (via(declare (hide ...)), nor should such files be compiled inblockmode, unless the methods are exported.
(add-method GENERIC METHOD)Adds the method object
METHODto the list of applicable methods for the generic functionGENERIC.
(make CLASS INITARG ...)Creates a new instance of
CLASSand passesINITARG ...to theinitializemethod of this class.
(make-class SUPERCLASSES SLOTNAMES)Creates a new class object, where
SUPERCLASSESshould be the list of direct superclass objects andSLOTNAMESshould be a list of symbols naming the slots of this class.
(make-generic [NAME])Creates a new generic function object. If
NAMEis specified, then it should be a string.
(make-method SPECIALIZERS PROC)Creates a new method object specialized to the list of classes in
SPECIALIZERS.(define-method (foo (x <bar>)) 123) <=> (add-method foo (make-method (list <bar>) (lambda (call-next-method x) 123)))
(slot-ref INSTANCE SLOTNAME)Returns the value of the slot
SLOTNAMEof the objectINSTANCE.
(slot-set! INSTANCE SLOTNAME VALUE) (set! (slot-ref INSTANCE SLOTNAME) VALUE)Sets the value of the slot
SLOTNAMEof the objectINSTANCEtoVALUE.
(class-cpl CLASS)Returns the class-precedence-list of
CLASSas a list of classes.
(class-direct-slots CLASS)Returns the list of direct slots of
CLASSas a list of lists, where each sublist contains the name of the slot.
(class-direct-supers CLASS)Returns the list of direct superclasses of
CLASS.
(class-slots CLASS)Returns the list of all slots of
CLASSand its superclasses as a list of lists, where each sublist contains the name of the slot.
(generic-methods GENERIC)Returns the list of all methods associated with the generic function
GENERIC.
(method-specializers METHOD)Returns the list of classes that specialize
METHOD.
(method-procedure METHOD)Returns the procedure that contains the body of
METHOD.
(subclass? CLASS1 CLASS2)Returns
#tisCLASS1is a subclass ofCLASS2, or#fotherwise. Note that the following holds:(subclass? X X) ==> #t
(instance-of? X CLASS)Returns
#tifXis an instance ofCLASS(or one of its subclasses).
These definitions allow interfacing to the Meta Object Protocol
of TinyCLOS. For serious use, it is recommended to consult
the source code (tinyclos.scm).
(allocate-instance CLASS)Allocates storage for an instance of
CLASSand returns the instance.
(compute-apply-generic GENERIC)Returns a procedure that will be called to apply the generic function methods to the arguments.
(compute-apply-methods GENERIC)Returns a procedure of two arguments, a list of applicable methods and a list of arguments and applies the methods.
(compute-methods GENERIC)Returns a procedure of one argument. The procedure is called with the list of actual arguments passed to the generic function and should return a list of applicable methods, sorted by precedence.
(compute-getter-and-setter CLASS SLOT ALLOCATOR)Returns two values, the procedures that get and set the contents of the slot
SLOT.ALLOCATORis a procedure of one argument that gets an initalizer function and returns the getter and setter procedures for the allocated slot.
(compute-method-more-specific? GENERIC)Returns a procedure of three arguments (two methods and a list of arguments) that returns
#tif the first method is more specific than the second one with respect to the list of arguments. Otherwise the returned predicate returns#f.
(initialize INSTANCE INITARGS)Initializes the object
INSTANCE.INITARGSis the list of initialization arguments that were passed to themakeprocedure.
(describe-object INSTANCE [PORT])Writes a description of
INSTANCEtoPORT. Execution of the interpreter command,dwill invoke this generic function. IfPORTis not given it defaults to the value of(current-output-port).
(print-object INSTANCE [PORT])Writes a textual representation of
INSTANCEtoPORT. Any output of an instance withdisplay, writeandPORTis not given it defaults to the value of(current-output-port).
(initialize-slots INSTANCE INITARGS)This procedure takes a sequence of alternating slot-names and initialization values in
INITARGSand initializes the corresponding slots inINSTANCE.(define-class <pos> () (x y)) (define-method (initialize (pos <pos>) initargs) (call-next-method) (initialize-slots pos initargs)) (define p1 (make <pos> 'x 1 'y 2)) (define p2 (make <pos> 'x 3 'y 5))
The class hierarchy of builtin classes looks like this:
<top>
<object>
<class>
<procedure-class>
<procedure>
<entity-class>
<generic>
<primitive-class>
<c++-object>
<primitive>
<void>
<boolean>
<symbol>
<char>
<vector>
<pair>
<number>
<integer>
<exact>
<inexact>
<string>
<port>
<input-port>
<output-port>
<pointer>
<tagged-pointer>
<swig-pointer>
<locative>
<byte-vector>
<u8vector>
<s8vector>
<u16vector>
<s16vector>
<u32vector>
<s32vector>
<f32vector>
<f64vector>
<structure>
<char-set>
<condition>
<condition-variable>
<environment>
<hash-table>
<lock>
<mmap>
<mutex>
<promise>
<queue>
<read-table>
<regexp>
<tcp-listener>
<thread>
<time>
<end-of-file>
The pa. If no generic function is defined under this name, then a fresh generic function object is created and assigned to
NAME.Note that only
define-genericexpands into a valid definition, so for internal lexically scoped definitions usedefine-generic.Currently methods defined with
define-methodshould not be hidden (via(declare (hide ...)), nor should such files be compiled inblockmode, unless the methods are exported.
(add-method GENERIC METHOD)Adds the method object
METHODto the list of applicable methods for the generic functionGENERIC.
(make CLASS INITARG ...)Creates a new instance of
CLASSand passesINITARG ...to theinitializemethod of this class.
(make-class SUPERCLASSES SLOTNAMES)Creates a new class object, where
SUPERCLASSESshould be the list of direct superclass objects andSLOTNAMESshould be a list of symbols naming the slots of this class.
(make-generic [NAME])Creates a new generic function object. If
NAMEis specified, then it should be a string.
(make-method SPECIALIZERS PROC)Creates a new method object specialized to the list of classes in
SPECIALIZERS.(define-method (foo (x <bar>)) 123) <=> (add-method foo (make-method (list <bar>) (lambda (call-next-method x) 123)))
(slot-ref INSTANCE SLOTNAME)Returns the value of the slot
SLOTNAMEof the objectINSTANCE.
(slot-set! INSTANCE SLOTNAME VALUE) (set! (slot-ref INSTANCE SLOTNAME) VALUE)Sets the value of the slot
SLOTNAMEof the objectINSTANCEtoVALUE.
(class-cpl CLASS)Returns the class-precedence-list of
CLASSas a list of classes.
(class-direct-slots CLASS)Returns the list of direct slots of
CLASSas a list of lists, where each sublist contains the name of the slot.
(class-direct-supers CLASS)Returns the list of direct superclasses of
CLASS.
(class-slots CLASS)Returns the list of all slots of
CLASSand its superclasses as a list of lists, where each sublist contains the name of the slot.
(generic-methods GENERIC)Returns the list of all methods associated with the generic function
GENERIC.
(method-specializers METHOD)Returns the list of classes that specialize
METHOD.
(method-procedure METHOD)Returns the procedure that contains the body of
METHOD.
(subclass? CLASS1 CLASS2)Returns
#tisCLASS1is a subclass ofCLASS2, or#fotherwise. Note that the following holds:(subclass? X X) ==> #t
(instance-of? X CLASS)Returns
#tifXis an instance ofCLASS(or one of its subclasses).
These definitions allow interfacing to the Meta Object Protocol
of TinyCLOS. For serious use, it is recommended to consult
the source code (tinyclos.scm).
(allocate-instance CLASS)Allocates storage for an instance of
CLASSand returns the instance.
(compute-apply-generic GENERIC)Returns a procedure that will be called to apply the generic function methods to the arguments.
(compute-apply-methods GENERIC)Returns a procedure of two arguments, a list of applicable methods and a list of arguments and applies the methods.
(compute-methods GENERIC)Returns a procedure of one argument. The procedure is called with the list of actual arguments passed to the generic function and should return a list of applicable methods, sorted by precedence.
(compute-getter-and-setter CLASS SLOT ALLOCATOR)Returns two values, the procedures that get and set the contents of the slot
SLOT.ALLOCATORis a procedure of one argument that gets an initalizer function and returns the getter and setter procedures for the allocated slot.
(compute-method-more-specific? GENERIC)Returns a procedure of three arguments (two methods and a list of arguments) that returns
#tif the first method is more specific than the second one with respect to the list of arguments. Otherwise the returned predicate returns#f.
(initialize INSTANCE INITARGS)Initializes the object
INSTANCE.INITARGSis the list of initialization arguments that were passed to themakeprocedure.
(describe-object INSTANCE [PORT])Writes a description of
INSTANCEtoPORT. Execution of the interpreter command,dwill invoke this generic function. IfPORTis not given it defaults to the value of(current-output-port).
(print-object INSTANCE [PORT])Writes a textual representation of
INSTANCEtoPORT. Any output of an instance withdisplay, writeandPORTis not given it defaults to the value of(current-output-port).
(initialize-slots INSTANCE INITARGS)This procedure takes a sequence of alternating slot-names and initialization values in
INITARGSand initializes the corresponding slots inINSTANCE.(define-class <pos> () (x y)) (define-method (initialize (pos <pos>) initargs) (call-next-method) (initialize-slots pos initargs)) (define p1 (make <pos> 'x 1 'y 2)) (define p2 (make <pos> 'x 3 'y 5))
The class hierarchy of builtin classes looks like this:
<top>
<object>
<class>
<procedure-class>
<procedure>
<entity-class>
<generic>
<primitive-class>
<c++-object>
<primitive>
<void>
<boolean>
<symbol>
<char>
<vector>
<pair>
<number>
<integer>
<exact>
<inexact>
<string>
<port>
<input-port>
<output-port>
<pointer>
<tagged-pointer>
<swig-pointer>
<locative>
<byte-vector>
<u8vector>
<s8vector>
<u16vector>
<s16vector>
<u32vector>
<s32vector>
<f32vector>
<f64vector>
<structure>
<char-set>
<condition>
<condition-variable>
<environment>
<hash-table>
<lock>
<mmap>
<mutex>
<promise>
<queue>
<read-table>
<regexp>
<tcp-listener>
<thread>
<time>
<end-of-file>
The pa. If no generic function is defined under this name, then a fresh generic function object is created and assigned to
NAME.Note that only
define-genericexpands into a valid definition, so for internal lexically scoped definitions usedefine-generic.Currently methods defined with
define-methodshould not be hidden (via(declare (hide ...)), nor should such files be compiled inblockmode, unless the methods are exported.
(add-method GENERIC METHOD)Adds the method object
METHODto the list of applicable methods for the generic functionGENERIC.
(make CLASS INITARG ...)Creates a new instance of
CLASSand passesINITARG ...to theinitializemethod of this class.
(make-class SUPERCLASSES SLOTNAMES)Creates a new class object, where
SUPERCLASSESshould be the list of direct superclass objects andSLOTNAMESshould be a list of symbols naming the slots of this class.
(make-generic [NAME])Creates a new generic function object. If
NAMEis specified, then it should be a string.
(make-method SPECIALIZERS PROC)Creates a new method object specialized to the list of classes in
SPECIALIZERS.(define-method (foo (x <bar>)) 123) <=> (add-method foo (make-method (list <bar>) (lambda (call-next-method x) 123)))
(slot-ref INSTANCE SLOTNAME)Returns the value of the slot
SLOTNAMEof the objectINSTANCE.
(slot-set! INSTANCE SLOTNAME VALUE) (set! (slot-ref INSTANCE SLOTNAME) VALUE)Sets the value of the slot
SLOTNAMEof the objectINSTANCEtoVALUE.
(class-cpl CLASS)Returns the class-precedence-list of
CLASSas a list of classes.
(class-direct-slots CLASS)Returns the list of direct slots of
CLASSas a list of lists, where each sublist contains the name of the slot.
(class-direct-supers CLASS)Returns the list of direct superclasses of
CLASS.
(class-slots CLASS)Returns the list of all slots of
CLASSand its superclasses as a list of lists, where each sublist contains the name of the slot.
(generic-methods GENERIC)Returns the list of all methods associated with the generic function
GENERIC.
(method-specializers METHOD)Returns the list of classes that specialize
METHOD.
(method-procedure METHOD)Returns the procedure that contains the body of
METHOD.
(subclass? CLASS1 CLASS2)Returns
#tisCLASS1is a subclass ofCLASS2, or#fotherwise. Note that the following holds:(subclass? X X) ==> #t
(instance-of? X CLASS)Returns
#tifXis an instance ofCLASS(or one of its subclasses).
These definitions allow interfacing to the Meta Object Protocol
of TinyCLOS. For serious use, it is recommended to consult
the source code (tinyclos.scm).
(allocate-instance CLASS)Allocates storage for an instance of
CLASSand returns the instance.
(compute-apply-generic GENERIC)Returns a procedure that will be called to apply the generic function methods to the arguments.
(compute-apply-methods GENERIC)Returns a procedure of two arguments, a list of applicable methods and a list of arguments and applies the methods.
(compute-methods GENERIC)Returns a procedure of one argument. The procedure is called with the list of actual arguments passed to the generic function and should return a list of applicable methods, sorted by precedence.
(compute-getter-and-setter CLASS SLOT ALLOCATOR)Returns two values, the procedures that get and set the contents of the slot
SLOT.ALLOCATORis a procedure of one argument that gets an initalizer function and returns the getter and setter procedures for the allocated slot.
(compute-method-more-specific? GENERIC)Returns a procedure of three arguments (two methods and a list of arguments) that returns
#tif the first method is more specific than the second one with respect to the list of arguments. Otherwise the returned predicate returns#f.
(initialize INSTANCE INITARGS)Initializes the object
INSTANCE.INITARGSis the list of initialization arguments that were passed to themakeprocedure.
(describe-object INSTANCE [PORT])Writes a description of
INSTANCEtoPORT. Execution of the interpreter command,dwill invoke this generic function. IfPORTis not given it defaults to the value of(current-output-port).
(print-object INSTANCE [PORT])Writes a textual representation of
INSTANCEtoPORT. Any output of an instance withdisplay, writeandPORTis not given it defaults to the value of(current-output-port).
(initialize-slots INSTANCE INITARGS)This procedure takes a sequence of alternating slot-names and initialization values in
INITARGSand initializes the corresponding slots inINSTANCE.(define-class <pos> () (x y)) (define-method (initialize (pos <pos>) initargs) (call-next-method) (initialize-slots pos initargs)) (define p1 (make <pos> 'x 1 'y 2)) (define p2 (make <pos> 'x 3 'y 5))
The class hierarchy of builtin classes looks like this:
<top>
<object>
<class>
<procedure-class>
<procedure>
<entity-class>
<generic>
<primitive-class>
<c++-object>
<primitive>
<void>
<boolean>
<symbol>
<char>
<vector>
<pair>
<number>
<integer>
<exact>
<inexact>
<string>
<port>
<input-port>
<output-port>
<pointer>
<tagged-pointer>
<swig-pointer>
<locative>
<byte-vector>
<u8vector>
<s8vector>
<u16vector>
<s16vector>
<u32vector>
<s32vector>
<f32vector>
<f64vector>
<structure>
<char-set>
<condition>
<condition-variable>
<environment>
<hash-table>
<lock>
<mmap>
<mutex>
<promise>
<queue>
<read-table>
<regexp>
<tcp-listener>
<thread>
<time>
<end-of-file>
The pa. If no generic function is defined under this name, then a fresh generic function object is created and assigned to
NAME.Note that only
define-genericexpands into a valid definition, so for internal lexically scoped definitions usedefine-generic.Currently methods defined with
define-methodshould not be hidden (via(declare (hide ...)), nor should such files be compiled inblockmode, unless the methods are exported.
(add-method GENERIC METHOD)Adds the method object
METHODto the list of applicable methods for the generic functionGENERIC.
(make CLASS INITARG ...)Creates a new instance of
CLASSand passesINITARG ...to theinitializemethod of this class.
(make-class SUPERCLASSES SLOTNAMES)Creates a new class object, where
SUPERCLASSESshould be the list of direct superclass objects andSLOTNAMESshould be a list of symbols naming the slots of this class.
(make-generic [NAME])Creates a new generic function object. If
NAMEis specified, then it should be a string.
(make-method SPECIALIZERS PROC)Creates a new method object specialized to the list of classes in
SPECIALIZERS.(define-method (foo (x <bar>)) 123) <=> (add-method foo (make-method (list <bar>) (lambda (call-next-method x) 123)))
(slot-ref INSTANCE SLOTNAME)Returns the value of the slot
SLOTNAMEof the objectINSTANCE.
(slot-set! INSTANCE SLOTNAME VALUE) (set! (slot-ref INSTANCE SLOTNAME) VALUE)Sets the value of the slot
SLOTNAMEof the objectINSTANCEtoVALUE.
(class-cpl CLASS)Returns the class-precedence-list of
CLASSas a list of classes.
(class-direct-slots CLASS)Returns the list of direct slots of
CLASSas a list of lists, where each sublist contains the name of the slot.
(class-direct-supers CLASS)Returns the list of direct superclasses of
CLASS.
(class-slots CLASS)Returns the list of all slots of
CLASSand its superclasses as a list of lists, where each sublist contains the name of the slot.
(generic-methods GENERIC)Returns the list of all methods associated with the generic function
GENERIC.
(method-specializers METHOD)Returns the list of classes that specialize
METHOD.
(method-procedure METHOD)Returns the procedure that contains the body of
METHOD.
(subclass? CLASS1 CLASS2)Returns
#tisCLASS1is a subclass ofCLASS2, or#fotherwise. Note that the following holds:(subclass? X X) ==> #t
(instance-of? X CLASS)Returns
#tifXis an instance ofCLASS(or one of its subclasses).
These definitions allow interfacing to the Meta Object Protocol
of TinyCLOS. For serious use, it is recommended to consult
the source code (tinyclos.scm).
(allocate-instance CLASS)Allocates storage for an instance of
CLASSand returns the instance.
(compute-apply-generic GENERIC)Returns a procedure that will be called to apply the generic function methods to the arguments.
(compute-apply-methods GENERIC)Returns a procedure of two arguments, a list of applicable methods and a list of arguments and applies the methods.
(compute-methods GENERIC)Returns a procedure of one argument. The procedure is called with the list of actual arguments passed to the generic function and should return a list of applicable methods, sorted by precedence.
(compute-getter-and-setter CLASS SLOT ALLOCATOR)Returns two values, the procedures that get and set the contents of the slot
SLOT.ALLOCATORis a procedure of one argument that gets an initalizer function and returns the getter and setter procedures for the allocated slot.
(compute-method-more-specific? GENERIC)Returns a procedure of three arguments (two methods and a list of arguments) that returns
#tif the first method is more specific than the second one with respect to the list of arguments. Otherwise the returned predicate returns#f.
(initialize INSTANCE INITARGS)Initializes the object
INSTANCE.INITARGSis the list of initialization arguments that were passed to themakeprocedure.
(describe-object INSTANCE [PORT])Writes a description of
INSTANCEtoPORT. Execution of the interpreter command,dwill invoke this generic function. IfPORTis not given it defaults to the value of(current-output-port).
(print-object INSTANCE [PORT])Writes a textual representation of
INSTANCEtoPORT. Any output of an instance withdisplay, writeandPORTis not given it defaults to the value of(current-output-port).
(initialize-slots INSTANCE INITARGS)This procedure takes a sequence of alternating slot-names and initialization values in
INITARGSand initializes the corresponding slots inINSTANCE.(define-class <pos> () (x y)) (define-method (initialize (pos <pos>) initargs) (call-next-method) (initialize-slots pos initargs)) (define p1 (make <pos> 'x 1 'y 2)) (define p2 (make <pos> 'x 3 'y 5))
The class hierarchy of builtin classes looks like this:
<top>
<object>
<class>
<procedure-class>
<procedure>
<entity-class>
<generic>
<primitive-class>
<c++-object>
<primitive>
<void>
<boolean>
<symbol>
<char>
<vector>
<pair>
<number>
<integer>
<exact>
<inexact>
<string>
<port>
<input-port>
<output-port>
<pointer>
<tagged-pointer>
<swig-pointer>
<locative>
<byte-vector>
<u8vector>
<s8vector>
<u16vector>
<s16vector>
<u32vector>
<s32vector>
<f32vector>
<f64vector>
<structure>
<char-set>
<condition>
<condition-variable>
<environment>
<hash-table>
<lock>
<mmap>
<mutex>
<promise>
<queue>
<read-table>
<regexp>
<tcp-listener>
<thread>
<time>
<end-of-file>
The pa. If no generic function is defined under this name, then a fresh generic function object is created and assigned to
NAME.Note that only
define-genericexpands into a valid definition, so for internal lexically scoped definitions usedefine-generic.Currently methods defined with
define-methodshould not be hidden (via(declare (hide ...)), nor should such files be compiled inblockmode, unless the methods are exported.
(add-method GENERIC METHOD)Adds the method object
METHODto the list of applicable methods for the generic functionGENERIC.
(make CLASS INITARG ...)Creates a new instance of
CLASSand passesINITARG ...to theinitializemethod of this class.
(make-class SUPERCLASSES SLOTNAMES)Creates a new class object, where
SUPERCLASSESshould be the list of direct superclass objects andSLOTNAMESshould be a list of symbols naming the slots of this class.
(make-generic [NAME])Creates a new generic function object. If
NAMEis specified, then it should be a string.
(make-method SPECIALIZERS PROC)Creates a new method object specialized to the list of classes in
SPECIALIZERS.(define-method (foo (x <bar>)) 123) <=> (add-method foo (make-method (list <bar>) (lambda (call-next-method x) 123)))
(slot-ref INSTANCE SLOTNAME)Returns the value of the slot
SLOTNAMEof the objectINSTANCE.
(slot-set! INSTANCE SLOTNAME VALUE) (set! (slot-ref INSTANCE SLOTNAME) VALUE)Sets the value of the slot
SLOTNAMEof the objectINSTANCEtoVALUE.
(class-cpl CLASS)Returns the class-precedence-list of
CLASSas a list of classes.
(class-direct-slots CLASS)Returns the list of direct slots of
CLASSas a list of lists, where each sublist contains the name of the slot.
(class-direct-supers CLASS)Returns the list of direct superclasses of
CLASS.
(class-slots CLASS)Returns the list of all slots of
CLASSand its superclasses as a list of lists, where each sublist contains the name of the slot.
(generic-methods GENERIC)Returns the list of all methods associated with the generic function
GENERIC.
(method-specializers METHOD)Returns the list of classes that specialize
METHOD.
(method-procedure METHOD)Returns the procedure that contains the body of
METHOD.
(subclass? CLASS1 CLASS2)Returns
#tisCLASS1is a subclass ofCLASS2, or#fotherwise. Note that the following holds:(subclass? X X) ==> #t
(instance-of? X CLASS)Returns
#tifXis an instance ofCLASS(or one of its subclasses).
These definitions allow interfacing to the Meta Object Protocol
of TinyCLOS. For serious use, it is recommended to consult
the source code (tinyclos.scm).
(allocate-instance CLASS)Allocates storage for an instance of
CLASSand returns the instance.
(compute-apply-generic GENERIC)Returns a procedure that will be called to apply the generic function methods to the arguments.
(compute-apply-methods GENERIC)Returns a procedure of two arguments, a list of applicable methods and a list of arguments and applies the methods.
(compute-methods GENERIC)Returns a procedure of one argument. The procedure is called with the list of actual arguments passed to the generic function and should return a list of applicable methods, sorted by precedence.
(compute-getter-and-setter CLASS SLOT ALLOCATOR)Returns two values, the procedures that get and set the contents of the slot
SLOT.ALLOCATORis a procedure of one argument that gets an initalizer function and returns the getter and setter procedures for the allocated slot.
(compute-method-more-specific? GENERIC)Returns a procedure of three arguments (two methods and a list of arguments) that returns
#tif the first method is more specific than the second one with respect to the list of arguments. Otherwise the returned predicate returns#f.
(initialize INSTANCE INITARGS)Initializes the object
INSTANCE.INITARGSis the list of initialization arguments that were passed to themakeprocedure.
(describe-object INSTANCE [PORT])Writes a description of
INSTANCEtoPORT. Execution of the interpreter command,dwill invoke this generic function. IfPORTis not given it defaults to the value of(current-output-port).
(print-object INSTANCE [PORT])Writes a textual representation of
INSTANCEtoPORT. Any output of an instance withdisplay, writeandPORTis not given it defaults to the value of(current-output-port).
(initialize-slots INSTANCE INITARGS)This procedure takes a sequence of alternating slot-names and initialization values in
INITARGSand initializes the corresponding slots inINSTANCE.(define-class <pos> () (x y)) (define-method (initialize (pos <pos>) initargs) (call-next-method) (initialize-slots pos initargs)) (define p1 (make <pos> 'x 1 'y 2)) (define p2 (make <pos> 'x 3 'y 5))
The class hierarchy of builtin classes looks like this:
<top>
<object>
<class>
<procedure-class>
<procedure>
<entity-class>
<generic>
<primitive-class>
<c++-object>
<primitive>
<void>
<boolean>
<symbol>
<char>
<vector>
<pair>
<number>
<integer>
<exact>
<inexact>
<string>
<port>
<input-port>
<output-port>
<pointer>
<tagged-pointer>
<swig-pointer>
<locative>
<byte-vector>
<u8vector>
<s8vector>
<u16vector>
<s16vector>
<u32vector>
<s32vector>
<f32vector>
<f64vector>
<structure>
<char-set>
<condition>
<condition-variable>
<environment>
<hash-table>
<lock>
<mmap>
<mutex>
<promise>
<queue>
<read-table>
<regexp>
<tcp-listener>
<thread>
<time>
<end-of-file>
The pa. If no generic function is defined under this name, then a fresh generic function object is created and assigned to
NAME.Note that only
define-genericexpands into a valid definition, so for internal lexically scoped definitions usedefine-generic.Currently methods defined with
define-methodshould not be hidden (via(declare (hide ...)), nor should such files be compiled inblockmode, unless the methods are exported.
(add-method GENERIC METHOD)Adds the method object
METHODto the list of applicable methods for the generic functionGENERIC.
(make CLASS INITARG ...)Creates a new instance of
CLASSand passesINITARG ...to theinitializemethod of this class.
(make-class SUPERCLASSES SLOTNAMES)Creates a new class object, where
SUPERCLASSESshould be the list of direct superclass objects andSLOTNAMESshould be a list of symbols naming the slots of this class.
(make-generic [NAME])Creates a new generic function object. If
NAMEis specified, then it should be a string.
(make-method SPECIALIZERS PROC)Creates a new method object specialized to the list of classes in
SPECIALIZERS.(define-method (foo (x <bar>)) 123) <=> (add-method foo (make-method (list <bar>) (lambda (call-next-method x) 123)))
(slot-ref INSTANCE SLOTNAME)Returns the value of the slot
SLOTNAMEof the objectINSTANCE.
(slot-set! INSTANCE SLOTNAME VALUE) (set! (slot-ref INSTANCE SLOTNAME) VALUE)Sets the value of the slot
SLOTNAMEof the objectINSTANCEtoVALUE.
(class-cpl CLASS)Returns the class-precedence-list of
CLASSas a list of classes.
(class-direct-slots CLASS)Returns the list of direct slots of
CLASSas a list of lists, where each sublist contains the name of the slot.
(class-direct-supers CLASS)Returns the list of direct superclasses of
CLASS.
(class-slots CLASS)Returns the list of all slots of
CLASSand its superclasses as a list of lists, where each sublist contains the name of the slot.
(generic-methods GENERIC)Returns the list of all methods associated with the generic function
GENERIC.
(method-specializers METHOD)Returns the list of classes that specialize
METHOD.
(method-procedure METHOD)Returns the procedure that contains the body of
METHOD.
(subclass? CLASS1 CLASS2)Returns
#tisCLASS1is a subclass ofCLASS2, or#fotherwise. Note that the following holds:(subclass? X X) ==> #t
(instance-of? X CLASS)Returns
#tifXis an instance ofCLASS(or one of its subclasses).
These definitions allow interfacing to the Meta Object Protocol
of TinyCLOS. For serious use, it is recommended to consult
the source code (tinyclos.scm).
(allocate-instance CLASS)Allocates storage for an instance of
CLASSand returns the instance.
(compute-apply-generic GENERIC)Returns a procedure that will be called to apply the generic function methods to the arguments.
(compute-apply-methods GENERIC)Returns a procedure of two arguments, a list of applicable methods and a list of arguments and applies the methods.
(compute-methods GENERIC)Returns a procedure of one argument. The procedure is called with the list of actual arguments passed to the generic function and should return a list of applicable methods, sorted by precedence.
(compute-getter-and-setter CLASS SLOT ALLOCATOR)Returns two values, the procedures that get and set the contents of the slot
SLOT.ALLOCATORis a procedure of one argument that gets an initalizer function and returns the getter and setter procedures for the allocated slot.
(compute-method-more-specific? GENERIC)Returns a procedure of three arguments (two methods and a list of arguments) that returns
#tif the first method is more specific than the second one with respect to the list of arguments. Otherwise the returned predicate returns#f.
(initialize INSTANCE INITARGS)Initializes the object
INSTANCE.INITARGSis the list of initialization arguments that were passed to themakeprocedure.
(describe-object INSTANCE [PORT])Writes a description of
INSTANCEtoPORT. Execution of the interpreter command,dwill invoke this generic function. IfPORTis not given it defaults to the value of(current-output-port).
(print-object INSTANCE [PORT])Writes a textual representation of
INSTANCEtoPORT. Any output of an instance withdisplay, writeandPORTis not given it defaults to the value of(current-output-port).
(initialize-slots INSTANCE INITARGS)This procedure takes a sequence of alternating slot-names and initialization values in
INITARGSand initializes the corresponding slots inINSTANCE.(define-class <pos> () (x y)) (define-method (initialize (pos <pos>) initargs) (call-next-method) (initialize-slots pos initargs)) (define p1 (make <pos> 'x 1 'y 2)) (define p2 (make <pos> 'x 3 'y 5))
The class hierarchy of builtin classes looks like this:
<top>
<object>
<class>
<procedure-class>
<procedure>
<entity-class>
<generic>
<primitive-class>
<c++-object>
<primitive>
<void>
<boolean>
<symbol>
<char>
<vector>
<pair>
<number>
<integer>
<exact>
<inexact>
<string>
<port>
<input-port>
<output-port>
<pointer>
<tagged-pointer>
<swig-pointer>
<locative>
<byte-vector>
<u8vector>
<s8vector>
<u16vector>
<s16vector>
<u32vector>
<s32vector>
<f32vector>
<f64vector>
<structure>
<char-set>
<condition>
<condition-variable>
<environment>
<hash-table>
<lock>
<mmap>
<mutex>
<promise>
<queue>
<read-table>
<regexp>
<tcp-listener>
<thread>
<time>
<end-of-file>
The pa. If no generic function is defined under this name, then a fresh generic function object is created and assigned to
NAME.Note that only
define-genericexpands into a valid definition, so for internal lexically scoped definitions usedefine-generic.Currently methods defined with
define-methodshould not be hidden (via(declare (hide ...)), nor should such files be compiled inblockmode, unless the methods are exported.
(add-method GENERIC METHOD)Adds the method object
METHODto the list of applicable methods for the generic functionGENERIC.
(make CLASS INITARG ...)Creates a new instance of
CLASSand passesINITARG ...to theinitializemethod of this class.
(make-class SUPERCLASSES SLOTNAMES)Creates a new class object, where
SUPERCLASSESshould be the list of direct superclass objects andSLOTNAMESshould be a list of symbols naming the slots of this class.
(make-generic [NAME])Creates a new generic function object. If
NAMEis specified, then it should be a string.
(make-method SPECIALIZERS PROC)Creates a new method object specialized to the list of classes in
SPECIALIZERS.(define-method (foo (x <bar>)) 123) <=> (add-method foo (make-method (list <bar>) (lambda (call-next-method x) 123)))
(slot-ref INSTANCE SLOTNAME)Returns the value of the slot
SLOTNAMEof the objectINSTANCE.
(slot-set! INSTANCE SLOTNAME VALUE) (set! (slot-ref INSTANCE SLOTNAME) VALUE)Sets the value of the slot
SLOTNAMEof the objectINSTANCEtoVALUE.
(class-cpl CLASS)Returns the class-precedence-list of
CLASSas a list of classes.
(class-direct-slots CLASS)Returns the list of direct slots of
CLASSas a list of lists, where each sublist contains the name of the slot.
(class-direct-supers CLASS)Returns the list of direct superclasses of
CLASS.
(class-slots CLASS)Returns the list of all slots of
CLASSand its superclasses as a list of lists, where each sublist contains the name of the slot.
(generic-methods GENERIC)Returns the list of all methods associated with the generic function
GENERIC.
(method-specializers METHOD)Returns the list of classes that specialize
METHOD.
(method-procedure METHOD)Returns the procedure that contains the body of
METHOD.
(subclass? CLASS1 CLASS2)Returns
#tisCLASS1is a subclass ofCLASS2, or#fotherwise. Note that the following holds:(subclass? X X) ==> #t
(instance-of? X CLASS)Returns
#tifXis an instance ofCLASS(or one of its subclasses).
These definitions allow interfacing to the Meta Object Protocol
of TinyCLOS. For serious use, it is recommended to consult
the source code (tinyclos.scm).
(allocate-instance CLASS)Allocates storage for an instance of
CLASSand returns the instance.
(compute-apply-generic GENERIC)Returns a procedure that will be called to apply the generic function methods to the arguments.
(compute-apply-methods GENERIC)Returns a procedure of two arguments, a list of applicable methods and a list of arguments and applies the methods.
(compute-methods GENERIC)Returns a procedure of one argument. The procedure is called with the list of actual arguments passed to the generic function and should return a list of applicable methods, sorted by precedence.
(compute-getter-and-setter CLASS SLOT ALLOCATOR)Returns two values, the procedures that get and set the contents of the slot
SLOT.ALLOCATORis a procedure of one argument that gets an initalizer function and returns the getter and setter procedures for the allocated slot.
(compute-method-more-specific? GENERIC)Returns a procedure of three arguments (two methods and a list of arguments) that returns
#tif the first method is more specific than the second one with respect to the list of arguments. Otherwise the returned predicate returns#f.
(initialize INSTANCE INITARGS)Initializes the object
INSTANCE.INITARGSis the list of initialization arguments that were passed to themakeprocedure.
(describe-object INSTANCE [PORT])Writes a description of
INSTANCEtoPORT. Execution of the interpreter command,dwill invoke this generic function. IfPORTis not given it defaults to the value of(current-output-port).
(print-object INSTANCE [PORT])Writes a textual representation of
INSTANCEtoPORT. Any output of an instance withdisplay, writeandPORTis not given it defaults to the value of(current-output-port).
(initialize-slots INSTANCE INITARGS)This procedure takes a sequence of alternating slot-names and initialization values in
INITARGSand initializes the corresponding slots inINSTANCE.(define-class <pos> () (x y)) (define-method (initialize (pos <pos>) initargs) (call-next-method) (initialize-slots pos initargs)) (define p1 (make <pos> 'x 1 'y 2)) (define p2 (make <pos> 'x 3 'y 5))
The class hierarchy of builtin classes looks like this:
<top>
<object>
<class>
<procedure-class>
<procedure>
<entity-class>
<generic>
<primitive-class>
<c++-object>
<primitive>
<void>
<boolean>
<symbol>
<char>
<vector>
<pair>
<number>
<integer>
<exact>
<inexact>
<string>
<port>
<input-port>
<output-port>
<pointer>
<tagged-pointer>
<swig-pointer>
<locative>
<byte-vector>
<u8vector>
<s8vector>
<u16vector>
<s16vector>
<u32vector>
<s32vector>
<f32vector>
<f64vector>
<structure>
<char-set>
<condition>
<condition-variable>
<environment>
<hash-table>
<lock>
<mmap>
<mutex>
<promise>
<queue>
<read-table>
<regexp>
<tcp-listener>
<thread>
<time>
<end-of-file>
The pa. If no generic function is defined under this name, then a fresh generic function object is created and assigned to
NAME.Note that only
define-genericexpands into a valid definition, so for internal lexically scoped definitions usedefine-generic.Currently methods defined with
define-methodshould not be hidden (via(declare (hide ...)), nor should such files be compiled inblockmode, unless the methods are exported.
(add-method GENERIC METHOD)Adds the method object
METHODto the list of applicable methods for the generic functionGENERIC.
(make CLASS INITARG ...)Creates a new instance of
CLASSand passesINITARG ...to theinitializemethod of this class.
(make-class SUPERCLASSES SLOTNAMES)Creates a new class object, where
SUPERCLASSESshould be the list of direct superclass objects andSLOTNAMESshould be a list of symbols naming the slots of this class.
(make-generic [NAME])Creates a new generic function object. If
NAMEis specified, then it should be a string.
(make-method SPECIALIZERS PROC)Creates a new method object specialized to the list of classes in
SPECIALIZERS.(define-method (foo (x <bar>)) 123) <=> (add-method foo (make-method (list <bar>) (lambda (call-next-method x) 123)))
(slot-ref INSTANCE SLOTNAME)Returns the value of the slot
SLOTNAMEof the objectINSTANCE.
(slot-set! INSTANCE SLOTNAME VALUE) (set! (slot-ref INSTANCE SLOTNAME) VALUE)Sets the value of the slot
SLOTNAMEof the objectINSTANCEtoVALUE.
(class-cpl CLASS)Returns the class-precedence-list of
CLASSas a list of classes.
(class-direct-slots CLASS)Returns the list of direct slots of
CLASSas a list of lists, where each sublist contains the name of the slot.
(class-direct-supers CLASS)Returns the list of direct superclasses of
CLASS.
(class-slots CLASS)Returns the list of all slots of
CLASSand its superclasses as a list of lists, where each sublist contains the name of the slot.
(generic-methods GENERIC)Returns the list of all methods associated with the generic function
GENERIC.
(method-specializers METHOD)Returns the list of classes that specialize
METHOD.
(method-procedure METHOD)Returns the procedure that contains the body of
METHOD.
(subclass? CLASS1 CLASS2)Returns
#tisCLASS1is a subclass ofCLASS2, or#fotherwise. Note that the following holds:(subclass? X X) ==> #t
(instance-of? X CLASS)Returns
#tifXis an instance ofCLASS(or one of its subclasses).
These definitions allow interfacing to the Meta Object Protocol
of TinyCLOS. For serious use, it is recommended to consult
the source code (tinyclos.scm).
(allocate-instance CLASS)Allocates storage for an instance of
CLASSand returns the instance.
(compute-apply-generic GENERIC)Returns a procedure that will be called to apply the generic function methods to the arguments.
(compute-apply-methods GENERIC)Returns a procedure of two arguments, a list of applicable methods and a list of arguments and applies the methods.
(compute-methods GENERIC)Returns a procedure of one argument. The procedure is called with the list of actual arguments passed to the generic function and should return a list of applicable methods, sorted by precedence.
(compute-getter-and-setter CLASS SLOT ALLOCATOR)Returns two values, the procedures that get and set the contents of the slot
SLOT.ALLOCATORis a procedure of one argument that gets an initalizer function and returns the getter and setter procedures for the allocated slot.
(compute-method-more-specific? GENERIC)Returns a procedure of three arguments (two methods and a list of arguments) that returns
#tif the first method is more specific than the second one with respect to the list of arguments. Otherwise the returned predicate returns#f.
(initialize INSTANCE INITARGS)Initializes the object
INSTANCE.INITARGSis the list of initialization arguments that were passed to themakeprocedure.
(describe-object INSTANCE [PORT])Writes a description of
INSTANCEtoPORT. Execution of the interpreter command,dwill invoke this generic function. IfPORTis not given it defaults to the value of(current-output-port).
(print-object INSTANCE [PORT])Writes a textual representation of
INSTANCEtoPORT. Any output of an instance withdisplay, writeandPORTis not given it defaults to the value of(current-output-port).
(initialize-slots INSTANCE INITARGS)This procedure takes a sequence of alternating slot-names and initialization values in
INITARGSand initializes the corresponding slots inINSTANCE.(define-class <pos> () (x y)) (define-method (initialize (pos <pos>) initargs) (call-next-method) (initialize-slots pos initargs)) (define p1 (make <pos> 'x 1 'y 2)) (define p2 (make <pos> 'x 3 'y 5))
The class hierarchy of builtin classes looks like this:
<top>
<object>
<class>
<procedure-class>
<procedure>
<entity-class>
<generic>
<primitive-class>
<c++-object>
<primitive>
<void>
<boolean>
<symbol>
<char>
<vector>
<pair>
<number>
<integer>
<exact>
<inexact>
<string>
<port>
<input-port>
<output-port>
<pointer>
<tagged-pointer>
<swig-pointer>
<locative>
<byte-vector>
<u8vector>
<s8vector>
<u16vector>
<s16vector>
<u32vector>
<s32vector>
<f32vector>
<f64vector>
<structure>
<char-set>
<condition>
<condition-variable>
<environment>
<hash-table>
<lock>
<mmap>
<mutex>
<promise>
<queue>
<read-table>
<regexp>
<tcp-listener>
<thread>
<time>
<end-of-file>
The pa. If no generic function is defined under this name, then a fresh generic function object is created and assigned to
NAME.Note that only
define-genericexpands into a valid definition, so for internal lexically scoped definitions usedefine-generic.Currently methods defined with
define-methodshould not be hidden (via(declare (hide ...)), nor should such files be compiled inblockmode, unless the methods are exported.
(add-method GENERIC METHOD)Adds the method object
METHODto the list of applicable methods for the generic functionGENERIC.
(make CLASS INITARG ...)Creates a new instance of
CLASSand passesINITARG ...to theinitializemethod of this class.
(make-class SUPERCLASSES SLOTNAMES)Creates a new class object, where
SUPERCLASSESshould be the list of direct superclass objects andSLOTNAMESshould be a list of symbols naming the slots of this class.
(make-generic [NAME])Creates a new generic function object. If
NAMEis specified, then it should be a string.
(make-method SPECIALIZERS PROC)Creates a new method object specialized to the list of classes in
SPECIALIZERS.(define-method (foo (x <bar>)) 123) <=> (add-method foo (make-method (list <bar>) (lambda (call-next-method x) 123)))
(slot-ref INSTANCE SLOTNAME)Returns the value of the slot
SLOTNAMEof the objectINSTANCE.
(slot-set! INSTANCE SLOTNAME VALUE) (set! (slot-ref INSTANCE SLOTNAME) VALUE)Sets the value of the slot
SLOTNAMEof the objectINSTANCEtoVALUE.
(class-cpl CLASS)Returns the class-precedence-list of
CLASSas a list of classes.
(class-direct-slots CLASS)Returns the list of direct slots of
CLASSas a list of lists, where each sublist contains the name of the slot.
(class-direct-supers CLASS)Returns the list of direct superclasses of
CLASS.
(class-slots CLASS)Returns the list of all slots of
CLASSand its superclasses as a list of lists, where each sublist contains the name of the slot.
(generic-methods GENERIC)Returns the list of all methods associated with the generic function
GENERIC.
(method-specializers METHOD)Returns the list of classes that specialize
METHOD.
(method-procedure METHOD)Returns the procedure that contains the body of
METHOD.
(subclass? CLASS1 CLASS2)Returns
#tisCLASS1is a subclass ofCLASS2, or#fotherwise. Note that the following holds:(subclass? X X) ==> #t
(instance-of? X CLASS)Returns
#tifXis an instance ofCLASS(or one of its subclasses).
These definitions allow interfacing to the Meta Object Protocol
of TinyCLOS. For serious use, it is recommended to consult
the source code (tinyclos.scm).
(allocate-instance CLASS)Allocates storage for an instance of
CLASSand returns the instance.
(compute-apply-generic GENERIC)Returns a procedure that will be called to apply the generic function methods to the arguments.
(compute-apply-methods GENERIC)Returns a procedure of two arguments, a list of applicable methods and a list of arguments and applies the methods.
(compute-methods GENERIC)Returns a procedure of one argument. The procedure is called with the list of actual arguments passed to the generic function and should return a list of applicable methods, sorted by precedence.
(compute-getter-and-setter CLASS SLOT ALLOCATOR)Returns two values, the procedures that get and set the contents of the slot
SLOT.ALLOCATORis a procedure of one argument that gets an initalizer function and returns the getter and setter procedures for the allocated slot.
(compute-method-more-specific? GENERIC)Returns a procedure of three arguments (two methods and a list of arguments) that returns
#tif the first method is more specific than the second one with respect to the list of arguments. Otherwise the returned predicate returns#f.
(initialize INSTANCE INITARGS)Initializes the object
INSTANCE.INITARGSis the list of initialization arguments that were passed to themakeprocedure.
(describe-object INSTANCE [PORT])Writes a description of
INSTANCEtoPORT. Execution of the interpreter command,dwill invoke this generic function. IfPORTis not given it defaults to the value of(current-output-port).
(print-object INSTANCE [PORT])Writes a textual representation of
INSTANCEtoPORT. Any output of an instance withdisplay, writeandPORTis not given it defaults to the value of(current-output-port).
(initialize-slots INSTANCE INITARGS)This procedure takes a sequence of alternating slot-names and initialization values in
INITARGSand initializes the corresponding slots inINSTANCE.(define-class <pos> () (x y)) (define-method (initialize (pos <pos>) initargs) (call-next-method) (initialize-slots pos initargs)) (define p1 (make <pos> 'x 1 'y 2)) (define p2 (make <pos> 'x 3 'y 5))
The class hierarchy of builtin classes looks like this:
<top>
<object>
<class>
<procedure-class>
<procedure>
<entity-class>
<generic>
<primitive-class>
<c++-object>
<primitive>
<void>
<boolean>
<symbol>
<char>
<vector>
<pair>
<number>
<integer>
<exact>
<inexact>
<string>
<port>
<input-port>
<output-port>
<pointer>
<tagged-pointer>
<swig-pointer>
<locative>
<byte-vector>
<u8vector>
<s8vector>
<u16vector>
<s16vector>
<u32vector>
<s32vector>
<f32vector>
<f64vector>
<structure>
<char-set>
<condition>
<condition-variable>
<environment>
<hash-table>
<lock>
<mmap>
<mutex>
<promise>
<queue>
<read-table>
<regexp>
<tcp-listener>
<thread>
<time>
<end-of-file>
The pa. If no generic function is defined under this name, then a fresh generic function object is created and assigned to
NAME.Note that only
define-genericexpands into a valid definition, so for internal lexically scoped definitions usedefine-generic.Currently methods defined with
define-methodshould not be hidden (via(declare (hide ...)), nor should such files be compiled inblockmode, unless the methods are exported.
(add-method GENERIC METHOD)Adds the method object
METHODto the list of applicable methods for the generic functionGENERIC.
(make CLASS INITARG ...)Creates a new instance of
CLASSand passesINITARG ...to theinitializemethod of this class.
(make-class SUPERCLASSES SLOTNAMES)Creates a new class object, where
SUPERCLASSESshould be the list of direct superclass objects andSLOTNAMESshould be a list of symbols naming the slots of this class.
(make-generic [NAME])Creates a new generic function object. If
NAMEis specified, then it should be a string.
(make-method SPECIALIZERS PROC)Creates a new method object specialized to the list of classes in
SPECIALIZERS.(define-method (foo (x <bar>)) 123) <=> (add-method foo (make-method (list <bar>) (lambda (call-next-method x) 123)))
(slot-ref INSTANCE SLOTNAME)Returns the value of the slot
SLOTNAMEof the objectINSTANCE.
(slot-set! INSTANCE SLOTNAME VALUE) (set! (slot-ref INSTANCE SLOTNAME) VALUE)Sets the value of the slot
SLOTNAMEof the objectINSTANCEtoVALUE.
(class-cpl CLASS)Returns the class-precedence-list of
CLASSas a list of classes.
(class-direct-slots CLASS)Returns the list of direct slots of
CLASSas a list of lists, where each sublist contains the name of the slot.
(class-direct-supers CLASS)Returns the list of direct superclasses of
CLASS.
(class-slots CLASS)Returns the list of all slots of
CLASSand its superclasses as a list of lists, where each sublist contains the name of the slot.
(generic-methods GENERIC)Returns the list of all methods associated with the generic function
GENERIC.
(method-specializers METHOD)Returns the list of classes that specialize
METHOD.
(method-procedure METHOD)Returns the procedure that contains the body of
METHOD.
(subclass? CLASS1 CLASS2)Returns
#tisCLASS1is a subclass ofCLASS2, or#fotherwise. Note that the following holds:(subclass? X X) ==> #t
(instance-of? X CLASS)Returns
#tifXis an instance ofCLASS(or one of its subclasses).
These definitions allow interfacing to the Meta Object Protocol
of TinyCLOS. For serious use, it is recommended to consult
the source code (tinyclos.scm).
(allocate-instance CLASS)Allocates storage for an instance of
CLASSand returns the instance.
(compute-apply-generic GENERIC)Returns a procedure that will be called to apply the generic function methods to the arguments.
(compute-apply-methods GENERIC)Returns a procedure of two arguments, a list of applicable methods and a list of arguments and applies the methods.
(compute-methods GENERIC)Returns a procedure of one argument. The procedure is called with the list of actual arguments passed to the generic function and should return a list of applicable methods, sorted by precedence.
(compute-getter-and-setter CLASS SLOT ALLOCATOR)Returns two values, the procedures that get and set the contents of the slot
SLOT.ALLOCATORis a procedure of one argument that gets an initalizer function and returns the getter and setter procedures for the allocated slot.
(compute-method-more-specific? GENERIC)Returns a procedure of three arguments (two methods and a list of arguments) that returns
#tif the first method is more specific than the second one with respect to the list of arguments. Otherwise the returned predicate returns#f.
(initialize INSTANCE INITARGS)Initializes the object
INSTANCE.INITARGSis the list of initialization arguments that were passed to themakeprocedure.
(describe-object INSTANCE [PORT])Writes a description of
INSTANCEtoPORT. Execution of the interpreter command,dwill invoke this generic function. IfPORTis not given it defaults to the value of(current-output-port).
(print-object INSTANCE [PORT])Writes a textual representation of
INSTANCEtoPORT. Any output of an instance withdisplay, writeandPORTis not given it defaults to the value of(current-output-port).
(initialize-slots INSTANCE INITARGS)This procedure takes a sequence of alternating slot-names and initialization values in
INITARGSand initializes the corresponding slots inINSTANCE.(define-class <pos> () (x y)) (define-method (initialize (pos <pos>) initargs) (call-next-method) (initialize-slots pos initargs)) (define p1 (make <pos> 'x 1 'y 2)) (define p2 (make <pos> 'x 3 'y 5))
The class hierarchy of builtin classes looks like this:
<top>
<object>
<class>
<procedure-class>
<procedure>
<entity-class>
<generic>
<primitive-class>
<c++-object>
<primitive>
<void>
<boolean>
<symbol>
<char>
<vector>
<pair>
<number>
<integer>
<exact>
<inexact>
<string>
<port>
<input-port>
<output-port>
<pointer>
<tagged-pointer>
<swig-pointer>
<locative>
<byte-vector>
<u8vector>
<s8vector>
<u16vector>
<s16vector>
<u32vector>
<s32vector>
<f32vector>
<f64vector>
<structure>
<char-set>
<condition>
<condition-variable>
<environment>
<hash-table>
<lock>
<mmap>
<mutex>
<promise>
<queue>
<read-table>
<regexp>
<tcp-listener>
<thread>
<time>
<end-of-file>
The pa. If no generic function is defined under this name, then a fresh generic function object is created and assigned to
NAME.Note that only
define-genericexpands into a valid definition, so for internal lexically scoped definitions usedefine-generic.Currently methods defined with
define-methodshould not be hidden (via(declare (hide ...)), nor should such files be compiled inblockmode, unless the methods are exported.
(add-method GENERIC METHOD)Adds the method object
METHODto the list of applicable methods for the generic functionGENERIC.
(make CLASS INITARG ...)Creates a new instance of
CLASSand passesINITARG ...to theinitializemethod of this class.
(make-class SUPERCLASSES SLOTNAMES)Creates a new class object, where
SUPERCLASSESshould be the list of direct superclass objects andSLOTNAMESshould be a list of symbols naming the slots of this class.
(make-generic [NAME])Creates a new generic function object. If
NAMEis specified, then it should be a string.
(make-method SPECIALIZERS PROC)Creates a new method object specialized to the list of classes in
SPECIALIZERS.(define-method (foo (x <bar>)) 123) <=> (add-method foo (make-method (list <bar>) (lambda (call-next-method x) 123)))
(slot-ref INSTANCE SLOTNAME)Returns the value of the slot
SLOTNAMEof the objectINSTANCE.
(slot-set! INSTANCE SLOTNAME VALUE) (set! (slot-ref INSTANCE SLOTNAME) VALUE)Sets the value of the slot
SLOTNAMEof the objectINSTANCEtoVALUE.
(class-cpl CLASS)Returns the class-precedence-list of
CLASSas a list of classes.
(class-direct-slots CLASS)Returns the list of direct slots of
CLASSas a list of lists, where each sublist contains the name of the slot.
(class-direct-supers CLASS)Returns the list of direct superclasses of
CLASS.
(class-slots CLASS)Returns the list of all slots of
CLASSand its superclasses as a list of lists, where each sublist contains the name of the slot.
(generic-methods GENERIC)Returns the list of all methods associated with the generic function
GENERIC.
(method-specializers METHOD)Returns the list of classes that specialize
METHOD.
(method-procedure METHOD)Returns the procedure that contains the body of
METHOD.
(subclass? CLASS1 CLASS2)Returns
#tisCLASS1is a subclass ofCLASS2, or#fotherwise. Note that the following holds:(subclass? X X) ==> #t
(instance-of? X CLASS)Returns
#tifXis an instance ofCLASS(or one of its subclasses).
These definitions allow interfacing to the Meta Object Protocol
of TinyCLOS. For serious use, it is recommended to consult
the source code (tinyclos.scm).
(allocate-instance CLASS)Allocates storage for an instance of
CLASSand returns the instance.
(compute-apply-generic GENERIC)Returns a procedure that will be called to apply the generic function methods to the arguments.
(compute-apply-methods GENERIC)Returns a procedure of two arguments, a list of applicable methods and a list of arguments and applies the methods.
(compute-methods GENERIC)Returns a procedure of one argument. The procedure is called with the list of actual arguments passed to the generic function and should return a list of applicable methods, sorted by precedence.
(compute-getter-and-setter CLASS SLOT ALLOCATOR)Returns two values, the procedures that get and set the contents of the slot
SLOT.ALLOCATORis a procedure of one argument that gets an initalizer function and returns the getter and setter procedures for the allocated slot.
(compute-method-more-specific? GENERIC)Returns a procedure of three arguments (two methods and a list of arguments) that returns
#tif the first method is more specific than the second one with respect to the list of arguments. Otherwise the returned predicate returns#f.
(initialize INSTANCE INITARGS)Initializes the object
INSTANCE.INITARGSis the list of initialization arguments that were passed to themakeprocedure.
(describe-object INSTANCE [PORT])Writes a description of
INSTANCEtoPORT. Execution of the interpreter command,dwill invoke this generic function. IfPORTis not given it defaults to the value of(current-output-port).
(print-object INSTANCE [PORT])Writes a textual representation of
INSTANCEtoPORT. Any output of an instance withdisplay, writeandPORTis not given it defaults to the value of(current-output-port).
(initialize-slots INSTANCE INITARGS)This procedure takes a sequence of alternating slot-names and initialization values in
INITARGSand initializes the corresponding slots inINSTANCE.(define-class <pos> () (x y)) (define-method (initialize (pos <pos>) initargs) (call-next-method) (initialize-slots pos initargs)) (define p1 (make <pos> 'x 1 'y 2)) (define p2 (make <pos> 'x 3 'y 5))
The class hierarchy of builtin classes looks like this:
<top>
<object>
<class>
<procedure-class>
<procedure>
<entity-class>
<generic>
<primitive-class>
<c++-object>
<primitive>
<void>
<boolean>
<symbol>
<char>
<vector>
<pair>
<number>
<integer>
<exact>
<inexact>
<string>
<port>
<input-port>
<output-port>
<pointer>
<tagged-pointer>
<swig-pointer>
<locative>
<byte-vector>
<u8vector>
<s8vector>
<u16vector>
<s16vector>
<u32vector>
<s32vector>
<f32vector>
<f64vector>
<structure>
<char-set>
<condition>
<condition-variable>
<environment>
<hash-table>
<lock>
<mmap>
<mutex>
<promise>
<queue>
<read-table>
<regexp>
<tcp-listener>
<thread>
<time>
<end-of-file>
The pa. If no generic function is defined under this name, then a fresh generic function object is created and assigned to
NAME.Note that only
define-genericexpands into a valid definition, so for internal lexically scoped definitions usedefine-generic.Currently methods defined with
define-methodshould not be hidden (via(declare (hide ...)), nor should such files be compiled inblockmode, unless the methods are exported.
(add-method GENERIC METHOD)Adds the method object
METHODto the list of applicable methods for the generic functionGENERIC.
(make CLASS INITARG ...)Creates a new instance of
CLASSand passesINITARG ...to theinitializemethod of this class.
(make-class SUPERCLASSES SLOTNAMES)Creates a new class object, where
SUPERCLASSESshould be the list of direct superclass objects andSLOTNAMESshould be a list of symbols naming the slots of this class.
(make-generic [NAME])Creates a new generic function object. If
NAMEis specified, then it should be a string.
(make-method SPECIALIZERS PROC)Creates a new method object specialized to the list of classes in
SPECIALIZERS.(define-method (foo (x <bar>)) 123) <=> (add-method foo (make-method (list <bar>) (lambda (call-next-method x) 123)))
(slot-ref INSTANCE SLOTNAME)Returns the value of the slot
SLOTNAMEof the objectINSTANCE.
(slot-set! INSTANCE SLOTNAME VALUE) (set! (slot-ref INSTANCE SLOTNAME) VALUE)Sets the value of the slot
SLOTNAMEof the objectINSTANCEtoVALUE.
(class-cpl CLASS)Returns the class-precedence-list of
CLASSas a list of classes.
(class-direct-slots CLASS)Returns the list of direct slots of
CLASSas a list of lists, where each sublist contains the name of the slot.
(class-direct-supers CLASS)Returns the list of direct superclasses of
CLASS.
(class-slots CLASS)Returns the list of all slots of
CLASSand its superclasses as a list of lists, where each sublist contains the name of the slot.
(generic-methods GENERIC)Returns the list of all methods associated with the generic function
GENERIC.
(method-specializers METHOD)Returns the list of classes that specialize
METHOD.
(method-procedure METHOD)Returns the procedure that contains the body of
METHOD.
(subclass? CLASS1 CLASS2)Returns
#tisCLASS1is a subclass ofCLASS2, or#fotherwise. Note that the following holds:(subclass? X X) ==> #t
(instance-of? X CLASS)Returns
#tifXis an instance ofCLASS(or one of its subclasses).
These definitions allow interfacing to the Meta Object Protocol
of TinyCLOS. For serious use, it is recommended to consult
the source code (tinyclos.scm).
(allocate-instance CLASS)Allocates storage for an instance of
CLASSand returns the instance.
(compute-apply-generic GENERIC)Returns a procedure that will be called to apply the generic function methods to the arguments.
(compute-apply-methods GENERIC)Returns a procedure of two arguments, a list of applicable methods and a list of arguments and applies the methods.
(compute-methods GENERIC)Returns a procedure of one argument. The procedure is called with the list of actual arguments passed to the generic function and should return a list of applicable methods, sorted by precedence.
(compute-getter-and-setter CLASS SLOT ALLOCATOR)Returns two values, the procedures that get and set the contents of the slot
SLOT.ALLOCATORis a procedure of one argument that gets an initalizer function and returns the getter and setter procedures for the allocated slot.
(compute-method-more-specific? GENERIC)Returns a procedure of three arguments (two methods and a list of arguments) that returns
#tif the first method is more specific than the second one with respect to the list of arguments. Otherwise the returned predicate returns#f.
(initialize INSTANCE INITARGS)Initializes the object
INSTANCE.INITARGSis the list of initialization arguments that were passed to themakeprocedure.
(describe-object INSTANCE [PORT])Writes a description of
INSTANCEtoPORT. Execution of the interpreter command,dwill invoke this generic function. IfPORTis not given it defaults to the value of(current-output-port).
(print-object INSTANCE [PORT])Writes a textual representation of
INSTANCEtoPORT. Any output of an instance withdisplay, writeandPORTis not given it defaults to the value of(current-output-port).
(initialize-slots INSTANCE INITARGS)This procedure takes a sequence of alternating slot-names and initialization values in
INITARGSand initializes the corresponding slots inINSTANCE.(define-class <pos> () (x y)) (define-method (initialize (pos <pos>) initargs) (call-next-method) (initialize-slots pos initargs)) (define p1 (make <pos> 'x 1 'y 2)) (define p2 (make <pos> 'x 3 'y 5))
The class hierarchy of builtin classes looks like this:
<top>
<object>
<class>
<procedure-class>
<procedure>
<entity-class>
<generic>
<primitive-class>
<c++-object>
<primitive>
<void>
<boolean>
<symbol>
<char>
<vector>
<pair>
<number>
<integer>
<exact>
<inexact>
<string>
<port>
<input-port>
<output-port>
<pointer>
<tagged-pointer>
<swig-pointer>
<locative>
<byte-vector>
<u8vector>
<s8vector>
<u16vector>
<s16vector>
<u32vector>
<s32vector>
<f32vector>
<f64vector>
<structure>
<char-set>
<condition>
<condition-variable>
<environment>
<hash-table>
<lock>
<mmap>
<mutex>
<promise>
<queue>
<read-table>
<regexp>
<tcp-listener>
<thread>
<time>
<end-of-file>
The pa. If no generic function is defined under this name, then a fresh generic function object is created and assigned to
NAME.Note that only
define-genericexpands into a valid definition, so for internal lexically scoped definitions usedefine-generic.Currently methods defined with
define-methodshould not be hidden (via(declare (hide ...)), nor should such files be compiled inblockmode, unless the methods are exported.
(add-method GENERIC METHOD)Adds the method object
METHODto the list of applicable methods for the generic functionGENERIC.
(make CLASS INITARG ...)Creates a new instance of
CLASSand passesINITARG ...to theinitializemethod of this class.
(make-class SUPERCLASSES SLOTNAMES)Creates a new class object, where
SUPERCLASSESshould be the list of direct superclass objects andSLOTNAMESshould be a list of symbols naming the slots of this class.
(make-generic [NAME])Creates a new generic function object. If
NAMEis specified, then it should be a string.
(make-method SPECIALIZERS PROC)Creates a new method object specialized to the list of classes in
SPECIALIZERS.(define-method (foo (x <bar>)) 123) <=> (add-method foo (make-method (list <bar>) (lambda (call-next-method x) 123)))
(slot-ref INSTANCE SLOTNAME)Returns the value of the slot
SLOTNAMEof the objectINSTANCE.
(slot-set! INSTANCE SLOTNAME VALUE) (set! (slot-ref INSTANCE SLOTNAME) VALUE)Sets the value of the slot
SLOTNAMEof the objectINSTANCEtoVALUE.
(class-cpl CLASS)Returns the class-precedence-list of
CLASSas a list of classes.
(class-direct-slots CLASS)Returns the list of direct slots of
CLASSas a list of lists, where each sublist contains the name of the slot.
(class-direct-supers CLASS)Returns the list of direct superclasses of
CLASS.
(class-slots CLASS)Returns the list of all slots of
CLASSand its superclasses as a list of lists, where each sublist contains the name of the slot.
(generic-methods GENERIC)Returns the list of all methods associated with the generic function
GENERIC.
(method-specializers METHOD)Returns the list of classes that specialize
METHOD.
(method-procedure METHOD)Returns the procedure that contains the body of
METHOD.
(subclass? CLASS1 CLASS2)Returns
#tisCLASS1is a subclass ofCLASS2, or#fotherwise. Note that the following holds:(subclass? X X) ==> #t
(instance-of? X CLASS)Returns
#tifXis an instance ofCLASS(or one of its subclasses).
These definitions allow interfacing to the Meta Object Protocol
of TinyCLOS. For serious use, it is recommended to consult
the source code (tinyclos.scm).
(allocate-instance CLASS)Allocates storage for an instance of
CLASSand returns the instance.
(compute-apply-generic GENERIC)Returns a procedure that will be called to apply the generic function methods to the arguments.
(compute-apply-methods GENERIC)Returns a procedure of two arguments, a list of applicable methods and a list of arguments and applies the methods.
(compute-methods GENERIC)Returns a procedure of one argument. The procedure is called with the list of actual arguments passed to the generic function and should return a list of applicable methods, sorted by precedence.
(compute-getter-and-setter CLASS SLOT ALLOCATOR)Returns two values, the procedures that get and set the contents of the slot
SLOT.ALLOCATORis a procedure of one argument that gets an initalizer function and returns the getter and setter procedures for the allocated slot.
(compute-method-more-specific? GENERIC)Returns a procedure of three arguments (two methods and a list of arguments) that returns
#tif the first method is more specific than the second one with respect to the list of arguments. Otherwise the returned predicate returns#f.
(initialize INSTANCE INITARGS)Initializes the object
INSTANCE.INITARGSis the list of initialization arguments that were passed to themakeprocedure.
(describe-object INSTANCE [PORT])Writes a description of
INSTANCEtoPORT. Execution of the interpreter command,dwill invoke this generic function. IfPORTis not given it defaults to the value of(current-output-port).
(print-object INSTANCE [PORT])Writes a textual representation of
INSTANCEtoPORT. Any output of an instance withdisplay, writeandPORTis not given it defaults to the value of(current-output-port).
(initialize-slots INSTANCE INITARGS)This procedure takes a sequence of alternating slot-names and initialization values in
INITARGSand initializes the corresponding slots inINSTANCE.(define-class <pos> () (x y)) (define-method (initialize (pos <pos>) initargs) (call-next-method) (initialize-slots pos initargs)) (define p1 (make <pos> 'x 1 'y 2)) (define p2 (make <pos> 'x 3 'y 5))
The class hierarchy of builtin classes looks like this:
<top>
<object>
<class>
<procedure-class>
<procedure>
<entity-class>
<generic>
<primitive-class>
<c++-object>
<primitive>
<void>
<boolean>
<symbol>
<char>
<vector>
<pair>
<number>
<integer>
<exact>
<inexact>
<string>
<port>
<input-port>
<output-port>
<pointer>
<tagged-pointer>
<swig-pointer>
<locative>
<byte-vector>
<u8vector>
<s8vector>
<u16vector>
<s16vector>
<u32vector>
<s32vector>
<f32vector>
<f64vector>
<structure>
<char-set>
<condition>
<condition-variable>
<environment>
<hash-table>
<lock>
<mmap>
<mutex>
<promise>
<queue>
<read-table>
<regexp>
<tcp-listener>
<thread>
<time>
<end-of-file>
The pa. If no generic function is defined under this name, then a fresh generic function object is created and assigned to
NAME.Note that only
define-genericexpands into a valid definition, so for internal lexically scoped definitions usedefine-generic.Currently methods defined with
define-methodshould not be hidden (via(declare (hide ...)), nor should such files be compiled inblockmode, unless the methods are exported.
(add-method GENERIC METHOD)Adds the method object
METHODto the list of applicable methods for the generic functionGENERIC.
(make CLASS INITARG ...)Creates a new instance of
CLASSand passesINITARG ...to theinitializemethod of this class.
(make-class SUPERCLASSES SLOTNAMES)Creates a new class object, where
SUPERCLASSESshould be the list of direct superclass objects andSLOTNAMESshould be a list of symbols naming the slots of this class.
(make-generic [NAME])Creates a new generic function object. If
NAMEis specified, then it should be a string.
(make-method SPECIALIZERS PROC)Creates a new method object specialized to the list of classes in
SPECIALIZERS.(define-method (foo (x <bar>)) 123) <=> (add-method foo (make-method (list <bar>) (lambda (call-next-method x) 123)))
(slot-ref INSTANCE SLOTNAME)Returns the value of the slot
SLOTNAMEof the objectINSTANCE.
(slot-set! INSTANCE SLOTNAME VALUE) (set! (slot-ref INSTANCE SLOTNAME) VALUE)Sets the value of the slot
SLOTNAMEof the objectINSTANCEtoVALUE.
(class-cpl CLASS)Returns the class-precedence-list of
CLASSas a list of classes.
(class-direct-slots CLASS)Returns the list of direct slots of
CLASSas a list of lists, where each sublist contains the name of the slot.
(class-direct-supers CLASS)Returns the list of direct superclasses of
CLASS.
(class-slots CLASS)Returns the list of all slots of
CLASSand its superclasses as a list of lists, where each sublist contains the name of the slot.
(generic-methods GENERIC)Returns the list of all methods associated with the generic function
GENERIC.
(method-specializers METHOD)Returns the list of classes that specialize
METHOD.
(method-procedure METHOD)Returns the procedure that contains the body of
METHOD.
(subclass? CLASS1 CLASS2)Returns
#tisCLASS1is a subclass ofCLASS2, or#fotherwise. Note that the following holds:(subclass? X X) ==> #t
(instance-of? X CLASS)Returns
#tifXis an instance ofCLASS(or one of its subclasses).
These definitions allow interfacing to the Meta Object Protocol
of TinyCLOS. For serious use, it is recommended to consult
the source code (tinyclos.scm).
(allocate-instance CLASS)Allocates storage for an instance of
CLASSand returns the instance.
(compute-apply-generic GENERIC)Returns a procedure that will be called to apply the generic function methods to the arguments.
(compute-apply-methods GENERIC)Returns a procedure of two arguments, a list of applicable methods and a list of arguments and applies the methods.
(compute-methods GENERIC)Returns a procedure of one argument. The procedure is called with the list of actual arguments passed to the generic function and should return a list of applicable methods, sorted by precedence.
(compute-getter-and-setter CLASS SLOT ALLOCATOR)Returns two values, the procedures that get and set the contents of the slot
SLOT.ALLOCATORis a procedure of one argument that gets an initalizer function and returns the getter and setter procedures for the allocated slot.
(compute-method-more-specific? GENERIC)Returns a procedure of three arguments (two methods and a list of arguments) that returns
#tif the first method is more specific than the second one with respect to the list of arguments. Otherwise the returned predicate returns#f.
(initialize INSTANCE INITARGS)Initializes the object
INSTANCE.INITARGSis the list of initialization arguments that were passed to themakeprocedure.
(describe-object INSTANCE [PORT])Writes a description of
INSTANCEtoPORT. Execution of the interpreter command,dwill invoke this generic function. IfPORTis not given it defaults to the value of(current-output-port).
(print-object INSTANCE [PORT])Writes a textual representation of
INSTANCEtoPORT. Any output of an instance withdisplay, writeandPORTis not given it defaults to the value of(current-output-port).
(initialize-slots INSTANCE INITARGS)This procedure takes a sequence of alternating slot-names and initialization values in
INITARGSand initializes the corresponding slots inINSTANCE.(define-class <pos> () (x y)) (define-method (initialize (pos <pos>) initargs) (call-next-method) (initialize-slots pos initargs)) (define p1 (make <pos> 'x 1 'y 2)) (define p2 (make <pos> 'x 3 'y 5))
The class hierarchy of builtin classes looks like this:
<top>
<object>
<class>
<procedure-class>
<procedure>
<entity-class>
<generic>
<primitive-class>
<c++-object>
<primitive>
<void>
<boolean>
<symbol>
<char>
<vector>
<pair>
<number>
<integer>
<exact>
<inexact>
<string>
<port>
<input-port>
<output-port>
<pointer>
<tagged-pointer>
<swig-pointer>
<locative>
<byte-vector>
<u8vector>
<s8vector>
<u16vector>
<s16vector>
<u32vector>
<s32vector>
<f32vector>
<f64vector>
<structure>
<char-set>
<condition>
<condition-variable>
<environment>
<hash-table>
<lock>
<mmap>
<mutex>
<promise>
<queue>
<read-table>
<regexp>
<tcp-listener>
<thread>
<time>
<end-of-file>
The pa. If no generic function is defined under this name, then a fresh generic function object is created and assigned to
NAME.Note that only
define-genericexpands into a valid definition, so for internal lexically scoped definitions usedefine-generic.Currently methods defined with
define-methodshould not be hidden (via(declare (hide ...)), nor should such files be compiled inblockmode, unless the methods are exported.
(add-method GENERIC METHOD)Adds the method object
METHODto the list of applicable methods for the generic functionGENERIC.
(make CLASS INITARG ...)Creates a new instance of
CLASSand passesINITARG ...to theinitializemethod of this class.
(make-class SUPERCLASSES SLOTNAMES)Creates a new class object, where
SUPERCLASSESshould be the list of direct superclass objects andSLOTNAMESshould be a list of symbols naming the slots of this class.
(make-generic [NAME])Creates a new generic function object. If
NAMEis specified, then it should be a string.
(make-method SPECIALIZERS PROC)Creates a new method object specialized to the list of classes in
SPECIALIZERS.(define-method (foo (x <bar>)) 123) <=> (add-method foo (make-method (list <bar>) (lambda (call-next-method x) 123)))
(slot-ref INSTANCE SLOTNAME)Returns the value of the slot
SLOTNAMEof the objectINSTANCE.
(slot-set! INSTANCE SLOTNAME VALUE) (set! (slot-ref INSTANCE SLOTNAME) VALUE)Sets the value of the slot
SLOTNAMEof the objectINSTANCEtoVALUE.
(class-cpl CLASS)Returns the class-precedence-list of
CLASSas a list of classes.
(class-direct-slots CLASS)Returns the list of direct slots of
CLASSas a list of lists, where each sublist contains the name of the slot.
(class-direct-supers CLASS)Returns the list of direct superclasses of
CLASS.
(class-slots CLASS)Returns the list of all slots of
CLASSand its superclasses as a list of lists, where each sublist contains the name of the slot.
(generic-methods GENERIC)Returns the list of all methods associated with the generic function
GENERIC.
(method-specializers METHOD)Returns the list of classes that specialize
METHOD.
(method-procedure METHOD)Returns the procedure that contains the body of
METHOD.
(subclass? CLASS1 CLASS2)Returns
#tisCLASS1is a subclass ofCLASS2, or#fotherwise. Note that the following holds:(subclass? X X) ==> #t