Copyright © 1990, 1991, 1992, 1993, 1994, 1995 Aubrey Jaffer
Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.
Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.
Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the author.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
1 Copying | ||
2 Overview | Whats here and how to start using it. | |
3 Installing SCM | ||
4 Standard Facilities | ||
5 Packages | Optional Capabilities | |
6 Guile Facilities | Brave new World | |
7 Internals | How it works | |
Procedure and Macro Index | ||
Variable Index | ||
Type Index |
COPYRIGHT (c) 1989 BY
PARADIGM ASSOCIATES INCORPORATED, CAMBRIDGE, MASSACHUSETTS.
ALL RIGHTS RESERVED
Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Paradigm Associates Inc not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission.
PARADIGM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL PARADIGM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
gjc@paradigm.com
Phone: 617-492-6079
Paradigm Associates Inc 29 Putnam Ave, Suite 6 Cambridge, MA 02138
Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995
Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation.
NO WARRANTY
BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Scm is a portable Scheme implementation written in C. Scm provides a machine independent platform for [JACAL], a symbolic algebra system.
2.1 Features | ||
2.2 Authors | ||
2.3 Bibliography | ||
2.4 Invoking SCM | ||
2.5 Options | ||
2.6 Environment Variables | ||
2.8 Examples | ||
2.9 SCM Session |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
logand
, logor
, logxor
,
lognot
, ash
, logcount
, integer-length
,
bit-extract
, defmacro
, macroexpand
,
macroexpand1
, gentemp
, defvar
, force-output
,
software-type
, get-decoded-time
,
get-internal-run-time
, get-internal-real-time
,
delete-file
, rename-file
, copy-tree
, acons
,
and eval
.
Char-code-limit
, most-positive-fixnum
,
most-negative-fixnum
, and internal-time-units-per-second
constants. *Features*
and *load-pathname*
variables.
verbose
function).
Restart
, quit
, and exec
.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Most of SCM.
Arrays. gsubr
s, compiled closures, and records.
Real and Complex functions. Fast mixed type arithmetics.
Syntax checking and memoization of special forms by evaluator. Storage allocation strategy and parameters.
Siod, written by George Carrette, was the starting point for SCM. The major innovations taken from Siod are the evaluator’s use of the C-stack and being able to garbage collect off the C-stack (see section Garbage Collection).
There are many other contributors to SCM. They are acknowledged in the file ‘ChangeLog’, a log of changes that have been made to scm.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
IEEE Standard 1178-1990. IEEE Standard for the Scheme Programming Language. IEEE, New York, 1991.
Brian Harvey and Matthew Wright. Simply Scheme: Introducing Computer Science MIT Press, 1994 ISBN 0-262-08226-8
Harold Abelson and Gerald Jay Sussman with Julie Sussman. Structure and Interpretation of Computer Programs. MIT Press, Cambridge, 1985.
William Clinger and Jonathan Rees, Editors. <A HREF="r4rs_toc.html"> Revised(4) Report on the Algorithmic Language Scheme. </A> In ACM Lisp Pointers IV (July-September 1991).
Todd R. Eigenschink, Dave Love, and Aubrey Jaffer. <A HREF="slib_toc.html"> SLIB, The Portable Scheme Library. </A> Edition 2.01, for SLIB version 2a2, January 1995.
Aubrey Jaffer. <A HREF="jacal_toc.html"> JACAL Symbolic Mathematics System. </A> Version 1a5, April 1994.
Documentation of scm
extensions (beyond Scheme standards).
Documentation on the internal representation and how to extend or
include scm
in other programs.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
scm [-a kbytes] [-ibvqmu] [-p number] [-c expression] [-e expression] [-f filename] [-l filename] [-r feature] [– | - | -s] [filename] [arguments …]
Upon startup scm
loads the file specified by by the environment
variable SCM_INIT_PATH or by the parameter IMPLINIT in the
makefile (or ‘scmfig.h’) if SCM_INIT_PATH is not defined. The
makefiles attempt to set IMPLINIT to ‘Init.scm’ in the source
directory.
Unless the option -no-init-file
occurs in the command line,
‘Init.scm’ checks to see if there is file ‘ScmInit.scm’ in the
path specified by the environment variable HOME (or in the current
directory if HOME is undefined). If it finds such a file it is
loaded.
‘Init.scm’ then looks for command input from one of three sources: From an option on the command line, from a file named on the command line, or from standard input.
This explanation applies to SCMLIT or other builds of SCM. GUILE is invoked similarly to SCM. Guile’s startup script is ‘Ginit.scm’ rather than ‘Init.scm’.
Scheme-code files can also invoke SCM and its variants. See section #!.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The options are processed in the order specified on the command line.
specifies that scm
should allocate an initial heapsize of
kbytes. This option, if present, must be the first on the command
line.
Inhibits the loading of ‘ScmInit.scm’ as described above.
specifies that the scheme expression expression is to be
evaluated. These options are inspired by perl
and sh
respectively. On Amiga systems the entire option and argument need to be
enclosed in quotes. For instance ‘"-e(newline)"’.
requires feature. This will load a file from [SLIB] if that
feature is not already supported. If feature is 2, 3, 4, or
5 scm
will require the features neccessary to support [R2RS],
[R3RS], [R4RS], or proposed [R5RS], respectively.
loads filename. Scm
will load the first (unoptioned) file
named on the command line if no -c
, -e
, -f
,
-l
, or -s
option preceeds
it.
sets the prolixity (verboseness) to level. This is the same as
the scm
command (verobse level).
(verbose mode) specifies that scm
will print prompts, evaluation
times, notice of loading files, and garbage collection statistics. This
is the same as -p3
.
(quiet mode) specifies that scm
will print no extra
information. This is the same as -p0
.
specifies that subsequent loads, evaluations, and user interactions will
be with [R4RS] macro capability. To use a specific [R4RS] macro
implementation from [SLIB] (instead of [SLIB]’s default) put -r
macropackage before -m
on the command line.
specifies that subsequent loads, evaluations, and user interactions will
be without [R4RS] macro capability. [R4RS] macro capability can
be restored by a subsequent -m
on the command line or from Scheme
code.
specifies that scm
should run interactively. That means that
scm
will not terminate until the (quit)
or (exit)
command is given, even if there are errors. It also sets the prolixity
level to 2 if it is less than 2. This will print prompts, evaluation
times, and notice of loading files. The prolixity level can be set by
subsequent options. If scm
is started from a tty, it will assume
that it should be interactive unless given a subsequent -b
option.
specifies that scm
should run non-interactively. That means that
scm
will terminate after processing the command line or if there
are errors.
specifies, by analogy with sh
, that further options are to be
treated as program aguments.
specifies that there are no more options on the command line.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
is the pathname where scm
will look for its initialization
code. The default is the file ‘Init.scm’ in the source directory.
is the [SLIB] Scheme library directory.
is the directory where ‘Init.scm’ will look for the user initialization file ‘ScmInit.scm’.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
contains the list of arguments to the program. *argv*
can change
during argument processing. This list is suitable for use as an argument
to [SLIB] getopt
.
controls whether loading and interaction support [R4RS] macros. Define
this in ‘ScmInit.scm’ or files specified on the command line. This
can be overridden by subsequent -m
and -u
options.
controls interactivity as explained for the -i
and -b
options. Define this in ‘ScmInit.scm’ or files specified on the
command line. This can be overridden by subsequent -i
and
-b
options.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
% scm foo.scm
Loads and executes the contents of ‘foo.scm’ and then enters interactive session.
% scm -f foo.scm arg1 arg2 arg3
Parameters arg1
, arg2
, and arg3
are stored in the
global list *argv*
; Loads and executes the contents of
‘foo.scm’ and exits.
% scm -s foo.scm arg1 arg2
Sets *argv* to ("foo.scm" "arg1" "arg2")
and enters interactive
session.
% scm -e `(write (list-ref *argv* *optind*))' bar
Prints ‘"bar"’.
% scm -rpretty-print -r format -i
Loads pretty-print
and format
and enters interactive
session.
% scm -r5
Loads dynamic-wind
, values
, and [R4RS] macros and enters
interactive (with macros) session.
% scm -r5 -r4
Like above but rev4-optional-procedures
are also loaded.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
3.1 SLIB | ||
3.2 Problems Compiling | ||
3.3 Problems Linking | ||
3.4 Problems Running | ||
3.5 Testing | ||
3.6 Reporting Problems |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
[SLIB] is a portable Scheme library meant to provide compatibility and utility functions for all standard Scheme implementations.
Although SLIB is not neccessary to run SCM, I strongly suggest you obtain and install it. Bug reports about running SCM without SLIB have very low priority. SLIB is available from the same sites as SCM:
<A HREF="file://ftp-swiss.ai.mit.edu/pub/scm/slib2a2.tar.gz"> ftp-swiss.ai.mit.edu:pub/scm/slib2a2.tar.gz </A> <A HREF="file://prep.ai.mit.edu/pub/gnu/jacal/slib2a2.tar.gz"> prep.ai.mit.edu:pub/gnu/jacal/slib2a2.tar.gz </A> <A HREF="file://ftp.maths.tcd.ie/pub/bosullvn/jacal/slib2a2.tar.gz"> ftp.maths.tcd.ie:pub/bosullvn/jacal/slib2a2.tar.gz </A> <A HREF="file://ftp.cs.indiana.edu/pub/scheme-repository/code/lib/slib2a2.tar.gz"> ftp.cs.indiana.edu:/pub/scheme-repository/code/lib/slib2a2.tar.gz </A>
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
HOW TO FIX
Correct the status of STDC_HEADERS in ‘scmfig.h’
fix #include statement or add #define for system type to ‘scmfig.h’.
Ignore.
change SIGRETTYPE in ‘scm.c’.
incompatablility between <stdlib.h> and <sys/types.h>. remove STDC_HEADERS in ‘scmfig.h’.
edit <sys/types.h> to remove incompatability.
Ignore.
ignore
#undef STDC_HEADERS in ‘scmfig.h’.
#define SYSTNAME to your system type in ‘scl.c’ (softtype)
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
HOW TO FIX
uncomment LIBS in makefile
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
HOW TO FIX
Change memory model option to C compiler (or makefile).
Make sure sizet
definition is correct in ‘scmfig.h’.
Reduce size of HEAP_SEG_SIZE in ‘setjump.h’.
#define NOSETBUF
Need to increase the initial heap allocation using -a<kbytes> or INIT_HEAP_SIZE.
Check sizet
definition.
Use 32 bit compiler mode.
Don’t try to run as subproccess
Do it and recompile files.
Assign correct IMPLINIT in makefile or ‘scmfig.h’ or define
environment variable SCM_INIT_PATH
to be the full pathname of
‘Init.scm’ (see section Installing SCM).
define environment variable SCHEME_LIBRARY_PATH
to be the full
pathname of the scheme library [SLIB] or change library-vicinity
in
‘Init.scm’ to point to library or remove. See Installation in SLIB.
Make sure the value of (library-vicinity)
has a trailing file
separator (like </> or <\>).
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Loading ‘test.scm’ in the distribution will run an [R4RS]
conformance test on scm
.
> (load "test.scm") -| ;loading "test.scm" SECTION(2 1) SECTION(3 4) #<primitive-procedure boolean?> #<primitive-procedure char?> #<primitive-procedure null?> #<primitive-procedure number?> …
Loading ‘pi.scm’ in the distribution will enable you to compute digits of pi.
> (load "pi") ;loading "pi" ;done loading "pi.scm" ;Evaluation took 20 mSec (0 in gc) 767 cells work, 233 bytes other #<unspecified> > (pi 100 5) 00003 14159 26535 89793 23846 26433 83279 50288 41971 69399 37510 58209 74944 59230 78164 06286 20899 86280 34825 34211 70679 ;Evaluation took 550 mSec (60 in gc) 36976 cells work, 1548 bytes other #<unspecified>
HOW TO FIX
See above under machine crashes.
Remove optimization option to C compiler and recompile.
#define SHORT_ALIGN
in ‘scmfig.h’.
Change memory model option to C compiler (or makefile).
Check that HEAP_SEG_SIZE
fits within sizet
.
Increase size of HEAP_SEG_SIZE
(or INIT_HEAP_SIZE
if it is
smaller than HEAP_SEG_SIZE
).
See above under machine crashes.
Check file mode (define OPEN_… in ‘Init.scm’
Check character defines in ‘scmfig.h’.
Check SRS in ‘scmfig.h’.
#define CHEAP_CONTIUATIONS
in ‘scmfig.h’.
You are experiencing a GC problem peculiar to the Sparc. The problem is that SCM doesn’t know how to clear register windows. Every location which is not reused still gets marked at GC time. This causes lots of stuff which should be collected to not be. This will be a problem with any conservative GC until we find what instruction will clear the register windows. This problem is exacerbated by using lots of call-with-current-continuations.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Reported problems and solutions are grouped under Compiling, Linking,
Running, and Testing. If you don’t find your problem listed there, you
can send a bug report to jaffer@ai.mit.edu
or
bug-scm@scrg.cs.tcd.ie
. The bug report should include:
SCM_INIT_PATH
and
SCHEME_LIBRARY_PATH
.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
4.1 Standards Compliance | Links to sections in [R4RS] and [SLIB] | |
4.2 System Interface | Like how to exit | |
4.3 Internal State | GC, errors, and diagnostics | |
4.4 Miscellaneous Procedures | ||
4.5 Time | Both real time and processor time | |
4.6 Interrupts | and exceptions | |
4.7 Process Synchronization | Because interrupts are preemptive | |
4.8 Files and Ports | ||
4.9 Soft Ports | Emulate I/O devices | |
4.10 Syntax Extensions | and how to Define New Syntax | |
4.11 Low Level Syntactic Hooks |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Scm conforms to the [IEEE], IEEE Standard 1178-1990. IEEE Standard for the Scheme Programming Language. and [R4RS], <A HREF="r4rs_toc.html"> Revised(4) Report on the Algorithmic Language Scheme. </A> All the required features of these specifications are supported. Many of the optional features are supported as well.
if
: (if <test> <consequent>)
See Conditionals in Revised(4) Scheme.
let*
let
See Binding constructs in Revised(4) Scheme.
do
See Iteration in Revised(4) Scheme.
define
See Definitions in Revised(4) Scheme.
list-tail
See Pairs and lists in Revised(4) Scheme.
string-copy
string-fill!
See Strings in Revised(4) Scheme.
make-vector
of two argumentsvector-fill!
See Vectors in Revised(4) Scheme.
apply
of more than 2 argumentsSee Control features in Revised(4) Scheme.
-
and /
of more than 2 argumentsexp
log
sin
cos
tan
asin
acos
atan
sqrt
expt
make-rectangular
make-polar
real-part
imag-part
magnitude
angle
exact->inexact
inexact->exact
See Numerical operations in Revised(4) Scheme.
delay
force
See Control features in Revised(4) Scheme.
with-input-from-file
with-output-to-file
See Ports in Revised(4) Scheme.
char-ready?
See Input in Revised(4) Scheme.
transcript-on
transcript-off
See System interface in Revised(4) Scheme.
numerator
denominator
rationalize
See Numerical operations in Revised(4) Scheme.
See Macros in Revised(4) Scheme.
delay
full-continuation
ieee-p1178
object-hash
rev4-report
source
See SLIB file ‘Template.scm’.
current-time
See Time in SLIB.
defmacro
See Defmacro in SLIB.
dynamic-wind
See Dynamic-Wind in SLIB.
eval
See System in SLIB.
getenv
system
See System Interface in SLIB.
hash
See Hashing in SLIB.
logical
See Bit-Twiddling in SLIB.
multiarg-apply
See Multi-argument Apply in SLIB.
multiarg/and-
See Multi-argument / and - in SLIB.
rev4-optional-procedures
See Rev4 Optional Procedures in SLIB.
string-port
See String Ports in SLIB.
tmpnam
See Input/Output in SLIB.
transcript
See Transcripts in SLIB.
vicinity
See Vicinity in SLIB.
with-file
See With-File in SLIB.
array
See Arrays in SLIB.
array-for-each
See Array Mapping in SLIB.
bignum
complex
inexact
rational
real
See Require in SLIB.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
For documentation of the procedures getenv
and system
See System Interface in SLIB.
Aliases for exit
(see exit in SLIB). On many
systems, SCM can also tail-call another program. See section execp.
If SCM is compiled under VMS these commands will invoke the editor or debugger respectively.
If SCM is compiled under VMS ed
will invoke the editor with a
single the single argument filename.
Otherwise, the value of the environment variable EDITOR
(or just
ed
if it isn’t defined) is invoked as a command with arguments
arg1 ….
Returns a list of strings of the arguments scm was called with.
With no argument returns the current value of the system variable
errno
. When given an argument, errno
sets the system
variable errno
to n and returns the previous value of
errno
. (errno 0)
will clear outstanding errors. This is
recommended after try-load
returns #f
since this occurs
when the file could not be opened.
Prints on standard error output the argument string, a colon,
followed by a space, the error message corresponding to the current
value of errno
and a newline. The value returned is unspecified.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If SCM encounters a non-fatal error it aborts evaluation of the current
form, prints a message explaining the error, and resumes the top level
read-eval-print loop. The value of errobj is the offending object
if appropriate. errobj is not set from calls to the
procedure error
.
Alias for error in SLIB. Outputs an error message containing the arguments, aborts evaluation of the current form and resumes the top level read-eval-print loop. Error is defined in ‘Init.scm’; You change it to suit you.
Resumes the top level Read-Eval-Print loop.
Controls how much monitoring information is printed. If n is:
no prompt or information is printed.
a prompt is printed.
the CPU time is printed after each top level form evaluated.
messages about heap growth are printed.
garbage collection (see section Garbage Collection) messages are printed.
a warning will be printed for each top-level symbol which is defined more than one time.
Scans all of SCM objects and reclaims for further use those that are no longer accessible.
Prints out statistics about SCM’s current use of storage. (room #t)
also gives the hexadecimal heap segment and stack bounds.
Contains the version string (e.g. ‘4e2’) of SCM.
For other configuration constants and procedures See Configuration in SLIB.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If the string filename names an existing file, the try-load
procedure reads Scheme source code expressions and definitions from the
file and evaluates them sequentially and returns #t
. If not,
try-load returns #f
. The try-load procedure does not affect the
values returned by current-input-port
and
current-output-port
.
Is set to the pathname given as argument to load
,
try-load
, and dyn:link
(see section Compiling And Linking).
*load-pathname*
is used to compute the value of program-vicinity in SLIB.
Returns the current line number of the file currently being loaded.
Alias for eval in SLIB.
Returns the result of reading an expression from str and
evaluating it. eval-string
does not change
*load-pathname*
or line-number
.
Reads and evaluates all the expressions from str. As with
load
, the value returned is unspecified. eval-string
does
not change *load-pathname*
or line-number
.
Change the length of string, vector, bit-vector, or uniform-array object to length. If this shortens object then the remaining contents are lost. If it enlarges object then the contents of the extended part are undefined but the original part is unchanged. It is an error to change the length of literal datums. The new object is returned.
See copy-tree in SLIB. This extends the SLIB version by also copying vectors.
Returns (cons (cons obj1 obj2) obj3). The expression (set! a-list (acons key datum a-list)) adds a new association to a-list.
This command displays the GNU General Public License.
Displays the text contents of filename.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Is the integer number of internal time units in a second.
Returns the integer run time in internal time units from an unspecified
starting time. The difference of two calls to
get-internal-run-time
divided by
internal-time-units-per-second
will give elapsed run time in
seconds.
Returns the integer time in internal time units from an unspecified
starting time. The difference of two calls to
get-internal-real-time
divided by
interal-time-units-per-second
will give elapsed real time in
seconds.
Returns the time since 00:00:00 GMT, January 1, 1970, measured in
seconds. See current-time in SLIB. current-time
is
used in Time in SLIB.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Returns the number of ticks remaining till the next tick interrupt. Ticks are an arbitrary unit of evaluation. Ticks can vary greatly in the amount of time they represent.
If n is 0, any ticks request is canceled. Otherwise a
ticks-interrupt
will be signaled n from the current time.
ticks
is supported if SCM is compiled with the ticks
flag
defined.
Establishes a response for tick interrupts. Another tick interrupt will
not occur unless ticks
is called again. Program execution will
resume if the handler returns. This procedure should (abort) or some
other action which does not return if it does not want processing to
continue.
Returns the number of seconds remaining till the next alarm interrupt.
If secs is 0, any alarm request is canceled. Otherwise an
alarm-interrupt
will be signaled secs from the current
time. ALARM is not supported on all systems.
Establishes a response for SIGINT
(control-C interrupt) and
SIGALRM
interrupts. Program execution will resume if the handler
returns. This procedure should (abort)
or some other action
which does not return if it does not want processing to continue after
it returns.
Interrupt handlers are disabled during execution system
and
ed
procedures.
To unestablish a response for an interrupt set the handler symbol to
#f
. For instance, (set! user-interrupt #f)
.
Establishes a response for storage allocation error, file opening error, end of program, SIGHUP (hang up interrupt) and arithmetic errors respectively. This procedure should (abort) or some other action which does not return if it does not want the default error message to also be displayed. If no procedure is defined for hang-up then end-of-program (if defined) will be called.
To unestablish a response for an error set the handler symbol to
#f
. For instance, (set! could-not-open #f)
.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Returns an object of type arbiter and name name. Its state is initially unlocked.
Returns #t
and locks arbiter if arbiter was unlocked.
Otherwise, returns #f
.
Returns #t
and unlocks arbiter if arbiter was locked.
Otherwise, returns #f
.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These procedures generalize and extend the standard capabilities in Ports in Revised(4) Scheme.
Returns a port capable of receiving or delivering characters as
specified by the modes string. If a file cannot be opened
#f
is returned.
Contain modes strings specifying that a file is to be opened for reading, writing, and both reading and writing respectively.
Returns a version of modestr which when open-file is called with it as the second argument will return an unbuffered port. A non-file input-port must be unbuffered in order for char-ready? to work correctly on it. The initial value of (current-input-port) is unbuffered if the platform supports it.
Closes port. The same as close-input-port and close-output-port.
These functions are analogous to the standard scheme file functions. The ports are open to filename in read/write mode. Both input and output functions can be used with io-ports. An end of file must be read or a file-set-position done on the port between a read operation and a write operation or vice-versa.
Returns the current port to which diagnostic output is directed.
thunk must be a procedure of no arguments, and string must be a string naming a file. The file is opened for output, an output port connected to it is made the default value returned by current-error-port, and the thunk is called with no arguments. When the thunk returns, the port is closed and the previous default is restored. With-error-to-file returns the value yielded by thunk.
These routines differ from with-input-from-file, with-output-to-file, and with-error-to-file in that the first argument is a port, rather than a string naming a file.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A soft-port is a port based on a vector of procedures capable of accepting or delivering characters. It allows emulation of I/O ports.
Returns a port capable of receiving or delivering characters as specified by the modes string (see section open-file). vector must be a vector of length 6. Its components are as follows:
For an output-only port only elements 0, 1, 2, and 4 need be
procedures. For an input-only port only elements 3 and 4 need be
procedures. Thunks 2 and 4 can instead be #f
if there is no useful
operation for them to perform.
If thunk 3 returns #f
or an eof-object
(see eof-object? in Revised(4) Scheme) it indicates that the port has
reached end-of-file. For example:
(define stdout (current-output-port)) (define p (make-soft-port (vector (lambda (c) (write c stdout)) (lambda (s) (display s stdout)) (lambda () (display "." stdout)) (lambda () (char-upcase (read-char))) (lambda () (display "@" stdout))) "rw")) (write p p) ⇒ #<input-output-soft#\space45d10#\>
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Is read as the object resulting from the evaluation of expression. This substitution occurs even inside quoted structure.
In order to allow compiled code to work with #.
it is good
practice to define those symbols used inside of expression with
#.(define …)
. For example:
#.(define foo 9) ⇒ #<unspecified> '(#.foo #.(+ foo foo)) ⇒ (9 18)
If feature is provided?
(by *features*
) then form is
read as a scheme expression. If not, then form is treated as
whitespace.
Feature is a boolean expression composed of symbols and and
,
or
, and not
of boolean expressions.
For more information on provided?
and *features*
,
See Require in SLIB.
is equivalent to #+(not feature) expression
.
is equivalent to form (for compatibility with common-lisp).
Is a balanced comment. Everything up to the matching |#
is
ignored by the read
. Nested #|…|#
can occur inside
any thing.
On the first line of a file will be ignored when loaded by SCM. This makes SCM files usable as POSIX shell scripts if the first line is:
#!/usr/local/bin/scm
When such a file is invoked it executes /usr/local/bin/scm with the name of this file as the first argument. The following shell script will print factorial of its argument:
#!/usr/local/bin/scm ;;; -*-scheme-*- tells emacs this is a scheme file. (define (fact n) (if (< n 2) 1 (* n (fact (+ -1 n))))) (display (fact (string->number (caddr (program-arguments))))) (newline) (quit)
This technique has some drawbacks:
The following approach solves both problems – at the expense of
slightly slower startup. type;
should appear on every line to be
executed by the shell. These lines do not have the length restriction
mentioned above. Also, /bin/sh
searches the directories listed
in the ‘PATH’ environment variable for ‘scm’, eliminating the need
to know absolute locations in order to invoke a program.
#!/bin/sh type;exec scm $0 $* ;;; -*-scheme-*- tells emacs this is a scheme file. (define (fact n) (if (< n 2) 1 (* n (fact (+ -1 n))))) (display (fact (string->number (caddr (program-arguments))))) (newline) (quit)
Equivalent to #t
if symbol is a syntactic keyword (such as
if
) or a symbol with a value in the top level environment
(see Variables and regions in Revised(4) Scheme). Otherwise
equivalent to #f
.
If identifier is unbound in the top level environment, then
identifier is define
d to the result of evaluating the form
initial-value as if the defvar
form were instead the form
(define identifier initial-value)
. If identifier already
has a value, then initial-value is not evaluated and
identifier’s value is not changed.
SCM also supports the following constructs from Common Lisp:
defmacro
, macroexpand
, macroexpand-1
, and
gentemp
. See Defmacro in SLIB.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If a <#> followed by a character (for a non-standard syntax) is
encountered by read
, read
will call the value of the
symbol read:sharp
with arguments the character and the port being
read from. The value returned by this function will be the value of
read
for this expression unless the function returns
#<unspecified>
in which case the expression will be treated as
whitespace. #<unspecified>
is the value returned by the
expression (if #f #f)
.
Note: When adding new <#> syntaxes, have your code save the
previous value of read:sharp
when defining it. Call this saved
value if an invocation’s syntax is not recognized. This will allow
#+
, #-
, #!
, and Uniform Arrays to still be
supported (as they use read:sharp
).
Returns a macro which, when a symbol defined to this value appears as the first symbol in an expression, returns the result of applying proc to the expression and the environment.
Returns a macro which, when a symbol defined to this value appears
as the first symbol in an expression, evaluates the result of applying
proc to the expression and the environment. The value returned
from proc which has been passed to
PROCEDURE->MEMOIZING-MACRO
replaces the form passed to
proc. For example:
(define trace (procedure->macro (lambda (x env) `(set! ,(cadr x) (tracef ,(cadr x) ',(cadr x)))))) (trace foo) ≡ (set! foo (tracef foo 'foo)).
An environment is a list of environment frames. There are 2 types of environment frames:
((lambda (variable1 …) …) value1 …)
(let ((variable1 value1) (variable2 value2) …) …)
(letrec ((variable1 value1) …) …)
result in a single enviroment frame:
((variable1 …) value1 …)
(let ((variable1 value1)) …)
(let* ((variable1 value1) …) …)
result in an environment frame for each variable:
(variable1 . value1) (variable2 . value2) …
Returns the result of applying procedure to argument-list. (apply procedure argument-list) will produce the same result.
Returns the result of applying procedure to the current continuation.
(call-with-current-continuation procedure)
will have the
same effect.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
5.1 Compiling And Linking | and Dynamic Linking | |
5.2 Numeric | ||
5.3 Arrays | As in APL | |
5.4 I/O-Extensions | ’i/o-extensions | |
5.5 Posix Extensions | ||
5.7 Regular Expression Pattern Matching | ’regex | |
5.8 Line Editing | ||
5.9 Curses | Screen Control | |
5.10 Sockets | Cruise the Net |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If the HOBBIT compiler is installed in the
(implementation-vicinity)
, compiles the files name1
name2 … to an object file name name1<object-suffix>,
where <object-suffix> is the object file suffix for your computer (for
instance, ‘.o’). name1 must be in the current directory.
name2 … can be in other directories.
Creates a new SCM executable with name name. name will include the object modules module1 … which can be produced with compile-file.
If SCM has been compiled with ‘dynl.c’ then the additional
properties of load and require (from [SLIB]) specified below are
supported. The require
forms are preferred. The variable
*catalog*
can be extended to define other requirable packages.
See ‘Link.scm’ for details.
In addition to the [R4RS] requirement of loading Scheme expressions if
filename is a Scheme source file, load
will also
dynamically load/link object files (produced by compile-file
, for
instance). The object-suffix need not be given to load. For example,
(load (in-vicinity (implementation-vicinity) "sc2")) or (load (in-vicinity (implementation-vicinity) "sc2.o")) or (require 'rev2-procedures) or (require 'rev3-procedures)
will load/link ‘sc2.o’ if it exists.
The lib1 … pathnames are for additional libraries which may be needed for object files not produced by the Hobbit compiler. For instance, crs is linked on Linux by
(load (in-vicinity (implementation-vicinity) "crs.o") (usr:lib "ncurses") (usr:lib "c")) or (require 'curses)
Turtlegr graphics library is linked by:
(load (in-vicinity (implementation-vicinity) "turtlegr") (usr:lib "X11") (usr:lib "c") (usr:lib "m")) or (require 'turtle-graphics)
And the string regular expression (see section Regular Expression Pattern Matching) package is linked by:
(load (in-vicinity (implementation-vicinity) "rgx") (usr:lib "c"))
or
(require 'regex)
Either form will dynamically load the WB database system from the wb:vicinity (‘../wb/’) specified in ‘Link.scm’. See ‘scm/ANNOUNCE’ for ftp sites where WB is available.
The following functions comprise the low-level Scheme interface to dynamic linking. See the file ‘Link.scm’ in the SCM distribution for an example of their use.
filename should be a string naming an object or
archive file, the result of C-compiling. The dyn:link
procedure links and loads filename into the current SCM session.
If successfull, dyn:link
returns a link-token suitable for
passing as the second argument to dyn:call
. If not successful,
#f
is returned.
link-token should be the value returned by a call to
dyn:link
. name should be the name of C function of no
arguments defined in the file named filename which was succesfully
dyn:link
ed in the current SCM session. The dyn:call
procedure calls the C function corresponding to name. If
successful, dyn:call
returns #t
; If not successful,
#f
is returned.
dyn:call
is used to call the init_… function after
loading SCM object files. The init_… function then makes the
identifiers defined in the file accessible as Scheme procedures.
link-token should be the value returned by a call to
dyn:link
. The dyn:unlink
procedure removes the previously
loaded file from the current SCM session. If successful,
dyn:unlink
returns #t
; If not successful, #f
is
returned.
Returns the pathname of the C library named lib. For example:
(usr:lib "m")
could return "/usr/lib/libm.a"
, the path of
the C math library.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The immediate integer closest to positive infinity. See Configuration in SLIB.
The immediate integer closest to negative infinity.
These procedures augment the standard capabilities in Numerical operations in Revised(4) Scheme.
Return the hyperbolic sine, cosine, and tangent of z
Return the inverse hyperbolic sine, cosine, and tangent of z
Real-only versions of these popular functions. The argument x must be a real number. It is an error if the value which should be returned by a call to these procedures is not real.
Computes (angle (make-rectangular x y))
for real numbers y
and x.
Returns real number x1 raised to the real power x2. It is
an error if the value which should be returned by a call to $expt
is not real.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
5.3.1 Conventional Arrays | ||
5.3.2 Array Mapping | ||
5.3.3 Uniform Array | ||
5.3.4 Bit Vectors |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Arrays read and write as a #
followed by the rank
(number of dimensions) followed by what appear as lists (of lists) of
elements. The lists must be nested to the depth of the rank. For each
depth, all lists must be the same length.
(make-array 'ho 3 3) ⇒ #2((ho ho ho) (ho ho ho) (ho ho ho))
Unshared conventional (not uniform) 0-based arrays of rank 1 (dimension) are equivalent to (and can’t be distinguished from) vectors.
(make-array 'ho 3) ⇒ (ho ho ho)
When constructing an array, bound is either an inclusive range of indices expressed as a two element list, or an upper bound expressed as a single integer. So
(make-array 'foo 3 3) ≡ (make-array 'foo '(0 2) '(0 2))
Returns #t
if the obj is an array, and #f
if not.
Creates and returns an array that has as many dimensions as there are bounds and fills it with initial-value.
Returns the element at the (index1, index2)
element in array.
Returns #t
if its arguments would be acceptable to array-ref.
Sets the element at the (index1, index2)
element in array to
new-value. The value returned by array-set! is unspecified.
make-shared-array
can be used to create shared subarrays of other
arrays. The mapper is a function that translates coordinates in
the new array into coordinates in the old array. A mapper must be
linear, and its range must stay within the bounds of the old array, but
it can be otherwise arbitrary. A simple example:
(define fred (make-array #f 8 8)) (define freds-diagonal (make-shared-array fred (lambda (i) (list i i)) 8)) (array-set! freds-diagonal 'foo 3) (array-ref fred 3 3) ⇒ foo (define freds-center (make-shared-array fred (lambda (i j) (list (+ 3 i) (+ 3 j))) 2 2)) (array-ref freds-center 0 0) ⇒ foo
Returns an array sharing contents with array, but with dimensions arranged in a different order. There must be one dim argument for each dimension of array. dim0, dim1, … should be integers between 0 and the rank of the array to be returned. Each integer in that range must appear at least once in the argument list.
The values of dim0, dim1, … correspond to dimensions in the array to be returned, their positions in the argument list to dimensions of array. Several dims may have the same value, in which case the returned array will have smaller rank than array.
examples:
(transpose-array '#2((a b) (c d)) 1 0) ⇒ #2((a c) (b d)) (transpose-array '#2((a b) (c d)) 0 0) ⇒ #1(a d) (transpose-array '#3(((a b c) (d e f)) ((1 2 3) (4 5 6))) 1 1 0) ⇒ #2((a 4) (b 5) (c 6))
dim0, dim1 … should be nonnegative integers less than the rank of array. enclose-array returns an array resembling an array of shared arrays. The dimensions of each shared array are the same as the dimth dimensions of the original array, the dimensions of the outer array are the same as those of the original array that did not match a dim.
An enclosed array is not a general Scheme array. Its elements may not
be set using array-set!
. Two references to the same element of
an enclosed array will be equal?
but will not in general be
eq?
. The value returned by array-prototype when given an
enclosed array is unspecified.
examples:
(enclose-array '#3(((a b c) (d e f)) ((1 2 3) (4 5 6))) 1) ⇒ #<enclosed-array (#1(a d) #1(b e) #1(c f)) (#1(1 4) #1(2 5) #1(3 6))> (enclose-array '#3(((a b c) (d e f)) ((1 2 3) (4 5 6))) 1 0) ⇒ #<enclosed-array #2((a 1) (d 4)) #2((b 2) (e 5)) #2((c 3) (f 6))>
Returns a list of inclusive bounds of integers.
(array-shape (make-array 'foo '(-1 3) 5)) ⇒ ((-1 3) (0 4))
Array-dimensions
is similar to array-shape
but replaces
elements with a 0
minimum with one greater than the maximum. So:
(array-dimensions (make-array 'foo '(-1 3) 5)) ⇒ ((-1 3) 5)
Returns the number of dimensions of obj. If obj is not an
array, 0
is returned.
Returns a list consisting of all the elements, in order, of array.
Copies every element from vector or array source to the corresponding element of destination. destination must have the same rank as source, and be at least as large in each dimension. The order is unspecified.
Same as array-copy!
but guaranteed to copy in row-major order.
Stores fill in every element of array. The value returned is unspecified.
Returns #t
iff all arguments are arrays with the same shape, the
same type, and have corresponding elements which are either
equal?
or array-equal?
. This function differs from
equal?
in that a one dimensional shared array may be
array-equal? but not equal? to a vector or uniform vector.
If array may be unrolled into a one dimensional shared array
without changing their order (last subscript changing fastest), then
array-contents
returns that shared array, otherwise it returns
#f
. All arrays made by make-array and
make-uniform-array may be unrolled, some arrays made by
make-shared-array may not be.
If the optional argument strict is provided, a shared array will be returned only if its elements are stored internally contiguous in memory.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
array1, … must have the same number of dimensions as array0 and have a range for each index which includes the range for the corresponding index in array0. proc is applied to each tuple of elements of array1 … and the result is stored as the corresponding element in array0. The value returned is unspecified. The order of application is unspecified.
Same as array-map!, but guaranteed to apply proc in row-major order.
proc is applied to each tuple of elements of array0 … in row-major order. The value returned is unspecified.
applies proc to the indices of each element of array in turn, storing the result in the corresponding element. The value returned and the order of application are unspecified.
One can implement array-indexes as
(define (array-indexes array) (let ((ra (apply make-array #f (array-shape array)))) (array-index-map! ra (lambda x x)) ra))
Another example:
(define (apl:index-generator n) (let ((v (make-uniform-vector n 1))) (array-index-map! v (lambda (i) i)) v))
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Uniform Arrays and vectors are arrays whose elements are all of the same type. Uniform vectors occupy less storage than conventional vectors. Uniform Array procedures also work on vectors, uniform-vectors, bit-vectors, and strings.
prototype arguments in the following procedures are interpreted according to the table:
prototype type printing character #t boolean (bit-vector) b #\a char (string) a integer >0 unsigned integer u integer <0 signed integer e 1.0 float (single precision) s 1/3 double (double precision float) i +i complex (double precision) c () conventional vector
Unshared uniform character 0-based arrays of rank 1 (dimension) are equivalent to (and can’t be distinguished from) strings.
(make-uniform-array #\a 3) ⇒ "$q2"
Unshared uniform boolean 0-based arrays of rank 1 (dimension) are equivalent to (and can’t be distinguished from) bit-vectors.
(make-uniform-array #t 3) ⇒ #*000 ≡ #b(#f #f #f) ⇒ #*000 ≡ #1b(#f #f #f) ⇒ #*000
Other uniform vectors are written in a form similar to that of vectors,
except that a single character from the above table is put between
#
and (
. For example, '#e(3 5 9)
returns a uniform
vector of signed integers.
Returns #t
if the obj is an array of type corresponding to
prototype, and #f
if not.
Creates and returns a uniform array of type corresponding to prototype that has as many dimensions as there are bounds and fills it with prototype.
Returns an object that would produce an array of the same type as
array, if used as the prototype for
make-uniform-array
.
Returns a uniform array of the type indicated by prototype prot with elements the same as those of lst. Elements must be of the appropriate type, no coercions are done.
Stores fill in every element of uve. The value returned is unspecified.
Returns the number of elements in uve.
Creates and returns a uniform array or vector of type corresponding to prototype with dimensions dims or length length. If the fill argument is supplied, the returned array is filled with this value.
Attempts to read all elements of ura, in lexicographic order, as binary objects from port. If an end of file is encountered during uniform-array-read! the objects up to that point only are put into ura (starting at the beginning) and the remainder of the array is unchanged.
uniform-array-read!
returns the number of objects read.
port may be omitted, in which case it defaults to the value
returned by (current-input-port)
.
Writes all elements of ura as binary objects to port. The
number of objects actually written is returned. port may be
omitted, in which case it defaults to the value returned by
(current-output-port)
.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Bit vectors can be written and read as a sequence of 0
s and
1
s prefixed by #*
.
#b(#f #f #f #t #f #t #f) ⇒ #*0001010
Some of these operations will eventually be generalized to other uniform-arrays.
Returns the number occurrences of bool in bv.
Returns the minimum index of an occurrence of bool in bv
which is at least k. If no bool occurs within the specified
range #f
is returned.
Modifies bv by replacing each element with its negation.
If uve is a bit-vector bv and uve must be of the same length. If
bool is #t
, uve is OR’ed into bv; If bool is #f
, the
inversion of uve is AND’ed into bv.
If uve is a unsigned integer vector all the elements of uve must be
between 0 and the LENGTH
of bv. The bits of bv
corresponding to the indexes in uve are set to bool.
The return value is unspecified.
Returns
(bit-count (bit-set*! (if bool bv (bit-invert! bv)) uve #t) #t).
bv is not modified.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If 'i/o-extensions
is provided (by linking in ‘ioext.o’),
Line I/O in SLIB, and the following functions are defined:
Returns #t
if port is input or output to a serial non-file device.
Returns a vector of integers describing the argument. The argument
can be either a string or an open input port. If the argument is an
open port then the returned vector describes the file to which the
port is opened; If the argument is a string then the returned vector
describes the file named by that string. If there exists no file with
the name string, or if the file cannot be accessed #f
is returned.
The elements of the returned vector are as follows:
ID of device containing a directory entry for this file
Inode number
File type, attributes, and access control summary
Number of links
User ID of file owner
Group ID of file group
Device ID; this entry defined only for char or blk spec files
File size (bytes)
Time of last access
Last modification time
Last file status change time
Returns the process ID of the current process.
Returns the current position of the character in port which will next be read or written. If port is not open to a file the result is unspecified.
Sets the current position in port which will next be read or
written. If port is not open to a file the action of
file-set-position
is unspecified. The result of
file-set-position
is unspecified.
Closes port port and reopens it with filename and
modes. reopen-file
returns #t
if successful,
#f
if not.
Creates and returns a duplicate port from port. Duplicate unbuffered ports share one file position. modes are as for open-file.
Closes to-port and makes to-port be a duplicate of
from-port. redirect-port!
returns to-port if
successful, #f
if not. If unsuccessful, to-port is not
closed.
Returns a directory object corresponding to the file system
directory named dirname. If unsuccessful, returns #f
.
Returns the string name of the next entry from the directory dir.
If there are no more entries in the directory, readdir
returns a
#f
.
Reinitializes dir so that the next call to readdir
with
dir will return the first entry in the directory again.
Closes dir and returns #t
. If dir is already
closed,, closedir
returns a #f
.
The mkdir
function creates a new, empty directory whose name is
path. The integer argument mode specifies the file
permissions for the new directory. See The Mode Bits for Access Permission in Gnu C Library, for more information about this.
mkdir
returns if successful, #f
if not.
The rmdir
function deletes the directory path. The
directory must be empty before it can be removed. rmdir
returns
if successful, #f
if not.
Changes the current directory to filename. If filename does not
exist or is not a directory, #f
is returned. Otherwise, #t
is
returned.
The function getcwd
returns a string containing the absolute file
name representing the current working directory. If this string cannot
be obtained, #f
is returned.
Renames the file specified by oldfilename to newfilename.
If the renaming is successful, #t
is returned. Otherwise,
#f
is returned.
The function chmod
sets the access permission bits for the file
named by file to mode. The file argument may be a
string containing the filename or a port open to the file.
chmod
returns if successful, #f
if not.
Sets the file times associated with the file named pathname to
have access time acctime and modification time modtime.
utime
returns if successful, #f
if not.
The function umask
sets the file creation mask of the current
process to mask, and returns the previous value of the file
creation mask.
Returns the integer file descriptor associated with the port port.
If an error is detected, #f
is returned.
Returns #t
if the file named by pathname can be accessed in
the way specified by the how argument. The how argument can
be the logior
of the flags:
Transfers control to program command called with arguments
arg0 …. For execl
, command must be an exact
pathname of an executable file. execlp
searches for
command in the list of directories specified by the environment
variable PATH. The convention is that arg0 is the same name
as command.
If successful, this procedure does not return. Otherwise an error
message is printed and the integer errno
is returned.
Like execl
and execlp
except that the set of arguments to
command is arglist.
adds or removes definitions from the environment. If the string is of the form ‘NAME=VALUE’, the definition is added to the environment. Otherwise, the string is interpreted as the name of an environment variable, and any definition for this variable in the environment is removed.
Names of environment variables are case-sensitive and must not contain
the character =
. System-defined environment variables are
invariably uppercase.
Putenv
is used to set up the environment before calls to
execl
, execlp
, execv
, execvp
, system
,
or open-pipe
(see section open-pipe).
To access environment variables, use getenv
(see getenv in SLIB).
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If 'posix
is provided (by linking in ‘posix.o’), the
following functions are defined:
If the string modes contains an <r>, returns an input port
capable of delivering characters from the standard output of the system
command string. Otherwise, returns an output port capable of
receiving characters which become the standard input of the system
command string. If a pipe cannot be created #f
is
returned.
Returns an input port capable of delivering characters from the
standard output of the system command string. If a pipe cannot be
created #f
is returned.
Returns an output port capable of receiving characters which become
the standard input of the system command string. If a pipe cannot
be created #f
is returned.
Closes the pipe, rendering it incapable of delivering or accepting characters. This routine has no effect if the pipe has already been closed. The value returned is unspecified.
Returns (cons rd wd)
where rd and wd are
the read and write (port) ends of a pipe respectively.
Creates a copy of the process calling fork
. Both processes
return from fork
, but the calling (parent) process’s
fork
returns the child process’s ID whereas the child
process’s fork
returns 0.
For a discussion of IDs See Process Persona in libc.
Returns the process ID of the parent of the current process. For a process’s own ID See section getpid.
Returns the real user ID of this process.
Returns the real group ID of this process.
Returns the effective group ID of this process.
Returns the effective user ID of this process.
Sets the real user ID of this process to id.
Returns #t
if successful, #f
if not.
Sets the real group ID of this process to id.
Returns #t
if successful, #f
if not.
Sets the effective group ID of this process to id.
Returns #t
if successful, #f
if not.
Sets the effective user ID of this process to id.
Returns #t
if successful, #f
if not.
The kill
function sends the signal signum to the process or
process group specified by pid. Besides the signals listed in
Standard Signals in GNU C Library, signum can also
have a value of zero to check the validity of the pid.
The pid specifies the process or process group to receive the signal:
The process whose identifier is pid.
All processes in the same process group as the sender. The sender itself does not receive the signal.
If the process is privileged, send the signal to all processes except for some special system processes. Otherwise, send the signal to all processes with the same effective user ID.
The process group whose identifier is (abs pid)
.
A process can send a signal to itself with (kill (getpid)
signum)
. If kill
is used by a process to send a signal to
itself, and the signal is not blocked, then kill
delivers at
least one signal (which might be some other pending unblocked signal
instead of the signal signum) to that process before it returns.
The return value from kill
is zero if the signal can be sent
successfully. Otherwise, no signal is sent, and a value of -1
is
returned. If pid specifies sending a signal to several processes,
kill
succeeds if it can send the signal to at least one of them.
There’s no way you can tell which of the processes got the signal or
whether all of them did.
The waitpid
function suspends execution of the current process
until a child as specified by the pid argument has exited, or until a
signal is deliverd whose action is to terminate the current process or
to call a signal handling function. If a child as requested by pid has
already exited by the time of the call (a so-called zombie
process), the function returns immediately. Any system resources used
by the child are freed.
The value of pid can be one of:
which means to wait for any child process whose process group ID is equal to the absolute value of
which means to wait for any child process whose process group ID is
equal to the (abs pid)
.
which means to wait for any child process; this is the same behaviour which wait exhibits.
which means to wait for any child process whose process group ID is equal to that of the calling process.
which means to wait for the child whose process ID is equal to the value of pid.
The value of options is one of the following:
WNOHANG
) which means to return immediately if no child is there
to be waited for.
WUNTRACED
) which means to also return for children which are
stopped, and whose status has not been reported.
The return value is normally the process ID of the child process whose
status is reported. If the WNOHANG
option was specified and no
child process is waiting to be noticed, the value is zero. A value of
#f
is returned in case of error and errno
is set. For
information about the errno
codes See Process Completion in libc.
You can use the uname
procedure to find out some information
about the type of computer your program is running on.
Returns a vector of strings. These strings are:
Some examples are ‘"i386-ANYTHING"’, ‘"m68k-hp"’, ‘"sparc-sun"’, ‘"m68k-sun"’, ‘"m68k-sony"’ and ‘"mips-dec"’.
Returns a vector of information for the entry for NAME
,
UID
, or the next entry if no argument is given. The
information is:
#f
, in
which case the interpretation is system-dependent.
#f
, indicating that the system default should be used.
Rewinds the pw entry table back to the begining.
Closes the pw table.
Returns a vector of information for the entry for NAME
,
UID
, or the next entry if no argument is given. The
information is:
Rewinds the group entry table back to the begining.
Closes the group table.
Returns a vector of all the supplementary group IDs of the process.
The link
function makes a new link to the existing file named by
oldname, under the new name newname.
link
returns a value of #t
if it is successful and
#f
on failure.
The chown
function changes the owner of the file filename
to owner, and its group owner to group.
chown
returns a value of #t
if it is successful and
#f
on failure.
If port port is associated with a terminal device, returns a
string containing the file name of termainal device; otherwise
#f
.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If 'unix
is provided (by linking in ‘unix.o’), the following
functions are defined:
These priveledged and symbolic link functions are not in Posix:
The symlink
function makes a symbolic link to oldname named
newname.
symlink
returns a value of #t
if it is successful and
#f
on failure.
Returns the value of the symbolic link filename or #f
for
failure.
The lstat
function is like stat
, except that it does not
follow symbolic links. If filename is the name of a symbolic
link, lstat
returns information about the link itself; otherwise,
lstat
works like stat
. See section I/O-Extensions.
Increment the priority of the current process by increment.
chown
returns a value of #t
if it is successful and
#f
on failure.
When called with the name of an exisitng file as argument, accounting is
turned on, records for each terminating pro-cess are appended to
filename as it terminates. An argument of #f
causes
accounting to be turned off.
acct
returns a value of #t
if it is successful and
#f
on failure.
The mknod
function makes a special file with name filename
and modes mode for device number dev.
mknod
returns a value of #t
if it is successful and
#f
on failure.
sync
first commits inodes to buffers, and then buffers to disk.
sync() only schedules the writes, so it may return before the actual
writing is done. The value returned is unspecified.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These functions are defined in ‘rgx.c’ using a POSIX or GNU regex library. If your computer does not support regex, a package is available via ftp from ‘prep.ai.mit.edu:/pub/gnu/regex-0.12.tar.gz’. For a description of regular expressions, See syntax in "regex" regular expression matching library.
Compile a regular expression. Return a compiled regular
expression, or an integer error code suitable as an argument to
regerror
.
flags in regcomp
is a string of option letters used to
control the compilation of the regular expression. The letters may
consist of:
newlines won’t be matched by .
or hat lists; ( [^...]
)
ignore case. only when compiled with _GNU_SOURCE:
allows dot to match a null character.
enable GNU fastmaps.
Returns a string describing the integer errno returned when
regcomp
fails.
Returns #f
or a vector of integers. These integers are in
doublets. The first of each doublet is the index of string of
the start of the matching expression or sub-expression (delimited by
parentheses in the pattern). The last of each doublet is index of
string of the end of that expression. #f
is returned if
the string does not match.
Returns #t
if the pattern such that regexp = (regcomp
pattern) matches string as a POSIX extended regular
expressions. Returns #f
otherwise.
Regsearch
searches for the pattern within the string.
Regmatch
anchors the pattern and begins matching it against
string.
Regsearch
returns the character position where re starts,
or #f
if not found.
Regmatch
returns the number of characters matched, #f
if
not matched.
Regsearchv
and regmatchv
return the match vector is
returned if re is found, #f
otherwise.
may be either:
regcomp
;
The string to be operated upon.
The character position at which to begin the search or match. If absent, the default is zero.
Compiled _GNU_SOURCE and using GNU libregex only:
When searching, if start is negative, the absolute value of start will be used as the start location and reverse searching will be performed.
The search is allowed to examine only the first len characters of string. If absent, the entire string may be examined.
String-split
splits a string into substrings that are separated
by re, returning a vector of substrings.
String-splitv
returns a vector of string positions that indicate
where the substrings are located.
Returns the edited string.
Is a string used to replace occurances of re. Backquoted integers
in the range of 1-9 may be used to insert subexpressions in re, as
in sed
.
The number of substitutions for string-edit
to perform. If
#t
, all occurances of re will be replaced. The default is
to perform one substitution.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These procedures provide input line editing and recall.
These functions are defined in ‘edline.c’ and ‘Iedline.scm’ using the editline or GNU readline libraries available from:
ftp.sys.toronto.edu:/pub/rc/editline.shar
prep.ai.mit.edu:pub/gnu/readline-2.0.tar.gz
When ‘Iedline.scm’ is loaded, if the current input port is the default input port and the environment variable EMACS is not defined, line-editing mode will be entered.
Returns the initial current-input-port
SCM was invoked with
(stdin).
Returns the initial current-output-port
SCM was invoked with
(stdout).
Returns an input/output port that allows command line editing and retrieval of history.
Returns the current edited line port or #f
.
If bool is false, exits line-editing mode and returns the previous
value of (line-editing)
. If bool is true, sets the current
input and output ports to an edited line port and returns the previous
value of (line-editing)
.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These functions are defined in ‘crs.c’ using the curses
library. Unless otherwise noted these routines return #t
for
successful completion and #f
for failure.
Returns a port for a full screen window. This routine must be called to initialize curses.
A program should call endwin
before exiting or escaping from
curses mode temporarily, to do a system call, for example. This routine
will restore termio modes, move the cursor to the lower left corner of
the screen and reset the terminal into the proper non-visual mode. To
resume after a temporary escape, call refresh.
5.9.1 Output Options Setting | ||
5.9.2 Terminal Mode Setting | ||
5.9.3 Window Manipulation | ||
5.9.4 Output | ||
5.9.5 Input | ||
5.9.6 Curses Miscellany |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These routines set options within curses that deal with output. All
options are initially #f
, unless otherwise stated. It is not
necessary to turn these options off before calling endwin
.
If enabled (bf is #t
), the next call to force-output
or refresh
with win will clear the screen completely and
redraw the entire screen from scratch. This is useful when the contents
of the screen are uncertain, or in some cases for a more pleasing visual
effect.
If enabled (bf is #t
), curses will consider using the
hardware “insert/delete-line” feature of terminals so equipped. If
disabled (bf is #f
), curses will very seldom use this
feature. The “insert/delete-character” feature is always considered.
This option should be enabled only if your application needs
“insert/delete-line”, for example, for a screen editor. It is
disabled by default because
“insert/delete-line” tends to be visually annoying when used in applications where it is not really needed. If “insert/delete-line” cannot be used, curses will redraw the changed portions of all lines.
Normally, the hardware cursor is left at the location of the window cursor being refreshed. This option allows the cursor to be left wherever the update happens to leave it. It is useful for applications where the cursor is not used, since it reduces the need for cursor motions. If possible, the cursor is made invisible when this option is enabled.
This option controls what happens when the cursor of window win is
moved off the edge of the window or scrolling region, either from a
newline on the bottom line, or typing the last character of the last
line. If disabled (bf is #f
), the cursor is left on the
bottom line at the location where the offending character was entered.
If enabled (bf is #t
), force-output
is called on the
window win, and then the physical terminal and window win
are scrolled up one line.
Note: in order to get the physical scrolling effect on the
terminal, it is also necessary to call idlok
.
This option causes wgetch to be a non-blocking call. If no input is ready, wgetch will return an eof-object. If disabled, wgetch will hang until a key is pressed.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These routines set options within curses that deal with input. The
options involve using ioctl(2) and therefore interact with curses
routines. It is not necessary to turn these options off before
calling endwin
. The routines in this section all return an
unspecified value.
These two routines put the terminal into and out of CBREAK
mode,
respectively. In CBREAK
mode, characters typed by the user are
immediately available to the program and erase/kill character
processing is not performed. When in NOCBREAK
mode, the tty driver
will buffer characters typed until a <LFD> or <RET> is typed.
Interrupt and flowcontrol characters are unaffected by this mode.
Initially the terminal may or may not be in CBREAK
mode, as it is
inherited, therefore, a program should call cbreak
or nocbreak
explicitly. Most interactive programs using curses will set CBREAK
mode.
Note: cbreak
overrides raw
. For a discussion of
how these routines interact with echo
and noecho
See section read-char.
The terminal is placed into or out of RAW
mode. RAW
mode
is similar to CBREAK
mode, in that characters typed are
immediately passed through to the user program. The differences are
that in RAW
mode, the interrupt, quit, suspend, and flow control
characters are passed through uninterpreted, instead of generating a
signal. RAW
mode also causes 8-bit input and output. The
behavior of the BREAK
key depends on other bits in the terminal
driver that are not set by curses.
These routines control whether characters typed by the user are echoed
by read-char
as they are typed. Echoing by the tty driver is
always disabled, but initially read-char
is in ECHO
mode,
so characters typed are echoed. Authors of most interactive programs
prefer to do their own echoing in a controlled area of the screen, or
not to echo at all, so they disable echoing by calling noecho
.
For a discussion of how these routines interact with echo
and
noecho
See section read-char.
These routines control whether <LFD> is translated into <RET>
and LFD
on output, and whether <RET> is translated into
<LFD> on input. Initially, the translations do occur. By disabling
these translations using nonl
, curses is able to make better use
of the linefeed capability, resulting in faster cursor motion.
These routines save and restore the state of the terminal modes.
savetty
saves the current state of the terminal in a buffer and
resetty
restores the state to what it was at the last call to
savetty
.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Create and return a new window with the given number of lines (or rows),
nlines, and columns, ncols. The upper left corner of the
window is at line begy, column begx. If either nlines
or ncols is 0, they will be set to the value of
LINES
-begy and COLS
-begx. A new full-screen
window is created by calling newwin(0,0,0,0)
.
Create and return a pointer to a new window with the given number of
lines (or rows), nlines, and columns, ncols. The window is
at position (begy, begx) on the screen. This position is
relative to the screen, and not to the window orig. The window is
made in the middle of the window orig, so that changes made to one
window will affect both windows. When using this routine, often it will
be necessary to call touchwin
or touchline
on orig
before calling force-output
.
Deletes the window win, freeing up all memory associated with it. In the case of sub-windows, they should be deleted before the main window win.
These routines are called to write output to the terminal, as most other
routines merely manipulate data structures. force-output
copies
the window win to the physical terminal screen, taking into
account what is already there in order to minimize the amount of
information that’s sent to the terminal (called optimization). Unless
leaveok
has been enabled, the physical cursor of the terminal is
left at the location of window win’s cursor. With refresh
,
the number of characters output to the terminal is returned.
Move the window win so that the upper left corner will be at position (y, x). If the move would cause the window win to be off the screen, it is an error and the window win is not moved.
These routines overlay srcwin on top of dstwin; that is, all
text in srcwin is copied into dstwin. srcwin and
dstwin need not be the same size; only text where the two windows
overlap is copied. The difference is that overlay
is
non-destructive (blanks are not copied), while overwrite
is
destructive.
Throw away all optimization information about which parts of the window
win have been touched, by pretending that the entire window
win has been drawn on. This is sometimes necessary when using
overlapping windows, since a change to one window will affect the other
window, but the records of which lines have been changed in the other
window will not reflect the change. touchline
only pretends that
count lines have been changed, beginning with line start.
The cursor associated with the window win is moved to line (row) y,
column x. This does not move the physical cursor of the terminal
until refresh
(or force-output
) is called. The position
specified is relative to the upper left corner of the window win,
which is (0, 0).
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These routines are used to draw text on windows
The character ch or characters in str are put into the window win at the current cursor position of the window and the position of win’s cursor is advanced. At the right margin, an automatic newline is performed. At the bottom of the scrolling region, if scrollok is enabled, the scrolling region will be scrolled up one line.
If ch is a <TAB>, <LFD>, or backspace, the cursor will be
moved appropriately within the window win. A <LFD> also does a
wclrtoeol
before moving. <TAB> characters are considered to
be at every eighth column. If ch is another control character, it
will be drawn in the C-x notation. (Calling winch
after
adding a control character will not return the control character, but
instead will return the representation of the control character.)
Video attributes can be combined with a character by or-ing them into
the parameter. This will result in these attributes also being set.
The intent here is that text, including attributes, can be copied from
one place to another using inch and display. See standout
,
below.
Note: For wadd
ch can be an integer and will insert
the character of the corresponding value.
This routine copies blanks to every position in the window win.
This routine is like werase
, but it also calls clearok, arranging that the screen will be cleared
completely on the next call to refresh
or force-output
for
window win, and repainted from scratch.
All lines below the cursor in window win are erased. Also, the current line to the right of the cursor, inclusive, is erased.
The current line to the right of the cursor, inclusive, is erased.
The character under the cursor in the window win is deleted. All characters to the right on the same line are moved to the left one position and the last character on the line is filled with a blank. The cursor position does not change. This does not imply use of the hardware “delete-character” feature.
The line under the cursor in the window win is deleted. All lines below the current line are moved up one line. The bottom line win is cleared. The cursor position does not change. This does not imply use of the hardware “deleteline” feature.
The character ch is inserted before the character under the cursor. All characters to the right are moved one <SPC> to the right, possibly losing the rightmost character of the line. The cursor position does not change . This does not imply use of the hardware “insertcharacter” feature.
A blank line is inserted above the current line and the bottom line is lost. This does not imply use of the hardware “insert-line” feature.
The window win is scrolled up one line. This involves moving the lines in win’s data structure. As an optimization, if win is stdscr and the scrolling region is the entire window, the physical screen will be scrolled at the same time.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A character is read from the terminal associated with the window
win. Depending on the setting of cbreak
, this will be
after one character (CBREAK
mode), or after the first newline
(NOCBREAK
mode). Unless noecho
has been set, the
character will also be echoed into win.
When using read-char
, do not set both NOCBREAK
mode
(nocbreak
) and ECHO
mode (echo
) at the same time.
Depending on the state of the terminal driver when each character is
typed, the program may produce undesirable results.
The character, of type chtype, at the current position in window win is returned. If any attributes are set for that position, their values will be OR’ed into the value returned.
A list of the y and x coordinates of the cursor position of the window win is returned
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These functions set the current attributes of the window win. The current attributes of win are applied to all characters that are written into it. Attributes are a property of the character, and move with the character through any scrolling and insert/delete line/character operations. To the extent possible on the particular terminal, they will be displayed as the graphic rendition of characters put on the screen.
wstandout
sets the current attributes of the window win to
be visibly different from other text. wstandend
turns off the
attributes.
A box is drawn around the edge of the window win. vertch
and horch are the characters the box is to be drawn with. If
vertch and horch are 0, then appropriate default characters,
ACS_VLINE
and ACS_HLINE
, will be used.
Note: vertch and horch can be an integers and will insert the character (with attributes) of the corresponding values.
This macro expands to a character string which is a printable representation of the character c. Control characters are displayed in the C-x notation. Printing characters are displayed as is.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These procedures (defined in ‘socket.c’) provide a Scheme interface to most of the C socket library. For more information on sockets, See Sockets in The GNU C Library Reference Manual.
5.10.1 Host Data, Network, Protocol, and Service Inquiries | ||
5.10.2 Internet Addresses | ||
5.10.3 Socket |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Integer family codes for Internet and Unix sockets, respectively.
Returns a vector of information for the entry for HOST-SPEC
or the
next entry if HOST-SPEC
isn’t given. The information is:
AF_INET
)
Rewinds the host entry table back to the begining if given an argument.
If the argument stay-open is #f
queries will be be done
using UDP
datagrams. Otherwise, a connected TCP
socket
will be used. When called without an argument, the host table is
closed.
Returns a vector of information for the entry for name-or-number or the next entry if an argument isn’t given. The information is:
AF_INET
)
Rewinds the network entry table back to the begining if given an
argument. If the argument stay-open is #f
the table will be closed
between calls to getnet. Otherwise, the table stays open. When
called without an argument, the network table is closed.
Returns a vector of information for the entry for name-or-number or the next entry if an argument isn’t given. The information is:
Rewinds the protocol entry table back to the begining if given an
argument. If the argument stay-open is #f
the table will be closed
between calls to getproto. Otherwise, the table stays open. When
called without an argument, the protocol table is closed.
Returns a vector of information for the entry for name-or-port-number and protocol or the next entry if arguments aren’t given. The information is:
Rewinds the service entry table back to the begining if given an
argument. If the argument stay-open is #f
the table will be closed
between calls to getserv. Otherwise, the table stays open. When
called without an argument, the service table is closed.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Returns the host address number (integer) for host string or
#f
if not found.
Converts an internet (integer) address to a string in numbers and dots notation. This is an inverse function to inet:address.
Returns the network number (integer) specified from address or
#f
if not found.
Returns the integer for the address of address within its local
network or #f
if not found.
Returns the Internet address of local-address in network.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
When a port is returned from one of these calls it is unbuffered. This allows both reading and writing to the same port to work. If you want buffered ports you can (assuming sock-port is a socket i/o port):
(require 'i/o-extensions) (define i-port (duplicate-port sock-port "r")) (define o-port (duplicate-port sock-port "w"))
Returns a SOCK_STREAM
socket of type family using
protocol. If family has the value AF_INET
,
SO_REUSEADDR
will be set. The integer argument protocol
corresponds to the integer protocol numbers returned (as vector
elements) from (getproto)
. If the protocol argument is not
supplied, the default (0) for the specified family is used. SCM
sockets look like ports opened for neither reading nor writing.
Returns a pair (cons) of connected SOCK_STREAM
(socket) ports of
type family using protocol. Many systems support only
socketpairs of the af-unix
family. The integer argument
protocol corresponds to the integer protocol numbers returned (as
vector elements) from (getproto). If the protocol argument is
not supplied, the default (0) for the specified family is used.
Makes socket no longer respond to some or all operations depending on the integer variable how:
Socket:shutdown
returns socket if successful, #f
if
not.
Returns socket (changed to a read/write port) connected to the
Internet socket on host host-number, port port-number or
the Unix socket specified by pathname. Returns #f
if not
successful.
Returns inet-socket bound to the integer port-number or the
unix-socket bound to new socket in the file system at location
pathname. Returns #f
if not successful. Binding a
unix-socket creates a socket in the file system that must be
deleted by the caller when it is no longer needed (using
delete-file
).
The bound (see section socket-bind) socket is readied to
accept connections. The positive integer backlog specifies how
many pending connections will be allowed before further connection
requests are refused. Returns socket if successful, #f
if
not.
Accepts a connection on a bound, listening socket. Returns an input/output port for the connection.
For example:
(let ((sock (socket:bind (make-stream-socket af_inet) 8001))) (socket:listen sock 5) (do ((connection (socket:accept sock) (socket:accept sock))) (#f) (handle-client-connection connection))))
A type socket-name is used for inquiries about open sockets in the following procedures:
Returns the socket-name of socket. Returns #f
if
unsuccessful or socket is closed.
Returns the socket-name of the socket connected to socket.
Returns #f
if unsuccessful or socket is closed.
Returns the integer code for the family of socket-name.
Returns the integer port number of socket-name.
Returns the integer Internet address for socket-name.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Using SCM as a base, GUILE is a being developed to be a GNU scripting language.
One design goal of GUILE is to fully support a large body of Emacs lisp code and a large population of Emacs lisp programmers. GUILE accomplishes this goal by means of a translator that rewrites elisp programs as equivalent programs in extended GUILE Scheme. We anticipate a port of the GNU Emacs built-ins to the GUILE environment.
Tom Lord (Lord@cygnus.com) is coordinating GUILE’s development.
6.1 Locked Vectors | You can define the layout of new types. | |
6.2 Exceptions | Cheap CATCH/THROW for errors and exits. | |
6.3 System Exceptions | All error conditions can be caught by Scheme code. | |
6.4 Variables | First class locatives for top level variables. | |
6.5 User Defined Top Levels | You can control the symbol->variable mapping. | |
6.6 Obarrays | First class tables for interning symbols. | |
6.7 Keywords | ||
6.8 Procedure Properties | ||
6.9 Dynamic Roots | Creating uncapturable continuations. | |
6.10 Tcl Facilities | Mutual calling between Tcl and Scheme. | |
6.11 Tk Facilities | Accessing Tk from Scheme. | |
6.12 Gwish | A Wish-like application of Guile. | |
6.13 System Calls | You can choose to ignore errors safely. | |
6.14 Gscsh | Shell and systems programming features. |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Locked vectors lvectors are a low level means by which Scheme code can define the representation of new types. They are not themselves especially easy to use, but useful system can be built on top of them (for example, see Records in SLIB).
User code should be selective about using lvector functions. Lvectors are intended as the representation for user-defined types. Types which otherwise have nothing to do with one another may have in common an lvector representation. Using lvector functions in a context other than defining a new type or family of types is likely to be an unsupported violation of abstractions – something you generally only want to do when you are debugging or are willing to write hacked up (in the pejorative sense) code.
Locked vectors have an internal representation similar to vectors. They are represented by a contiguous array in memory. Access and modifications to fields can be done in constant time. Like vectors, fields of a locked vector are addressed by integer addresses, based at 0.
The 0 element of a locked vector is special. It is called the key vector. It’s use is comparable to that of type objects in other systems.
The key vector must always be present (there is no such thing as a 0 length lvector). It must be a (normal) vector with at least as many elements as the lvector. The elements of the key vector are used as keys which control access to the corresponding elements of the lvector.
Keys are used this way: Procedures like lvector-ref and lvector-set!
take a key argument in addition to the lvector and field index.
The key argument is compared to the indexed element of the key vector.
If they are the same (eq?
), access to the lvector is granted.
If an access or modification fails because of an incorrect key, it may
be retried.
If element 0 of the key vector is itself an lvector, the first several elements of that lvector may be hook functions. These hook functions are used to extend the behavior of built-in procedures. Hook functions are explained in more detail at the end of this section.
6.1.1 Lvector Procedures | ||
6.1.2 Key-Vector 0 Elements |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Modify vec so that it is a locked vector instead of a vector. Once it
is locked, ordinary vector operations no longer apply to vec, and
vector?
returns #f
for vec.
In order to be locked, vec must have at least one element. The 0 element of vec must be a key vector (see above).
lock-vector!
is currently the only way to construct a locked
vector. However, the decision to create locked vectors by mutating
vectors is a dubious one. Therefore, you should only use lock-vector!
by wrapping it around a vector constructor, as in:
(lock-vector! (apply vector (cons key-vector field-inits)))
Following this convention will make it easier to replace lock-vector! with a more reasonable constructor later.
Modify lvec so that it is once again the vector passed to
lock-vector!
.
You should only use unlock-vector!
for debugging. It is not
guaranteed to be present in future versions of Guile.
Return the indexth element of lvec.
If key matches the indexth element of the key vector of
lvec, then the indexth element of lvec is returned.
If the key does not match, then the ref-fn
hook is tried (hooks
are documented below). If the indexth element can not be
unlocked, an error is signaled.
Set the indexth element of lvec.
If key matches the indexth element of the key vector of
lvec, then the indexth element of lvec is set. If the
key does not match, then the set-fn
hook is tried (see below).
If the indexth element can not be unlocked, an error is signaled.
True if OBJ is indeed a locked vector.
Return the key vector of lvec, a locked vector.
Return an accessor for key-vec and index. This function is defined as:
(define (lvector-accessor keyvec index) (lambda (lvec) (lvector-ref lvec (vector-ref keyvec index) index)))
However, the built-in version returns an accessor function that is faster than what the above code would return.
Return an modifier for key-vec and index.
This function is defined as:
(define (lvector-modifier keyvec index) (lambda (lvec val) (lvector-set! lvec (vector-ref keyvec index) index val)))
However, the built-in version returns an modifier function that is faster than what the above code would return.
Return #t
if lvector’s 0th element is eq?
to
key-vector.
If key-vector is not equal to element 0, lvector-isa? may yet return a true value – it returns the (arbitrary) return value of the isa-fn?, if that hook is provided.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The first element of the key vector is special. It may refer to a number of hook functions used by the lvector procedures and other parts of the run time system.
The 0 element of a key vector may (optionally) be an lvector called
the type lvector. A type lvector is characterized by having as a
key the procedure lvector-ref
for elements at offsets where hook
functions are expected.
The hook function offsets are bound to the variables lvector-hook-<fn>; so the ref-fn is at the offset bound to lvector-ref-fn, the set-fn to lvector-set-fn and so on.
The order and position of the hooks is explicitly specified:
Here is how they are used:
This function is called by lvector-ref
for illegal keys. A
key is illegal if it is not eq?
to the indexth key of
the key vector of lvec. The ref-fn
hook may return a value
for lvector-ref
or can signal an error. The default action is to
signal an error.
This function is called by lvector-set!
for illegal keys. This
hook can interpret the assignment arbitrarily, including signal an
error. It can return a value for lvector-set!
. The default
action is to signal an error.
This function, if present, is called whenever the object is printed. It
should print the object on port. writing?, if #t
,
indicates that the value is being write
n; if #f
–
display
ed. The print function should return a true value if it
succeeds. It should return #f
for objects which it can not
print. In that case, a generic print routine for unknown objects
is used. The default action (if no print-fn is supplied) is to
print something like: ‘#<locked-vector 0x7856af8>’.
If present, called to evaluate (equal? lvec lvec2)
.
The default action is a member-wise comparison of the two lvecs.
Note that the first argument to equal?
chooses the hook function.
If present, this may be called by lvector-isa?
.
If key-vector is eq to lvecs key-vector, then lvector-isa?
simply returns #t
. If not, if the isa-fn is present, it is
called. The default action is to return #f
.
Any of the hooks may be #f
specifying that the default action
should be used.
The variable lvector-hook-slots
is bound to the number of hook
slots looked for by the run time system. A type lvector should have at
least that many fields.
Here is an illustration of the construction of lvectors. Note that two lvectors are built – one to hold the hook functions, and then the one for user code.
;; Create a key vector compatible with the run-time system's ;; way of finding hook functions. ;; (define a-type-keyvec ;; The run-time system uses procedure lvector-ref as the key ;; to access hook functions. You could define type keyvecs ;; with more elements if you had a use for them. ;; (make-vector lvector-hook-slots lvector-ref)) ;; Lock up user-provided hook functions for the run-time system. ;; A var-args implementation would make more sense -- it would ;; make it easier to add hooks later. The example is written ;; this way just to provide a reference for the proper order ;; of hook functions within the lvector. ;; (define (make-type-lvector ref-hook set-hook print-hook equal-hook isa-hook) (lock-vector! (vector a-type-keyvec ref-hook set-hook print-hook equal-hook isa-hook))) ;; Turn a list of field keys into a key vector of a particular ;; type: ;; (define (make-key-vector type-lvector . field-keys) (apply vector (cons type-lvector field-keys))) ;; Turn a key-vector and list of field initializers into ;; a locked vector. Note that lock-vector! does some error ;; checking on the lengths of the input arguments. ;; (define (make-object key-vector . field-inits) (lock-vector! (apply (vector (cons key-vector field-inits)))))
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These are the low level entry points to exceptions. Individual subsystems may define their own uses for exceptions.
Invoke thunk in the dynamic context of handler for excpetions matching key. If thunk throws to the symbol key, then handler is invoked this way:
(handler key args ...)
key may be a symbol. In that case, thunk takes no
arguments. If thunk returns normally, that is the return value of
catch
.
Handler is invoked outside the scope of its own catch
. If
handler against throws to the same key, a new handler from further up
the call chain is invoked.
If the key is #t, then a throw to any symbol will match this call
to catch
.
Key may also be the value #f
. In that case, thunk takes
one argument which will be passed a jump buffer object. A jump
buffer object may be used as the key argument to throw
to throw
to a specific catch
without an intervening search for a symbolic
key.
Invoke the catch form matching key, passing args to the handler.
If the key is a symbol it will match catches of the same
symbol or of #t. If no catch matches, the throw-default-handler
property of the key is checked. If it is bound to a procedure,
that procedure is called:
(handler key args ...)
That procedure is called the default handler.
If there is no handler at all, or if the default handler returns to its caller, an error is signaled.
It is traditional in Scheme to implement exception systems using
call-with-current-continuation
, but his has not been done, for
performance reaons. The implementation of
call-with-current-continuation
is a stack copying implementation.
This allows it to interact well with ordinary C code. Unfortunately, a
stack-copying implementation can be slow – creating a new continuation
involves a block copy of the stack.
Instead of using call-with-current-continuation
, the exception
primitives are implemented as built-ins that take advantage of the
upward only nature of exceptions.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These two expressions are equivalent:
(error arg ...) (throw 'error arg ...)
The following are the names of excpetions that may be thrown by the interpreter itself.
ARGn "Wrong type argument" ARG1 "Wrong type argument in position 1" ARG2 "Wrong type argument in position 2" ARG3 "Wrong type argument in position 3" ARG4 "Wrong type argument in position 4" ARG5 "Wrong type argument in position 5" WNA "Wrong number of arguments" OVFLOW "Numerical overflow" OUTOFRANGE "Argument out of range" NALLOC "Could not allocate" HUP_SIGNAL "hang-up" INT_SIGNAL "user interrupt" FPE_SIGNAL "arithmetic error" BUS_SIGNAL "bus error" SEGV_SIGNAL "segmentation violation" ALRM_SIGNAL "alarm" read-sharp-error
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
All top level bindings are stored in locations called variables. Variables are first class objects.
Return a new variable, bound to init.
The optional name-hint is a symbolic name for the variable. It will be used in some error messages relating to the variable.
Return the current binding of variable.
It is an error to call variable-ref
on a variable which is
unbound.
Modify the binding of variable.
Return the built-in variable for named name. name must be a symbol.
Even symbols with no top level bindings have built-in variables. There is an unbounded supply of undefined variables.
Return #t
if obj is a variable; #f
otherwise.
Return #t
if var is a bound variable; #f
otherwise.
Return a new variable, initially unbound.
The optional name-hint a symbolic name for the variable. It will be used in some error messages relating to the variable.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Low level support is provided for multiple top levels. This procedure should only be used advisadly. Most people should stick to the user level module system interface.
Evaluate form in the top level environment described by env-fn.
env-fn is called this way:
(env-fn name defining)
Return a variable object for the symbol name. Returning #f
indicates that name has no binding.
The boolean defining is #t
, then the lookup is for a
define
form or the equivalent – a new variable may be created if
none already exists.
If #f
, then the request should not create a new binding.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
An obarray is an ordinary Scheme vector, used in a particular way. It represents two mapping: a mapping of strings to symbols, and a mapping of symbols to arbitrary values.
To initialize an obarray, create a vector of any non-0 size, filled with the empty list. Thereafter, referring to the contents of the vector yields unspecified values. (You might be able guess the detailed representation of obarrays by examining the array, but if your code depends on that representation, it might easily break in future versions of Guile.)
Return the symbol bound to the stringname in obarray.
If there is no such symbol, a new symbol is allocated.
obarray may be #f
which guarantees that a new symbol
is returned.
Add symbol to obarray. If symbol is already present, this has no effect.
After this addition, symbol is the symbol binding of its name. That is, even if another symbol of the same name was previously interned in obarray, symbol becomes the binding of that name after intern-symbol. (This does not mean that the previous symbol is removed from the obarray).
Return #t
if symbol is in obarray.
A symbol in an obarray may be bound arbitrarily. The binding may be changed. When first interned, a symbol is unbound.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A keyword is a self-evaluating symbol-like object with a convenient read syntax.
(keyword? :keyword) => #t
Construct a keyword from a symbol.
(symbol->keyword 'fnord) => :fnord
A low-level way to construct a keyword from a symbol, convenient when dealing with Tcl or Unix. The first character of the symbol’s name must be ’-’.
(make-keyword '-command) => :command
Return #f
unless obj is a keyword object.
Return the symbol that corresponds to a keyword.
(keyword->symbol :text) => -text
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Procedures created using "define" or "lambda" have a binding slot which you can use arbitrarily. Many parts of the system will presume that this slot will contain a (possible empty) assoc list, keyed by symbols (‘procedure properties’). If your procedure will be manipulated by a part of the system which is documented as using property lists, you should follow the convention, and use a unique prefix for all property names that you define. Procedures which do not escape to such parts of the system can hve any value at all in their binding slot.
It is an arbitrary restriction that (some) built-in procedures lack a binding slot. This ought to be fixed. The reason it hasn’t been fixed already is that the representation of the binding slot has to be chosen carefully for built-in procedure types.
Return or set the value held in a procedures binding slow.
Retrieve or get the binding of a particular procedure property.
These functions assume that the binding slot of the procedure holds an assoc list.
procedure-property
returns the binding of the property while
procedure-assoc
returns the key-value pair that holds the binding.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A dynamic root is a root frame of Scheme evaluation. The top-level repl, for example, is an instance of a dynamic root.
Each dynamic root has its own chain of dynamic-wind information. Each has its own set of continuations, jump-buffers, and pending CATCH statements which are inaccessible from the dynamic scope of any other dynamic root.
In a thread-based system, each thread has its own dynamic root. Therefore, continuations created by one thread may not be invoked by another. [Thread support is not yet fully implemented.]
Even in a single-threaded system, it is sometimes useful to create a new dynamic root. For example, if you want to apply a procedure, but to not allow that procedure to capture the current continuation, calling the procedure under a new dynamic root will do the job.
Evaluate (thunk) in a new dynamic context, returning its value.
If an error occurs during evaluation, call error-thunk, passing it an error code describing the condition. [Error codes are currently meaningless integers. In the future, real values will be specified.] If this happens, the error-thunk is called outside the scope of the new root – it is called in the same dynamic context in which call-with-dynamic-root was evaluated.
If THUNK captures a continuation, the continuation is rooted at the call to THUNK. In particular, the call to call-with-dynamic-root is not captured. Therefore, call-with-dynamic-root always returns at most one time.
Before calling THUNK, the dynamic-wind chain is un-wound back to the root and a new chain started for THUNK. Therefore, this call may not do what you expect:
;; Almost certainly a bug: (call-with-output-to-port some-port (lambda () (call-with-dynamic-root (lambda () (display 'fnord) (newline)) (lambda (errcode) errcode))))
The problem is, on what port will ‘fnord\n’ be displayed? You
might expect that because of the call-with-input-from-port
that
it will be displayed on the port bound to some-port
. But it
probably won’t – before evaluating the thunk, dynamic winds are
unwound, including those created by call-with-input-from-port
.
So, the standard output port will have been re-set to its default value
before display
is evaluated.
(This function was added to Guile mostly to help calls to functions in C libraries that can not tolerate non-local exits or calls that return multiple times. If such functions call back to the interpreter, it should be under a new dynamic root.)
Return an object representing the current dynamic root.
These objects are only useful for comparison using eq?
.
They are currently represented as numbers, but your code should
in no way depend on this.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If you have Tcl extension modules written in C, these can be accessed from Guile programs. If you have an application that uses the Tcl interpreter, you can use Guile to define new modules for it – modules that can be loaded without having to re-compile.
Documented here are the low-level facilities linking Tcl to Guile. In the future, a friendlier Scheme interface will be provided in preference to these entry points.
Return a new Tcl interpreter object.
An interpreter object is a namespace of functions and variables managed by modules that use the Tcl calling conventions.
Evaluate a string according to Tcl’s evaluation rules.
interpreter must be an object returned by tcl-create-interp
.
The return value is an integer/string pair. The integer is the Tcl status code, the string is the Tcl result.
This is not the way to call a Tcl command. See the functions tcl-command
and tcl-apply-command
. Using those functions is faster.
N.B.: by default, most built-in Tcl commands are absent in Guile. Consequently, most Tcl programs will not run. However, facilities exist so that you can link all of libtcl with Guile programs – in which case all the usual built-in commands will be present. [add reference!]
Convert strings to Scheme types according to the conventions of Tcl.
Split a Tcl-style "list" (a string following Tcl’s list syntax) into a list.
Combine a list of strings into a string following Tcl’s list syntax.
Define a new Tcl command which is recognized by the Tcl evaluator.
interpreter must be an object returned by tcl-create-command
.
name must be a string which is a valid Tcl identifier.
procedure may be any Scheme procedure object.
When the Tcl evaluator invokes the new command, procedure is called with as many arguments as were passed to the Tcl command. The arguments are all passed as strings.
The return value of procedure is used as the Tcl result. The return value of procedure determines the Tcl return value according to these rules:
if PROCEDURE returns: the Tcl result is: and Tcl status is: __________________________________________________________________ string (e.g. "foo") that string ("foo") TCL_OK integer (e.g. 1) the empty string the int (1) an int/string pair the string the int (e.g. (1 . "bogus frob")) ("bogus frob") (1)
Remove the named command from a Tcl interpreter.
Add a callback to a Tcl variable.
name is the name of the variable.
index is the subscript of the variable, or #f
for a scalar.
After tcl-trace-var2
, modifications to the named variable or
array position cause procedure to be called with four arguments:
a tcl interpreter, the variable being modified, an index into the
named variable (possible the empty string), and an integer of flags.
Set or return the current value of a Tcl variable.
Symbolic names for Tcl flags are provided in the source file Gtcl.scm
and are the same as their C counterparts. The procedure flags
is used to combine flags. For example:
(flags TCL_TRACE_READS TCL_TRACE_WRITES TCL_TRACE_UNSETS)
Tcl commands can be invoked from Scheme directly, without having to use the Tcl evaluator:
Return an object representing the named command (or #f if none is defined).
Apply Tcl command command to the list of strings args.
command should be an object returned by tcl-command
.
args should be a list of arguments.
The return value is an integer/string pair. The integer is a Tcl return code, the string the Tcl result.
The arguments can be of several types but must ultimately be converted to strings because of the way Tcl and Tk work internally. Types are converted this way:
;;---------------------------------------- ;; Argument Converted argument ;;---------------------------------------- 123 "123" 123.34 "123.34" "a-string" "a-string" 'a-symbol "a-symbol" :keyword "-keyword" #t "1" #f "0" (lambda (...) ...) "*__guile#234"
The automatic conversion of a procedure works this way. First, a new Tcl name is generated for the procedure and a Tcl command with that name is defined. When evaluated, the Tcl command calls the Scheme procedure. Second, if the procedure has a property defined called ’tcl-calling-convention, and if that is bound to a string, then that string is appended to the name with an intervening space. For example, if a procedure’s properties bind ’tcl-calling-convention to "%x %y", then the name is appended and winds up like "__guile#234 %x %y". Finally, an asterix is prepended to the name (e.g. "*__guile#234 %x %y").
In the GNU modified version of Tcl/Tk, an asterix prepended to a command name has special meaning if the name is passed as a "-command" or similar configuration parameter to a widget, or if passed as the command argument to a "bind" operation. In that case, the command is renamed to a canonical name that is unique to the widget or binding sequence (overwriting any previous definition). If the widget or binding sequence is later deleted, so is the canonicalized command. This is an extremely twisted way to trick Tcl into managing anonymous Scheme procedures with acceptable semantics (e.g., without core leaks and without requiring Scheme programmers to invent liveness for anonymous procedures they’d otherwise drop).
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
So that Tk widgets can be used form Scheme, Guile provides the following functions:
Initialize a Tcl interpreter as a Tk main window.
display, name, and class must all be strings.
Process one window system event.
Symbolic definitions for flags are provided in Gtk.scm and have the same name as their C counterparts.
Process window events until no windows remain.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Gwish is a Wish-like application of Guile, based on STk by Erick Gallesio.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
In Gwish, there is a single Tcl/Tk interpreter which is an implicit default. Commands defined in that interpreter are automaticly defined as Scheme commands as well (unless a Scheme-specific binding overwrites them). This means that you can write Scheme code that closely matches the corresponding Tcl code. For example:
(button '.b) (.b 'configure :text "hello world" :command (tcl-lambda () (beep)))
Arguments passed to a procedure implemented by a Tcl command must be converted to a string for the sake of Tcl’s calling conventions and data representations. This table illustrates how argument types are converted:
;;---------------------------------------- ;; Argument Converted argument ;;---------------------------------------- 123 "123" 123.34 "123.34" "a-string" "a-string" 'a-symbol "a-symbol" :keyword "-keyword" #t "1" #f "0" (lambda (...) ...) "*__guile#234"
Most of these conversions are simple and obvious but the conversion of procedure objects is subtle and non-obvious. It is not necessary to understand the details, though they are documented elsewhere. It is necessary to know that procedure arguments ‘do the right thing’ when they are passed as command parameters to widget configuration commands, and as event bindings. You might ask: what is the right thing?
A procedure passed as either an event binding or widget command is protected by the binding or widget involved. Effectively, the widget or binding keeps a reference to the procedure object. For this reason, it is possible to use an anonymous Scheme procedure as an event binding or widget command. For example:
(let ((n 0)) (.b configure :command (lambda () (write n) (newline) (set! n + 1) ""))) ;; Incidently, note that the command procedure returns an empty string. ;; All procedures called by Tcl have to return a proper Tcl result. ;; Return values are explained further in the next subsection. ;;
When a command or binding is overwritten and that command or binding is to a Scheme procedure, the reference to the procedure is dropped. The procedure is also dropped if the binding or widget is deleted. For this reason, there are no core leaks associated with passing anonymous procedures as these kinds of arguments.
At this time, it isn’t generally useful to pass Scheme procedures to Tcl commands other than as an argument to a binding command or widget configuration command.
The details of how procedures are translated are described in the documentation for ‘tcl-apply-command’. See section Tcl Facilities.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Gwish provides a convenient syntax for defining new Tcl commands.
Define a new Tcl command and Scheme procedure simultaneously.
;; A two argument string-append callable as a Tcl command. ;; (proc string-smash (s1 s2) (string-append s1 s2))
Proc expands to a tcl-lambda
form, which is explained below.
The example above is equivalent to:
(begin (define string-smash (tcl-lambda (s1 s2) (string-append s1 s2))) (tcl-create-command the-interpreter 'string-smash string-smash))
Similar to lambda, but imposes Tcl-specific calling conventions. Type declarations are supported. This is best explained via examples.
A simple use of tcl-lambda
:
;; By default, when called from Tcl, all of the arguments ;; to a tcl-lambda are strings. ;; (tcl-lambda (a b) (string-append a b))
The return value of a tcl-lambda has special signficance when the function is invoked by Tcl.
An integer return value is converted to a string. A string or symbol is used used directly as a Tcl result. A cons pair with an integer car and string cdr is a Tcl status/message combination.
Type declarations can be used to specify that parameters passed as strings should be coerced to some other type. For example:
(define tcl-plus (tcl-lambda ((number a) (number b)) (+ a b))) (tcl-plus "23" 19) => 42
Tcl-lambda is very useful for using anonymous Scheme functions as Tk event bindings. For this purpose, you can can specify a Tk "calling convention" by writing a string in the first of the argument specification. For example:
(.c 'bind 'node "<Button-2>" (tcl-lambda ("%x %y" (number x) (number y)) (set! cur-x x) (set! cur-y y) #t)) ; Tcl-compatible return value.
In that example, "%x %y"
is the calling convention. The full command
that Tcl calls when invoking the binding will be similar to:
__binding#0x123123 %x %y
and therefore the Scheme procedure will be passed (in this case) the x and y position of the mouse.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This program implements the toy graph editor from the Tcl/Tk <fixme>.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A volunteer is need to write this section. Most of the system call documentation already exists in other sections. See also See section I/O-Extensions, See section Posix Extensions.
All of the unix system calls are available as Scheme procedures.
Any call that fails with errno EINTR is automaticly retried.
By default, any other error during a system call will cause the call
to signal an error and not return. There are two functions that control
this behavior and which you can redefine. These are syscall
and syserror
. The default definitions are:
(define (syserror key fn err . args) (errno err) (apply error (cons fn args))) (define (syscall thunk) (errno 0) (catch 'syserror thunk syserror))
A typical system call is written this way:
(define (connect port address . args) (syscall (lambda () (let ((rv (apply %connect (cons port (cons address args))))) (if (eq? rv #f) (throw 'syserror 'connect (errno) port address args))))))
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Fork a child process: returns child pid to parent, #f to child.
With an argument, fork a child process executing the Scheme procedure thunk. Returns child pid to parent.
Wait for any child to terminate.
Pid argument means for that child process to terminate. Special values for pid are: -1 wait for any child process; 0 wait for any child process in the process group of the calling process.
Options is an integer with the following OR’d values:
WNOHANG: do not wait. WUNTRACED: also return status information from stopped processes.
These functions run external programs in a pipeline. exec-pipe causes the pipeline to overlay the current process. fg-pipe waits for the first command in the pipeline to exit and returns its exit status code. bg-pipe runs the pipeline in the background, returning a list with the process id of the first program and ports which can be used for communicating with the programs in the pipeline.
The pipe argument consists of a series of commands and optionally connection lists. A command can be either an external Unix program or a scheme procedure. An external program is written as a list of strings with the name and arguments. An example of a pipeline connecting three programs and using the default connection lists is:
(exec-pipe '("cat" "/etc/passwd") '("sort" "-t:" "+2") '("grep" "^u"))
Alternatively a Scheme procedure (taking no arguments) may be specified and will be run in its own subprocess. The standard ports (current-input-port, current-output-port and current-error-port) are created automatically from file descriptors 0, 1 and 2. A Scheme procedure used in a pipeline would typically be a filter, such as:
(define filter (lambda () (let loop ((ch (read-char))) (cond ((not (eof-object? ch)) (display ch) (loop (read-char)))))))
and the term in the pipeline would be written:
`(,filter)
A connection list specifies how open Scheme ports are connected to Unix file descriptors in the programs in the pipeline and how file descriptors are wired together between programs. For example, the default connection list between the sort and grep commands in the pipeline above is:
`((1 0) (2 ,(current-error-port)))
which says to connect file descriptor 1 (standard output) from the sort command to file descriptor 0 (standard input) in the grep command and to connect file descriptor 2 (standard error) from the sort command to the Scheme current error port.
Connection lists may be placed between programs in the pipeline and if omitted the default above will be used. Connection lists may also be placed before the first program and after the last to specify connections at the beginning and end of the pipeline. The default connection list then depends on which pipeline function is used.
The defaults for exec-pipe and fg-pipe are:
`((,(current-input-port) 0)) `((1 ,(current-output-port)) (2 ,(current-error-port)))
for the input and output ends of the pipeline respectively.
The defaults for bg-pipe are:
'((return-port 0)) `((1 return-port) (2 ,(current-error-port)))
The symbol ’return-port in the connection list adds a port to the list returned by bg-pipe. In the default case two ports are returned: the first is an output port connected to the standard input of the first program in the pipeline and the second is an input port connected to the standard output of the last process. [need to beware of deadlocks if multiple output ports are returned].
The pipeline example above can be rewritten with all the connection lists given explicitly:
(exec-pipe `((,(current-input-port) 0)) '("cat" "/etc/passwd") `((1 0) (2 ,(current-error-port))) '("sort" "-t:" "+2") `((1 0) (2 ,(current-error-port))) '("grep" "^u") `((1 ,(current-output-port)) (2 ,(current-error-port)))
Multiple file descriptors can be connected to a single target if a connection list such as ’((1 0) (2 0)) or equivalently ’((1 2 0)) is specified.
A final construction which can be used in a connection list is a string to be interpreted as the name of a file. For example, the connection list between the sort and grep commands could be written:
'((1 0) (2 "sort-errors"))
which would capture the standard error from sort to a newly created file. [Maybe this should be extended to allow appending to a file, e.g., with ">sort-error-log", although it could also be done with ports].
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
7.1 Data Types | ||
7.2 Operations | ||
7.3 Improvements To Make | ||
7.4 Finishing Dynamic Linking |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
In the descriptions below it is assumed that long int
s are 32
bits in length. Acutally, SCM is written to work with any long
int
size larger than 31 bits. With some modification, SCM could work
with word sizes as small as 24 bits.
All SCM objects are represented by type SCM. Type SCM
come
in 2 basic flavors, Immediates and Cells:
7.1.1 Immediates | ||
7.1.2 Cells | ||
7.1.3 Data Type Representations |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
An immediate is a data type contained in type SCM
(long int
). The type codes distinguishing immediate types from
each other vary in length, but reside in the low order bits.
Return non-zero if the SCM
object x is an immediate or
non-immediate type, respectively.
immediate 30 bit signed integer. An INUM is flagged by a 1
in
the second to low order bit position. The high order 30 bits are used
for the integer’s value.
Return non-zero if the SCM
x is an immediate integer or not
an immediate integer, respectively.
Returns the C long integer
corresponding to SCM
x.
Returns the SCM
inum corresponding to C long integer
x.
is equivalent to MAKINUM(0)
.
Computations on INUMs are performed by converting the arguments to C integers (by a shift), operating on the integers, and converting the result to an inum. The result is checked for overflow by converting back to integer and checking the reverse operation.
The shifts used for conversion need to be signed shifts. If the C
implementation does not support signed right shift this fact is detected
in a #if statement in ‘scmfig.h’ and a signed right shift,
SRS
, is constructed in terms of unsigned right shift.
characters.
Return non-zero if the SCM
object x is a character.
Returns corresponding unsigned char
.
Given char
x, returns SCM
character.
These are frequently used immediate constants.
#t
#f
()
. If SICP
is #define
d, EOL
is
#define
d to be identical with BOOL_F
. In this case, both
print as #f
.
end of file token, #<eof>
.
#<undefined>
used for variables which have not been defined and
absent optional arguments.
#<unspecified>
is returned for those procedures whose return
values are not specified.
Returns non-zero if n is an ispcsym, isym or iflag.
Returns non-zero if n is an ispcsym or isym.
Given ispcsym, isym, or iflag n, returns its index in the C array
isymnames[]
.
Given ispcsym, isym, or iflag n, returns its char *
representation (from isymnames[]
).
Returns SCM
ispcsym n.
Returns SCM
iisym n.
Returns SCM
iflag n.
An array of strings containing the external representations of all the ispcsym, isym, and iflag immediates. Defined in ‘repl.c’.
The number of ispcsyms and ispcsyms+isyms, respectively. Defined in ‘scm.h’.
and
, begin
, case
, cond
, define
,
do
, if
, lambda
, let
, let*
,
letrec
, or
, quote
, set!
, #f
,
#t
, #<undefined>
, #<eof>
, ()
, and
#<unspecified>
.
special symbols: syntax-checked versions of first 14 isyms
indexes to a variable’s location in environment
pointer to a symbol’s value cell
pointer to a cell (not really an immediate type, but here for
completeness). Since cells are always 8 byte aligned, a pointer to a
cell has the low order 3 bits 0
.
There is one exception to this rule, CAR Immediates, described next.
A CAR Immediate is an Immediate point which can only occur in the
CAR
s of evaluated code (as a result of ceval
’s memoization
process).
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Cells represent all SCM objects other than immediates. A cell has
a CAR
and a CDR
. Low-order bits in CAR
identify
the type of object. The rest of CAR
and CDR
hold object
data. The number after tc
specifies how many bits are in the
type code. For instance, tc7
indicates that the type code is 7
bits.
Allocates a new cell and stores a pointer to it in SCM
local
variable x.
Care needs to be taken that stores into the new cell pointed to by x do not create an inconsistent object. See section Signals.
All of the C macros decribed in this section assume that their argument
is of type SCM
and points to a cell (CELLPTR
).
Returns the car
and cdr
of cell x, respectively.
Returns the 3, 7, and 16 bit type code of a cell.
scheme cons-cell returned by (cons arg1 arg2).
Returns non-zero if x is a tc3_cons
or isn’t, respectively.
applicable object returned by (lambda (args) …).
tc3_closure
s have a pointer to other the body of the procedure in
the CAR
and a pointer to the environment in the CDR
.
Returns non-zero if x is a tc3_closure
.
Returns the code body or environment of closure x, respectively.
Headers are Cells whose CDR
s point elsewhere in memory,
such as to memory allocated by malloc
.
spare tc7
type code
scheme vector.
Returns non-zero if x is a tc7_vector
or if not, respectively.
Returns the C array of SCM
s holding the elements of vector
x or its length, respectively.
static scheme symbol (part of initial system)
malloc
ed scheme symbol (can be GCed)
Returns non-zero if x is a tc7_ssymbol
or
tc7_msymbol
.
Returns the C array of char
s or as unsigned char
s holding
the elements of symbol x or its length, respectively.
scheme string
Returns non-zero if x is a tc7_string
or isn’t,
respectively.
Returns the C array of char
s or as unsigned char
s holding
the elements of string x or its length, respectively.
uniform vector of booleans (bit-vector)
uniform vector of integers
uniform vector of non-negative integers
uniform vector of short inexact real numbers
uniform vector of double precision inexact real numbers
uniform vector of double precision inexact complex numbers
applicable object produced by call-with-current-continuation
Subr and environment for compiled closure
A cclo is similar to a vector (and is GCed like one), but can be applied as a function:
makes a closure from the subr proc with len-1 extra
locations for SCM
data. Elements of a cclo are referenced
using VELTS(cclo)[n]
just as for vectors.
A Subr is a header whose CDR
points to a C code procedure.
Scheme primitive procedures are subrs. Except for the arithmetic
tc7_cxr
s, the C code procedures will be passed arguments (and
return results) of type SCM
.
associative C function of 2 arguments. Examples are +
, -
,
*
, /
, max
, and min
.
C function of no arguments.
C function of one argument.
These subrs are handled specially. If inexact numbers are enabled, the
CDR
should be a function which takes and returns type
double
. Conversions are handled in the interpreter.
floor
, ceiling
, truncate
, round
,
$sqrt
, $abs
, $exp
, $log
, $sin
,
$cos
, $tan
, $asin
, $acos
, $atan
,
$sinh
, $cosh
, $tanh
, $asinh
, $acosh
,
$atanh
, and exact->inexact
are defined this way.
If the CDR
is 0
(NULL
), the name string of the
procedure is used to control traversal of its list structure argument.
car
, cdr
, caar
, cadr
, cdar
,
cddr
, caaar
, caadr
, cadar
, caddr
,
cdaar
, cdadr
, cddar
, cdddr
, caaaar
,
caaadr
, caadar
, caaddr
, cadaar
,
cadadr
, caddar
, cadddr
, cdaaar
,
cdaadr
, cdadar
, cdaddr
, cddaar
,
cddadr
, cdddar
, and cddddr
are defined this way.
C function of 3 arguments.
C function of 2 arguments.
transitive relational predicate C function of 2 arguments. The C
function should return either BOOL_T
or BOOL_F
.
C function of one optional argument. If the optional argument is not
present, UNDEFINED
is passed in its place.
C function of 1 required and 1 optional argument. If the optional
argument is not present, UNDEFINED
is passed in its place.
C function of 2 arguments and a list of (rest of) SCM
arguments.
C function of list of SCM
arguments.
A ptob is a port object, capable of delivering or accepting characters. See Ports in Revised(4) Report on the Algorithmic Language Scheme. Unlike the types described so far, new varieties of ptobs can be defined dynamically (see section Defining Ptobs). These are the initial ptobs:
input port.
output port.
input-output port.
input pipe created by popen()
.
output pipe created by popen()
.
String port created by cwos()
or cwis()
.
Software (virtual) port created by mksfpt()
(see section Soft Ports).
Returns non-zero if x is a port, open port, open input-port, open output-port, input-port, or output-port, respectively.
Returns non-zero if port x is open or closed, respectively.
Returns the FILE *
stream for port x.
Ports which are particularly well behaved are called fports.
Advanced operations like file-position
and reopen-file
only work for fports.
Returns non-zero if x is a port, open port, open input-port, or open output-port, respectively.
A smob is a miscellaneous datatype. The type code and GCMARK bit
occupy the lower order 16 bits of the CAR
half of the cell. The
rest of the CAR
can be used for sub-type or other information.
The CDR
contains data of size long and is often a pointer to
allocated memory.
Like ptobs, new varieties of smobs can be defined dynamically (see section Defining Smobs). These are the initial smobs:
unused cell on the freelist.
single-precision float.
Inexact number data types are subtypes of type tc16_flo
. If the
sub-type is:
CDR
.
CDR
is a pointer to a malloc
ed double.
CDR
is a pointer to a malloc
ed pair of doubles.
double-precision float.
double-precision complex.
positive and negative bignums, respectively.
Scm has large precision integers called bignums. They are stored in
sign-magnitude form with the sign occuring in the type code of the SMOBs
bigpos and bigneg. The magnitude is stored as a malloc
ed array
of type BIGDIG
which must be an unsigned integral type with size
smaller than long
. BIGRAD
is the radix associated with
BIGDIG
.
made by DELAY. See Control features in Revised(4) Scheme.
synchronization object. See section Process Synchronization.
macro expanding function. See section Low Level Syntactic Hooks.
multi-dimensional array. See section Arrays.
This type implements both conventional arrays (those with arbitrary data as elements see section Conventional Arrays) and uniform arrays (those with elements of a uniform type see section Uniform Array).
Conventional Arrays have a pointer to a vector for their CDR
.
Uniform Arrays have a pointer to a Uniform Vector type (string, bvect,
ivect, uvect, fvect, dvect, or cvect) in their CDR
.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
IMMEDIATE: B,D,E,F=data bit, C=flag code, P=pointer address bit ................................ inum BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB10 ichr BBBBBBBBBBBBBBBBBBBBBBBB11110100 iflag CCCCCCC101110100 isym CCCCCCC001110100 IMCAR: only in car of evaluated code, cdr has cell’s GC bit ispcsym 000CCCC00CCCC100 iloc 0DDDDDDDDDDDDDDDEFFFFFFF11111100 pointer PPPPPPPPPPPPPPPPPPPPPPPPPPPPP000 gloc PPPPPPPPPPPPPPPPPPPPPPPPPPPPP001 HEAP CELL: G=gc_mark; 1 during mark, 0 other times. 1s and 0s here indicate type. G missing means sys (not GC’d) SIMPLE: cons ..........SCM car..............0 ...........SCM cdr.............G closure ..........SCM code...........011 ...........SCM env.............G HEADERs: ssymbol .........long length....G0000101 ..........char *chars........... msymbol .........long length....G0000111 ..........char *chars........... string .........long length....G0001101 ..........char *chars........... vector .........long length....G0001111 ...........SCM **elts........... bvect .........long length....G0010101 ..........long *words........... spare G0010111 ivect .........long length....G0011101 ..........long *words........... uvect .........long length....G0011111 ......unsigned long *words...... spare G0100101 spare G0100111 fvect .........long length....G0101101 .........float *words........... dvect .........long length....G0101111 ........double *words........... cvect .........long length....G0110101 ........double *words........... contin .........long length....G0111101 .............*regs.............. cclo .........long length....G0111111 ...........SCM **elts........... SUBRs: spare 010001x1 spare 010011x1 subr_0 ..........int hpoff.....01010101 ...........SCM (*f)()........... subr_1 ..........int hpoff.....01010111 ...........SCM (*f)()........... cxr ..........int hpoff.....01011101 .........double (*f)().......... subr_3 ..........int hpoff.....01011111 ...........SCM (*f)()........... subr_2 ..........int hpoff.....01100101 ...........SCM (*f)()........... asubr ..........int hpoff.....01100111 ...........SCM (*f)()........... subr_1o ..........int hpoff.....01101101 ...........SCM (*f)()........... subr_2o ..........int hpoff.....01101111 ...........SCM (*f)()........... lsubr_2 ..........int hpoff.....01110101 ...........SCM (*f)()........... lsubr_2n..........int hpoff.....01110111 ...........SCM (*f)()........... rpsubr ..........int hpoff.....01111101 ...........SCM (*f)()........... PTOBs: port 0bwroxxxxxxxxG1110111 ..........FILE *stream.......... socket ttttttt 00001xxxxxxxxG1110111 ..........FILE *stream.......... inport uuuuuuuuuuU00011xxxxxxxxG1110111 ..........FILE *stream.......... outport 0000000000000101xxxxxxxxG1110111 ..........FILE *stream.......... ioport uuuuuuuuuuU00111xxxxxxxxG1110111 ..........FILE *stream.......... fport 00 00000000G1110111 ..........FILE *stream.......... pipe 00 00000001G1110111 ..........FILE *stream.......... strport 00 00000010G1110111 ..........FILE *stream.......... sfport 00 00000011G1110111 ..........FILE *stream.......... SMOBs: free_cell 000000000000000000000000G1111111 ...........*free_cell........000 flo 000000000000000000000001G1111111 ...........float num............ dblr 000000000000000100000001G1111111 ..........double *real.......... dblc 000000000000001100000001G1111111 .........complex *cmpx.......... bignum ...int length...0000001 G1111111 .........short *digits.......... bigpos ...int length...00000010G1111111 .........short *digits.......... bigneg ...int length...00000011G1111111 .........short *digits.......... xxxxxxxx = code assigned by newsmob(); promise 000000000000000fxxxxxxxxG1111111 ...........SCM val.............. arbiter 000000000000000lxxxxxxxxG1111111 ...........SCM name............. macro 000000000000000mxxxxxxxxG1111111 ...........SCM name............. array ...short rank..cxxxxxxxxG1111111 ............*array..............
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
7.2.1 Garbage Collection | Automatically reclaims unused storage | |
7.2.2 Signals | ||
7.2.3 C Macros | ||
7.2.4 Changing Scm | How to really screw it up | |
7.2.5 Defining Subrs | ||
7.2.6 Defining Smobs | ||
7.2.7 Defining Ptobs | ||
7.2.8 Calling Scheme From C | ||
7.2.9 Continuations | ||
7.2.10 Evaluation | Why SCM is fast |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The garbage collector is in the latter half of ‘sys.c’. Immediates always appear as parts of other objects, so they are not subject to explicit garbage collection. There is a heap (composed of heap segments) in which all cells reside. The storage for strings, vectors, continuations, doubles, complexes, and bignums is managed by malloc. There is only one pointer to each malloc object from its type-header cell in the heap. This allows malloc objects to be freed when the associated heap object is garbage collected.
To garbage collect, first certain protected objects are marked (such as
symhash). Then the stack (and marked continuations) are traversed.
Each longword in the stack is tried to see if it is a valid cell pointer
into the heap. If it is, the object itself and any objects it points to
are marked. If the stack is word rather than longword aligned
(#define WORD_ALIGN)
, both alignments are tried. This
arrangement will occasionally mark an object which is no longer used.
This has not been a problem in practice and the advantage of using the
c-stack far outweighs it.
The heap is then swept. If a type-header cell pointing to malloc space is collected the malloc object is then freed. If the type header of smob is collected, the smob’s free procedure is called to free its storage.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
(in ‘scm.c’) initializes handlers for SIGINT
and
SIGALRM
if they are supported by the C implementation. All of
the signal handlers immediately reestablish themselves by a call to
signal()
.
The low level handlers for SIGINT
and SIGALRM
.
If an interrupt handler is defined when the interrupt is received, the
code is interpreted. If the code returns, execution resumes from where
the interrupt happened. Call-with-current-continuation
allows
the stack to be saved and restored.
SCM does not use any signal masking system calls. These are not a
portable feature. However, code can run uninterrupted by use of the C
macros DEFER_INTS
and ALLOW_INTS
.
sets the global variable ints_disabled
to 1. If an interrupt
occurs during a time when ints_disabled
is 1 one of the global
variables sig_deferred
or alrm_deferred
is set to 1 and
the handler returns.
Checks the deferred variables and if set the appropriate handler is called.
Calls to DEFER_INTS
can not be nested. An ALLOW_INTS
must
happen before another DEFER_INTS
can be done. In order to check
that this constraint is satisfied #define CAREFUL_INTS
in
‘scmfig.h’.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
signals an error if the expression (cond) is 0. arg is the offending object, subr is the string naming the subr, and pos indicates the position or type of error. pos can be one of
ARGn
(> 5 or unknown ARG number)
ARG1
ARG2
ARG3
ARG4
ARG5
WNA
(wrong number of args)
OVFLOW
OUTOFRANGE
NALLOC
EXIT
HUP_SIGNAL
INT_SIGNAL
FPE_SIGNAL
BUS_SIGNAL
SEGV_SIGNAL
ALRM_SIGNAL
(char *)
Error checking is not done by ASSERT
if the flag RECKLESS
is defined. An error condition can still be signaled in this case with
a call to wta(arg, pos, subr)
.
goto
label if the expression (cond) is 0. Like
ASSERT
, ASRTGO
does is not active if the flag
RECKLESS
is defined.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
When writing C-code for SCM, a precaution is recommended. If your
routine allocates a non-cons cell which will not be incorporated
into a SCM
object which is returned, you need to make sure that a
SCM
variable in your routine points to that cell as long as part
of it might be referenced by your code.
In order to make sure this SCM
variable does not get optimized
out you can put this assignment after its last possible use:
SCM_dummy1 = foo;
or put this assignment somewhere in your routine:
SCM_dummy1 = (SCM) &foo;
SCM_dummy
variables are not currently defined. Passing the
address of the local SCM
variable to any procedure also
protects it.
Also, if you maintain a static pointer to some (non-immediate)
SCM
object, you must either make your pointer be the value cell
of a symbol (see errobj
for an example) or make your pointer be
one of the sys_protects
(see symhash
for an example). The
former method is prefered since it does not require any changes to the
SCM distribution.
To add a C routine to scm:
make_subr
or make_gsubr
call to init_scm
. Or
put an entry into the appropriate iproc
structure.
To add a package of new procedures to scm (see ‘crs.c’ for example):
static char s_twiddle_bits[]="twiddle-bits!"; static char s_bitsp[]="bits?";
iproc
structure for each subr type used in ‘foo.c’
static iproc subr3s[]= { {s_twiddle-bits,twiddle-bits}, {s_bitsp,bitsp}, {0,0} };
init_<name of file>
routine at the end of the file
which calls init_iprocs
with the correct type for each of the
iproc
s created in step 5.
void init_foo() { init_iprocs(subr1s, tc7_subr_1); init_iprocs(subr3s, tc7_subr_3); }
If your package needs to have a finalization routine called to
free up storage, close files, etc, then also have a line in
init_foo
like:
add_final(final_foo);
final_foo
should be a (void) procedure of no arguments. The
finals will be called in opposite order from their definition.
The line:
add_feature("foo");
will append a symbol 'foo
to the (list) value of
*features*
.
if
into ‘Init.scm’ which loads ‘Ifoo.scm’ if
your package is included:
(if (defined? twiddle-bits!) (load (in-vicinity (implementation-vicinity) "Ifoo" (scheme-file-suffix))))
or use (provided? 'foo)
instead of (defined?
twiddle-bits!)
if you have added the feature.
init_foo\(\)\;
to the INITS=…
line at the beginning of the makefile.
These steps should allow your package to be linked into SCM with a minimum of difficulty. Your package should also work with dynamic linking if your SCM has this capability.
Special forms (new syntax) can be added to scm.
MAKISYM
in ‘scm.h’ and increment
NUM_ISYMS
.
isymnames
in ‘repl.c’.
case:
clause to ceval()
near i_quasiquote
(in
‘eval.c’).
New syntax can now be added without recompiling SCM by the use of the
procedure->syntax
, procedure->macro
,
procedure->memoizing-macro
, and defmacro
. For details,
See section Syntax Extensions.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If CCLO is #define
d when compiling, the compiled closure
feature will be enabled. It is automatically enabled if dynamic linking
is enabled.
The SCM interpreter directly recognizes subrs taking small numbers of arguments. In order to create subrs taking larger numbers of arguments use:
returns a cclo (compiled closure) object of name char *
name which takes int
req required arguments,
int
opt optional arguments, and a list of rest arguments if
int
rest is 1 (0 for not).
SCM (*fcn)()
is a pointer to a C function to do the work.
The C function will always be called with req + opt +
rest arguments, optional arguments not supplied will be passed
UNDEFINED
. An error will be signaled if the subr is called with
too many or too few arguments. Currently a total of 10 arguments may be
specified, but increasing this limit should not be difficult.
/* A silly example, taking 2 required args, 1 optional, and a list of rest args */ SCM gsubr_21l(req1,req2,opt,rst) SCM req1,req2,opt,rst; { lputs("gsubr-2-1-l:\n req1: ", cur_outp); display(req1,cur_outp); lputs("\n req2: ", cur_outp); display(req2,cur_outp); lputs("\n opt: ", cur_outp); display(opt,cur_outp); lputs("\n rest: ", cur_outp); display(rst,cur_outp); newline(cur_outp); return UNSPECIFIED; } void init_gsubr211() { make_gsubr("gsubr-2-1-l", 2, 1, 1, gsubr_21l); }
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Here is an example of how to add a new type named foo
to SCM.
The following lines need to be added to your code:
long tc16_foo;
The type code which will be used to identify the new type.
static smobfuns foosmob = {markfoo,freefoo,printfoo,equalpfoo};
smobfuns is a structure composed of 4 functions:
typedef struct { SCM (*mark)P((SCM)); sizet (*free)P((CELLPTR)); int (*print)P((SCM exp, SCM port, int writing)); SCM (*equalp)P((SCM, SCM)); } smobfuns;
smob.mark
is a function of one argument of type SCM
(the cell to mark) and
returns type SCM
which will then be marked. If no further
objects need to be marked then return an immediate object such as
BOOL_F
. 2 functions are provided:
markcdr(ptr)
which marks the current cell and returns CDR(ptr)
.
mark0(ptr)
which marks the current cell and returns BOOL_F
.
smob.free
is a function of one argument of type CELLPTR
(the cell to
collected) and returns type sizet
which is the number of
malloc
ed bytes which were freed. Smob.free
should free
any malloc
ed storage associated with this object. The function
free0(ptr) is provided which does not free any storage and returns 0.
smob.print
is 0 or a function of 3 arguments. The first, of type SCM
, is
the smob object. The second, of type SCM
, is the stream on which
to write the result. The third, of type int, is 1 if the object should
be write
n, 0 if it should be display
ed. This function
should return non-zero if it printed, and zero otherwise (in which case
a hexadecimal number will be printed).
smob.equalp
is 0 or a function of 2 SCM
arguments. Both of these arguments
will be of type tc16foo
. This function should return
BOOL_T
if the smobs are equal, BOOL_F
if they are not. If
smob.equalp
is 0, equal?
will return BOOL_F
if they
are not eq?
.
tc16_foo = newsmob(&foosmob);
Allocates the new type with the functions from foosmob
. This
line goes in an init_
routine.
Promises and macros in ‘eval.c’ and arbiters in ‘repl.c’ provide examples of SMOBs. There are a maximum of 256 SMOBs.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
ptobs are similar to smobs but define new types of port to which
SCM procedures can read or write. The following functions are defined
in the ptobfuns
:
typedef struct { SCM (*mark)P((SCM ptr)); int (*free)P((FILE *p)); int (*print)P((SCM exp, SCM port, int writing)); SCM (*equalp)P((SCM, SCM)); int (*fputc)P((int c, FILE *p)); int (*fputs)P((char *s, FILE *p)); sizet (*fwrite)P((char *s, sizet siz, sizet num, FILE *p)); int (*fflush)P((FILE *stream)); int (*fgetc)P((FILE *p)); int (*fclose)P((FILE *p)); } ptobfuns;
The .free
component to the structure takes a FILE *
or
other C construct as its argument, unlike .free
in a smob, which
takes the whole smob cell. Often, .free
and .fclose
can be
the same function. See fptob
and pipob
in ‘sys.c’
for examples of how to define ptobs.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
To use SCM as a whole from another program call init_scm
or
run_scm
as is done in main()
in ‘scm.c’.
In order to call indivdual Scheme procedures from C code more is required; SCM’s storage system needs to be initialized. The simplest way to do this for a statically linked single-thread program is to:
#define RTL
flag when compiling ‘scm.c’ to elide
SCM’s main()
.
main()
, call run_scm
with arguments (argc
and argv
) to invoke your code’s startup routine.
For a dynamically linked single-thread program:
init_
procedure for your code which will set up any Scheme
definitions you need and then call your startup routine
(see section Changing Scm).
init_
procedure will be called, and
hence your startup routine.
Now use apply
(and perhaps intern
) to call Scheme
procedures from your C code. For example:
/* If this apply fails, SCM will catch the error */ apply(CDR(intern("srv:startup",sizeof("srv:startup")-1)), mksproc(srvproc), listofnull); func = CDR(intern(rpcname,strlen(rpcname))); retval = apply(func, cons(mksproc(srvproc), args), EOL);
SCM now has routines to make calling back to Scheme procedures easier:
Loads the Scheme source file file. Returns 0 if successful, non-0 if not. This function is used to load SCM’s initialization file ‘Init.scm’.
Loads the Scheme source file (in-vicinity (program-vicinity)
file)
. Returns 0 if successful, non-0 if not.
This function is useful for compiled code init_ functions to load
non-compiled Scheme (source) files. program-vicinity
is the
directory from which the calling code was loaded (see Vicinity in SLIB).
Returns the result of reading an expression from str and evaluating it.
Reads and evaluates all the expressions from str.
If you wish to catch errors during execution of Scheme code, then you can use a wrapper like this for your Scheme procedures:
(define (srv:protect proc) (lambda args (define result #f) ; put default value here (call-with-current-continuation (lambda (cont) (dynamic-wind (lambda () #t) (lambda () (set! result (apply proc args)) (set! cont #f)) (lambda () (if cont (cont #f)))))) result))
Calls to procedures so wrapped will return even if an error occurs.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The scm procedure call-with-current-continuation calls it’s argument
with an object of type contin
.
If CHEAP_CONTINUATIONS
is #defined (in ‘scmfig.h’) the
contin just contains a jmp_buf. When the contin is applied, a longjmp
of the jmp_buf is done.
If CHEAP_CONTINUATIONS
is not #defined the contin contains the
jmp_buf and a copy of the C stack between the call_cc stack frame and
BASE(rootcont). When the contin is applied:
On systems with nonlinear stack disciplines (multiple stacks or
non-contiguous stack frames) copying the stack will not work properly.
These systems need to #define CHEAP_CONTINUATIONS
in
‘scmfig.h’.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Top level symbol values are stored in the symhash
table.
symhash
is an array of lists of ISYMs and pairs of symbols and
values.
Whenever a symbol’s value is found in the local environment the pointer to the symbol in the code is replaced with an immediate object (ILOC) which specifies how many environment frames down and how far in to go for the value. When this immediate object is subsequently encountered, the value can be retrieved quickly.
Pointers to symbols not defined in local environments are changed to one
plus the value cell address in symhash. This incremented pointer is
called a GLOC. The low order bit is normally reserved for GCmark; But,
since references to variables in the code always occur in the CAR
position and the GCmark is in the CDR
, there is no conflict.
If the compile FLAG CAUTIOUS
is #defined then the number of
arguments is always checked for application of closures. If the
compile FLAG RECKLESS
is #defined then they are not checked.
Otherwise, number of argument checks for closures are made only when
the function position (whose value is the closure) of a combination is
not an ILOC or GLOC. When the function position of a combination is a
symbol it will be checked only the first time it is evaluated because
it will then be replaced with an ILOC or GLOC.
EVAL
Returns the result of evaluating expression in
env. SIDEVAL
evaluates expression in env when
the value of the expression is not used.
Both of these macros alter the list structure of expression as it
is memoized and hence should be used only when it is known that
expression will not be referenced again. The C function
eval
is safe from this problem.
Returns the result of evaluating expression in the top-level
environment. eval
copies expression
so that memoization
does not modify expression
.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
lgcd()
needs to generate at most one bignum, but currently
generates more.
divide()
could use shifts instead of multiply and divide when
scaling.
UNDEFINED
which have no pointers to them can be
collected. In Maclisp this was called gctwa
.
malloc
ed objects by freeing and
reallocing all the malloc objects encountered in a scan of the heap.
Whether compactions would actually occur is system depenedent.
ILOC
s)
when it retrieves environments deeper or longer than 4095. The values
can still be retrieved (albeit slowly), but an ILOC
should not be
made. The MEMOIZE_LOCALS
flag could then be flushed.
must-
or make-
routines need some sort of C macros or
conditionalization so that they check:
LENGTH
field fits into a size_t
(as is checked
now) for platforms with (sizeof(size_t) < sizeof(SCM))
.
LENGTH
field fits into 24 (or 56) bits on machines where
size_t
is 32 bits or more.
This is trickier than it first looks because the must_malloc() routine
is also used for allocating heap segments, which do not have the
LENGTH
field restriction. Putting the 24 bit test into
must_malloc()
should be tested for speed impact.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Scott Schwartz <schwartz@galapagos.cse.psu.edu> suggests: One way to tidy up the dynamic loading stuff would be to grab the code from perl5.
George Carrette (gjc@mitech.com) outlines how to dynamically link on VMS. There is already some code in ‘dynl.c’ to do this, but someone with a VMS system needs to finish and debug it.
main() {init_lisp(); lisp_repl();}
eval.c
and there are some toplevel non-static variables in use
called the_heap
, the_environment
, and some read-only
toplevel structures, such as the_subr_table
.
$ LINK/SHARE=LISPRTL.EXE/DEBUG REPL.OBJ,GC.OBJ,EVAL.OBJ,LISPRTL.OPT/OPT
SYS$LIBRARY:VAXCRTL/SHARE UNIVERSAL=init_lisp UNIVERSAL=lisp_repl PSECT_ATTR=the_subr_table,SHR,NOWRT,LCL PSECT_ATTR=the_heap,NOSHR,LCL PSECT_ATTR=the_environment,NOSHR,LCL
Notice: The psect (Program Section) attributes.
LCL
means to keep the name local to the shared library. You almost always want to do that for a good clean library.
SHR,NOWRT
means shared-read-only. Which is the default for code, and is also good for efficiency of some data structures.
NOSHR,LCL
is what you want for everything else.
Note: If you do not have a handy list of all these toplevel variables, do not dispair. Just do your link with the /MAP=LISPRTL.MAP/FULL and then search the map file,
$SEARCH/OUT=LISPRTL.LOSERS LISPRTL.MAP ", SHR,NOEXE, RD, WRT"
And use an emacs keyboard macro to muck the result into the proper form. Of course only the programmer can tell if things can be made read-only. I have a DCL command procedure to do this if you want it.
$ DEFINE LISPRTL USER$DISK:[JAFFER]LISPRTL.EXE $LINK MAIN.OBJ,SYS$INPUT:/OPT SYS$LIBRARY:VAXCRTL/SHARE LISPRTL/SHARE
Note the definition of the LISPRTL
logical name. Without such a
definition you will need to copy ‘LISPRTL.EXE’ over to
‘SYS$SHARE:’ (aka ‘SYS$LIBRARY:’) in order to invoke the main
program once it is linked.
INIT_MYSUBRS
that must be called before using it.
$ CC MYSUBRS.C $ LINK/SHARE=MYSUBRS.EXE MYSUBRS.OBJ,SYS$INPUT:/OPT SYS$LIBRARY:VAXCRTL/SHARE LISPRTL/SHARE UNIVERSAL=INIT_MYSUBRS
Ok. Another hint is that you can avoid having to add the PSECT
declaration of NOSHR,LCL
by declaring variables status
in
the C language source. That works great for most things.
{void (*init_fcn)(); long retval; retval = lib$find_image_symbol("MYSUBRS","INIT_MYSUBRS",&init_fcn, "SYS$DISK:[].EXE"); if (retval != SS$_NORMAL) error(…); (*init_fcn)();}
But of course all string arguments must be (struct dsc$descriptor
*)
and the last argument is optional if MYSUBRS
is defined as a
logical name or if ‘MYSUBRS.EXE’ has been copied over to
‘SYS$SHARE’. The other consideration is that you will want to turn
off <C-c> or other interrupt handling while you are inside most
lib$
calls.
As far as the generation of all the UNIVERSAL=…
declarations. Well, you could do well to have that automatically
generated from the public ‘LISPRTL.H’ file, of course.
VMS has a good manual called the Guide to Writing Modular
Procedures or something like that, which covers this whole area rather
well, and also talks about advanced techniques, such as a way to declare
a program section with a pointer to a procedure that will be
automatically invoked whenever any shared image is dynamically
activated. Also, how to set up a handler for normal or abnormal program
exit so that you can clean up side effects (such as opening a database).
But for use with LISPRTL
you probably don’t need that hair.
One fancier option that is useful under VMS for ‘LISPLIB.EXE’ is to
define all your exported procedures through an call vector instead
of having them just be pointers into random places in the image, which
is what you get by using UNIVERSAL
.
If you set up the call vector thing correctly it will allow you to modify and relink ‘LISPLIB.EXE’ without having to relink programs that have been linked against it.
George Carrette (gjc@mitech.com) outlines how to dynamically link on Windows NT:
LISPLIB.exp: LISPLIB.lib: LISPLIB.def $(implib) -machine:$(CPU) -def:LISPLIB.def -out:LISPLIB.lib LISPLIB.DLL : $(LISPLIB_OBJS) LISPLIB.EXP $(link) $(linkdebug) \ -dll \ -out:LISPLIB.DLL \ LISPLIB.EXP $(LISPLIB_OBJS) $(conlibsdll)
LIBRARY lisplib EXPORT init_lisp init_repl
CLINK = $(link) $(ldebug) $(conflags) -out:$*.exe $** $(conlibsdll) MAIN.EXE : MAIN.OBJ LISPLIB.LIB $(CLINK)
mysubrs.exp: mysubrs.lib: mysubrs.def $(implib) -machine:$(CPU) -def:MYSUBRS.def -out:MYSUBRS.lib mysubrs.dll : mysubrs.obj mysubrs.exp mysubrs.lib $(link) $(linkdebug) \ -dll \ -out:mysubrs.dll \ MYSUBRS.OBJ MYSUBRS.EXP LISPLIB.LIB $(conlibsdll)
LIBRARY mysubrs EXPORT INIT_MYSUBRS
LoadLibrary
and GetProcAddress
.
LISP share_image_load(LISP fname) {long iflag; LISP retval,(*fcn)(void); HANDLE hLib; DWORD err; char *libname,fcnname[64]; iflag = nointerrupt(1); libname = c_string(fname); _snprintf(fcnname,sizeof(fcnname),"INIT_%s",libname); if (!(hLib = LoadLibrary(libname))) {err = GetLastError(); retval = list2(fname,LSPNUM(err)); serror1("library failed to load",retval);} if (!(fcn = (LISP (*)(void)) GetProcAddress(hLib,fcnname))) {err = GetLastError(); retval = list2(fname,LSPNUM(err)); serror1("could not find library init procedure",retval);} retval = (*fcn)(); nointerrupt(iflag); return(retval);}
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This is an alphabetical list of all the procedures and macros in SCM.
Jump to: | #
$
-
@
_
A B C D E F G H I K L M N O P Q R S T U V W |
---|
Jump to: | #
$
-
@
_
A B C D E F G H I K L M N O P Q R S T U V W |
---|
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This is an alphabetical list of all the global variables in SCM.
Jump to: | *
A B E H I L M N O S U |
---|
Jump to: | *
A B E H I L M N O S U |
---|
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This is an alphabetical list of all the data types in SCM.
Jump to: | C G I S T |
---|
Jump to: | C G I S T |
---|
[Top] | [Contents] | [Index] | [ ? ] |
[Top] | [Contents] | [Index] | [ ? ] |
This document was generated on November 5, 2024 using texi2html 5.0.
The buttons in the navigation panels have the following meaning:
Button | Name | Go to | From 1.2.3 go to |
---|---|---|---|
[ << ] | FastBack | Beginning of this chapter or previous chapter | 1 |
[ < ] | Back | Previous section in reading order | 1.2.2 |
[ Up ] | Up | Up section | 1.2 |
[ > ] | Forward | Next section in reading order | 1.2.4 |
[ >> ] | FastForward | Next chapter | 2 |
[Top] | Top | Cover (top) of document | |
[Contents] | Contents | Table of contents | |
[Index] | Index | Index | |
[ ? ] | About | About (help) |
where the Example assumes that the current position is at Subsubsection One-Two-Three of a document of the following structure:
This document was generated on November 5, 2024 using texi2html 5.0.