Libraries
The twelve R7RS libraries a file may import, and what each provides. Every name has its
own page in the Reference. A file that opens with (import ...) (see
Syntax) sees only the libraries it names; a file with none sees all twelve,
plus the Structure and Interpretation of Computer Programs (SICP)-compatibility names.
| Library | Provides |
|---|---|
| (scheme base) | The core: numbers, booleans, pairs and lists, symbols, characters, strings, vectors, bytevectors, control, exceptions, ports -- string and bytevector ports, the current ports -- and input and output; its syntax is on Syntax |
| (scheme write) | display and write |
| (scheme read) | read |
| (scheme char) | Unicode character classes, case mappings and case-insensitive comparisons |
| (scheme inexact) | Transcendental functions and the float predicates |
| (scheme cxr) | The three- and four-deep car/cdr compositions |
| (scheme lazy) | Promises |
| (scheme case-lambda) | case-lambda |
| (scheme process-context) | exit and emergency-exit only |
| (scheme eval) | eval and environment -- see eval |
| (scheme repl) | interaction-environment |
| (scheme file) | File ports, file-exists? and delete-file |
Every input and output procedure takes an optional port argument and uses the current
port without one. The current ports are parameter objects, so parameterize redirects
them. A file port is opened on a file name -- see (scheme file).
"captured (1 \"two\")"
((a b) 42 #t)
500000500000
4
3
Printing
write and display write a circular list or vector with datum labels,
#0=(a b c . #0#); structure shared without a cycle is written out each time.
An exact argument with an exact answer stays exact, and a flonum prints positionally
below 1e21 and with an exponent from there (and below 1e-6):
(4 1/2 1.4142135623730951 1 0)
(123456789.123 1e21 0.000001 1.5e-7 +inf.0)
Libraries of your own
A program splits into libraries with define-library: at the
beginning of the file, before its imports, or in a file of its own that
(import (shapes circle)) finds as shapes/circle.sld beside the program. A library's
names are private unless it exports them. include puts a file's
contents where it stands; both are read when the program is, so a compiled program needs
none of the files at run time.
; file: shapes/circle.sld
(define-library (shapes circle)
(export area)
(import (scheme base))
(begin
(define pi 314/100)
(define (area r) (* pi r r))))
(314 3)
Features
cond-expand picks code by the features of the implementation and the libraries it has, when the program is read: a program written for several Scheme systems runs here, and the branches it does not take are never compiled.
rontolisp