Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

r7rs

  1. Outdated egg!
  2. r7rs
    1. Description
      1. Repository
      2. Requirements
    2. Usage
      1. Compiling
      2. Libraries
        1. Import
        2. Inclusion
        3. Conditional expansion
      3. Macros
    3. Limitations
      1. Unsupported features
      2. Case folding
      3. Procedure names
      4. Library loading
      5. Libraries
        1. scheme char
        2. scheme r5rs
    4. Examples
      1. Compilation
    5. About
      1. Maintainers
      2. History
      3. License

Description

This egg provides support for most of the R7RS Scheme language.

It is still under construction and should be considered subject to change.

Repository

git://code.call-cc.org/chicken-r7rs

Requirements

CHICKEN version 4.9.0 or higher, and the following extensions:

Usage

To add R7RS support to a program, load the r7rs extension:

(require-extension r7rs)

This makes most features of the R7RS available, and immediately imports all identifiers from the (scheme base) library.

Compiling

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

Libraries

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)))
Import

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"
Inclusion

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.

Conditional expansion

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)))

Macros

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

Limitations

Unsupported features

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.
equal?
The R7RS requires that equal? terminate when given cyclic data, however the current implementation may enter an infinite loop.

Case folding

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.

Procedure names

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.

Library loading

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.

Libraries

scheme char

The procedures exported by the (scheme char) library are not unicode-aware.

scheme r5rs

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.

Examples

Compilation

$ 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

About

Maintainers

The CHICKEN Team

History

0.0.6
Export exp and truncate; drop export of nonexistent infinite? from scheme.inexact with no-numbers
0.0.5
Limit implicit imports in libraries to "meta language" (thanks to John J. Foerch)
0.0.4
Fix invalid import warnings
0.0.3
Add read and write hooks
0.0.2
More complete libraries
0.0.1
Prerelease

License

Copyright (c) 2013-2016 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.