;;;=============================================================================== ;;; ;;; R6RS Macros and R6RS libraries: ;;; ;;; Copyright (c) 2006 Andre van Tonder ;;; ;;; Copyright statement at srfi.schemers.org/srfi-process.html ;;; ;;;=============================================================================== ---------------------------------------------------------------------- TO RUN TESTS : execute macros-test.scm ---------------------------------------------------------------------- Tested on MzScheme and Petite Chez (for the latter, simply change define-struct -> define-record). Uses following non-r5rs properties and constructs: * assumes left-to-right evaluation of internal defines in "let". * interaction-environment eval * define-struct * records generated by define-struct must be disjoint from vectors * parameterize * let-values * pretty-print COMPATIBILITY WITH R6RS: ------------------------ SYNTAX-CASE: * PERMITTED : We use a renaming algorithm instead of the mark-antimark algorithm described in the draft. The difference will not matter for r6rs-conforming macros. * PERMITTED? : A wrapped syntax object is the same as an unwrapped syntax object, and can be directly manipulated using car, cdr, ... without syntax-case deconstruction. Do not use this feature in portable macros. * CORRECTION : R(5.91)RS assigned a lexical-scope-violating semantics to many Scheme expressions. This expander instead follows the the following specification: It is a syntax violation if an identifier whose meaning is needed during the left-to-right expansion of definitions is subsequently redefined by a definition in the same body. To detect this error, the expander records each identifier reference occurring during expansion of the body. Before an identifier is bound, its current binding is compared against bindings already referenced for the same (in the sense of bound-identifier=?) identifier during the expansion of the definitions. If a match is found, the binding may have already affected the expansion of the body, and a syntax violation is therefore thrown. For many examples of this issue, see macros-test.scm LIBRARIES: * PERMITTED : Phase semantics: The following phase semantics guarantees that there is no difference between compiling and executing libraries all in the same run-time system instance, and compiling libraries in separate instances of the run-time system. - Each library form or program is expanded in a fresh environment. - Each program is run in a fresh environment. * PERMITTED : Phase semantics: - Expand-time bindings are shared between the meta-levels into which they are imported. - A syntax violation is raised if a binding is used outside its declared levels. - Instantiation semantics described below. * EXTENSION : A traditional REPL is provided. Libraries can be defined at and imported into the REPL toplevel. See macros-test.scm. * TODO : Exceptions are not currently raised if exported variables are set! or if set! variables are indirectly exported INSTANTIATION SEMANTICS: ------------------------ During expansion of a library or program, all variable bindings and body expressions in libraries imported directly or indirectly at level n > 0, and all syntax definitions in libraries imported directly or indirectly at level n >= 0 relative to the library or program being expanded, are evaluated once. The order of these evaluations respects any dependencies established by the import declarations. During invocation of a program, all variable bindings and body expressions in libraries imported directly or indirectly at level 0 are evaluated once. The order of these evaluations respects any dependencies established by the import declarations. CHANGES SINCE VERSION OF DECEMBER 25, 2006: ------------------------------------------- - corrected bug in phase shift enforcement while visiting and invoking, which affected behaviour of syntax forms evaluated in a library's top-level expand-time or runtime sequence. - (r6rs base) now also exports ... and _ for use with syntax-rules. CHANGES SINCE VERSION OF DECEMBER 17, 2006: ------------------------------------------- - dropped unshared instantiation option, keeping only shared semantics. - corrected export phase of syntax-rules and identifier-syntax in (r6rs base). These are now exported for expand instead of for run. - simplified documentation in readme. CHANGES SINCE VERSION OF DECEMBER 14, 2006: ------------------------------------------- - removed support for declarations - changed script -> program everywhere - changed add-prefix -> prefix everywhere - dropped the unparenthesized shorthand for library names - changed forall -> for-all everywhere - fenders have been removed from syntax-rules - added "identifier-syntax" to (r6rs base) CHANGES SINCE VERSION OF NOVEMBER 27, 2006: ------------------------------------------- - Corrected implementation and description of invocation semantics and its interaction with negative import levels. CHANGES SINCE VERSION OF NOVEMBER 5, 2006: ------------------------------------------ - Added UNSHARED semantics (see above) as a configurable option. CHANGES SINCE VERSION OF SEPTEMBER 13, 2006: -------------------------------------------- - Added support for scripts. - Quasisyntax now works with unsyntax(-splicing) instead of unquote(-splicing). - Many bug fixes and improvements in code. - Reorganized standard libraries. - Properly avoids defect in R(5.91)RS assigning lexical scope violating semantics to certain expressions. - Implemented library reference syntax.