Working with Libraries¶
Importing Standard Libraries¶
Every R7RS program starts by importing what it needs:
Multiple imports can be combined:
Import Modifiers¶
;; Import only specific names — the names must be exports of that
;; library ((scheme base) has map but not filter, which is SRFI-1)
(import (only (scheme base) map for-each))
;; Import everything except certain names
(import (except (scheme base) error))
;; Rename on import
(import (rename (scheme base) (map scheme-map)))
;; Add a prefix to all imported names
(import (prefix (scheme char) char:))
(char:char-alphabetic? #\A) ;=> #t
Available Libraries¶
Kaappi includes all 14 R7RS standard libraries, 178 SRFIs (12 built-in, 162 portable, three sub-library-only, plus the SRFI 261 naming convention), and four Kaappi extension libraries.
Standard R7RS Libraries (16)¶
| Library | Exports | Description |
|---|---|---|
(scheme base) |
230+ | Core procedures and syntax |
(scheme case-lambda) |
1 | case-lambda syntax |
(scheme char) |
22 | Unicode character operations |
(scheme complex) |
6 | Complex number procedures |
(scheme cxr) |
28 | Car/cdr compositions (3 and 4 deep) |
(scheme eval) |
3 | eval, environment, interaction-environment |
(scheme file) |
10 | File I/O |
(scheme inexact) |
12 | Transcendental math (sin, cos, exp, log, ...) |
(scheme lazy) |
5 | delay, force, promises |
(scheme load) |
1 | load |
(scheme process-context) |
5 | exit, command-line, environment variables |
(scheme r5rs) |
141 | The R5RS identifier set, with exact->inexact / inexact->exact under their R5RS names |
(scheme read) |
1 | read |
(scheme repl) |
1 | interaction-environment |
(scheme time) |
3 | current-second, jiffies |
(scheme write) |
7 | write, display, write-shared |
SRFI Libraries (178)¶
See the SRFI Support page for the complete list of all 178 supported SRFIs, built-in and portable.
Kaappi Extension Libraries¶
| Library | Description |
|---|---|
(kaappi ffi) |
Foreign function interface (ffi-open, ffi-fn, ffi-callback, ffi-close) |
(kaappi fibers) |
Green threads (spawn, yield, fiber-join, channels) |
(kaappi parallel) |
Worker pools and parallel map over OS threads (make-pool, pool-submit, parallel-map) |
(kaappi diagnostics) |
Stable KP diagnostic codes on error objects (error-object-code) |
Writing Your Own Library¶
Define libraries with define-library in .sld files. The
Library Authoring guide covers the full syntax:
export specifications, include, cond-expand, file naming, bytecode
caching, and organization tips.
Library Search Paths¶
Kaappi searches for .sld files in this order:
- The current directory (
./) - The
./lib/subdirectory - Directories specified with
--lib-path
The library name (mylib math) maps to the file path mylib/math.sld.
Next: Library Authoring