define-namespace/README.rst

52 lines
1.1 KiB
ReStructuredText
Raw Normal View History

2024-07-29 14:01:20 -04:00
================
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.