This egg provides support for most of the R7RS Scheme language.
It is still under construction and should be considered subject to change.
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 -require-extension r7rs foo.scm
This is equivalent to beginning your program with (require-extension 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 (require-extension 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 -extend r7rs -require-extension 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. (use r7rs) (define-library (foo bar) (import (scheme base)) (export baz) (begin (define baz 1)))
When the r7rs extension is loaded, it overrides CHICKEN's built-in import and import-for-syntax forms with versions that support the R7RS's library syntax.
As such, r7rs's import expects library names to be lists rather than single identifiers (as with library definitions). It also does the dual duty of both importing identifiers and loading code, which makes it more akin to CHICKEN's require-extension (a.k.a. use) than the built-in import form.
;; Without the r7rs extension, import loads identifiers but not the underlying implementation: (import (only (files) pathname-file)) (pathname-file "foo/bar/baz") ; => Error: unbound variable: pathname-file ;; After loading the r7rs extension, import does both: (require-extension r7rs) (import (only (files) pathname-file)) (pathname-file "foo/bar/baz") ; => "baz"
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.
(use 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
- Colon-terminated hex values in symbols and strings are not recognized, and will be treated incorrectly if used.
- define-values with improper lambda lists
- The current implementation of define-values supports only proper lists in its binding form.
- 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
Copyright (c) 2013-2014 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.