This egg provides support for most of the R7RS Scheme language.
CHICKEN version 5.0 or newer, and the following extensions:
To add R7RS support to a program, load the r7rs extension:
This makes most features of the R7RS available, and immediately imports all identifiers from the (scheme base) library.
To compile R7RS code, it's usually sufficient to load the r7rs extension by providing the -require-extension (or -R) flag to csc(1):
$ csc -R r7rs foo.scm
This is equivalent to beginning your program with (import (r7rs)), but avoids the need to modify your source with CHICKEN-specific forms. Alternatively, you can cond-expand on the extension to load it only when your program is running on CHICKEN:
(cond-expand (r7rs) (chicken (import (r7rs))))
Some syntactic features of the R7RS, such as long-form booleans and extended number literals, require that r7rs support be activated during compilation. To do this, load the r7rs egg as a compiler extension by providing the -extend (or -X) flag to csc(1), as well:
$ csc -X r7rs -R r7rs foo.scm
R7RS library forms are converted into standard CHICKEN modules at compile time. During this conversion, R7RS library names (which are proper lists rather than simple identifiers) are mapped to module names by joining their components with periods. Thus, the following programs are roughly equivalent:
;; A standard CHICKEN module. (module (foo bar) (baz) (import scheme) (define baz 1))
;; An R7RS library definition. (import (r7rs)) (define-library (foo bar) (import (scheme base)) (export baz) (begin (define baz 1)))
Include forms within library definitions (include, include-ci, and include-library-declarations) search for files relatively to the including file, as well as on the standard include path.
The include form provided by the (scheme base) also includes files relatively, but only when used at the top level.
The (library ...) feature test of the (scheme base) library's cond-expand form searches for the specified library amongst all currently-loaded modules, any import files in the current directory, and any libraries registered in CHICKEN's extensions repository. Refer to the CHICKEN manual for more information about import files and extensions.
(import (r7rs)) (define spiffy-installed? (cond-expand ((library (spiffy)) #t) (else #f)))
The r7rs extension's syntax-rules behaves slightly differently than that of CHICKEN proper in a few edge cases. Specifically, it treats undercores as wildcards and allows ellipses within syntax templates to be escaped with (... <template>).
To use the r7rs extension's version of syntax-rules, it must be imported at macro expansion time with import-for-syntax:
(import-for-syntax (r7rs)) ; Load r7rs's syntax-rules at expansion time. (define-syntax be-like-begin (syntax-rules () ((be-like-begin name) (define-syntax name (syntax-rules () ((name expr (... ...)) (begin expr (... ...)))))))) (be-like-begin sequence) (sequence 1 2 3 4) ; => 4
The following features are currently unsupported:
- \x...; escaped characters
- Semicolon-terminated hex values in symbols and strings are not recognized, and will be treated incorrectly if used.
- export renaming
- Export forms with renaming, as in (export (rename foo bar)), currently signal an error.
- The R7RS requires that equal? terminate when given cyclic data, however the current implementation may enter an infinite loop.
The #!fold-case and #!no-fold-case directives are only supported when the (scheme read) library has been loaded. Use of these directives without first importing (scheme read) will signal an error.
Because the r7rs egg reexports some procedures directly from CHICKEN core under different identifiers, r7rs procedure names (as accessed by procedure-information) may not always be correct.
Some implementations treat library name components as filesystem paths and attempt to load the library (foo bar baz) from the file "foo/bar/baz.scm", for example. This egg does not.
Some implementations use the ".sld" file extension for files containing R7RS library definitions. This egg currently provides no special support for such files.
The procedures exported by the (scheme char) library are not Unicode-aware.
The (scheme r5rs) library exports the R5RS versions of many identifiers. As such, some of its procedures are incompatible with their R7RS versions, and an unqualified import of the (scheme r5rs) library will overwrite those R7RS versions and lead to subtle problems.
$ cat foo.bar.scm (define-library (foo bar) (import (scheme base)) (export baz) (begin (define baz 1))) $ csc -X r7rs -R r7rs -sJ -o foo.bar.so foo.bar.scm $ cat program.scm (import (foo bar) (scheme write)) (display baz) (display #\newline) $ csc -X r7rs -R r7rs program.scm $ ./program 1
The CHICKEN Team
This egg is hosted on the CHICKEN Subversion repository:
If you want to check out the source code repository of this egg and you are not familiar with Subversion, see this page.
- Fix egg dependency list (see https://lists.nongnu.org/archive/html/chicken-hackers/2021-04/msg00023.html for more info)
- Fix invalid use of obsolete internal library procedure, use proper slot for building environments (thanks to Lukas Boeger)
- Enable static linking
- Port to CHICKEN 5
- Export exp and truncate; drop export of nonexistent infinite? from scheme.inexact with no-numbers
- Limit implicit imports in libraries to "meta language" (thanks to John J. Foerch)
- Fix invalid import warnings
- Add read and write hooks
- More complete libraries
Copyright (c) 2013-2020 The CHICKEN Team Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the authors may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.