R5RS portable library for a subset of R7RS define-library
Go to file
Peter McGoron c18bee846d aatree and linked-list 2024-07-29 21:18:46 -04:00
examples aatree and linked-list 2024-07-29 21:18:46 -04:00
srfi aatree and linked-list 2024-07-29 21:18:46 -04:00
README.rst aatree and linked-list 2024-07-29 21:18:46 -04:00
define-namespace-5.scm aatree and linked-list 2024-07-29 21:18:46 -04:00
define-namespace-7.scm define-namespace and SRFI-1 2024-07-29 14:01:20 -04:00

README.rst

================
define-namespace
================

DEFINE-NAMESPACE is an R5RS macro that implements a subset of R7RS's
DEFINE-LIBRARY.

-----
Usage
-----

Syntax::

    (define-namespace namespace-name [DECL list])

    DECL ::= (define defbody ...)
           | (export [identifier list])
           | (import [IMPORTSPEC list])

    IMPORTSPEC ::= (only ns [identifier list])
               ::= (rename ns [(identifier identifier) list]

    (import-from-namespace [IMPORTSPEC list])

Example::

    (define-namespace ns
      (define param 5)
      (define (f x) (* 5 x))
      (export f))

    (define-namespace ns2
      (import (rename ns (f g)))
      (define (f x) (* 5 (g x)))
      (export f))

    (import-from-namespace (only ns2 f))

    (f 17)

---------------------
Differences from R7RS
---------------------

* There are only EXPORT, IMPORT, and BEGIN statements.
* DEFINE-SYNTAX does not work.
* EXPORT statements must occur after DEFINEs.
* IMPORT only allows for ONLY and RENAME clauses.
* Namespace names are identifers, not lists.
* Namespaces are Scheme objects.
* To import outside of namespaces, use IMPORT-FROM-NAMSPACE, not IMPORT.

--------
Examples
--------

* ``srfi/srfi-1.scm`` is the reference implementation of SRFI-1 wrapped in
  a namespace.
* ``examples/aatree.scm`` is an imperative binary tree implementation.
  ``examples/test-aatree.scm`` uses SRFI-64 to run some tests on the
  implementation. Requires SRFI-9 and SRFI-11 (``let-values``).