-
-
Notifications
You must be signed in to change notification settings - Fork 648
Commit
provide
and require
The intent of this change is to better support languages besides plain Racket where multiple binding spaces (within a phase) makes sense. The existing `make-interned-syntax-introducer` function supports a binding-space convention where a scope (keyed on a symbol name) can be used consistently across modules to create bindings with that scope. This commit adds more direct support for binding spaces to `require` and `provide`. A `for-space` form allows a module to provide a binding in a space, and then `require` will (by default) create a binding in an importing context using the space's scope. The changes to `require` and `provide` are mostly internal, but the result of a function like `identfier-binding` might need to include require/provide space information as well as require/provide phase information. To minimize changes to existing code, space information is combined with phase information in a single value, and the default space (i.e., no extra space scope) is represented by just using the phase value. In other words, the representation of import and export information is unchanged unless binding spaces are specifically used. Require and provide transformers similarly need to change to work with binding spaces, but existing transformers continue to work as long as they are not combined with binding-space operations. The representation for combined phase and space information is supported by a new `racket/phase+space` library, which provides functions like `phase+space?`. Using "phase+space" seems a bit on the nose, but after trying alternatives and considering that further extensions seem unlikely, I ended up preferring "phase+space".
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#lang scribble/doc | ||
@(require "mz.rkt" | ||
(for-label racket/phase+space)) | ||
|
||
@title[#:tag "phase+space"]{Phase and Space Utilities} | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mflatt
Author
Member
|
||
|
||
@note-lib-only[racket/phase+space] | ||
|
||
The @racketmodname[racket/phase+space] library provides functions for | ||
manipulating combined representations of @tech{phase levels} and | ||
@tech{binding spaces}, particularly as used for @tech{require | ||
transformers} and @tech{provide transformers}. | ||
|
||
When @racket[identifier-binding] (and related functions, like | ||
@racket[identifier-transformer-binding]), | ||
@racket[syntax-local-module-exports], | ||
@racket[syntax-local-module-required-identifiers], | ||
@racket[module-compiled-exports], or @racket[module->exports] produces | ||
a phase--space combination (or phase--space shift combination), then | ||
two such values that are @racket[equal?] will be @racket[eqv?]. | ||
|
||
@history[#:added "8.2.0.3"] | ||
|
||
@defproc[(phase? [v any/c]) boolean?]{ | ||
|
||
Returns @racket[#f] if @racket[v] is a valid representation of a | ||
This comment has been minimized.
Sorry, something went wrong.
greghendershott
Contributor
|
||
@tech{phase level}: either an exact integer representing a numbered | ||
phase level or @racket[#f] representing the @tech{label phase level}.} | ||
|
||
@defproc[(space? [v any/c]) boolean?]{ | ||
|
||
Returns @racket[#f] if @racket[v] is a valid representation of a | ||
@tech{binding space}: either a symbol representing the space whose | ||
scope is accessed via @racket[make-interned-syntax-introducer], or | ||
@racket[#f] representing the default binding space.} | ||
|
||
@defproc[(phase+space? [v any/c]) boolean?]{ | ||
|
||
Returns @racket[#f] if @racket[v] is a valid representation of a | ||
@tech{phase level} and @tech{binding space} combination. The possible | ||
representations are as follows: | ||
|
||
@itemlist[ | ||
|
||
@item{a phase (in the sense of @racket[phase?]) by itself, which | ||
represents that phase plus the default binding space} | ||
|
||
@item{a pair whose @racket[car] is a phase and whose @racket[cdr] is | ||
a non-@racket[#f] space (in the sense of @racket[space?])} | ||
|
||
]} | ||
|
||
@deftogether[( | ||
@defproc[(phase+space-phase [p+s phase+space?]) phase?] | ||
@defproc[(phase+space-space [p+s phase+space?]) phase?] | ||
)]{ | ||
|
||
Extracts the @tech{phase level} or @tech{binding space} component from | ||
a combination.} | ||
|
||
|
||
@defproc[(phase+space-shift? [v any/c]) boolean?]{ | ||
|
||
Returns @racket[#f] if @racket[v] is a valid representation of a | ||
@tech{phase level} shift and @tech{binding space} shift combination. A | ||
shift can be applied to a combination of a phase level and binding | ||
space using @racket[phase+shift+]. The possible representations of a | ||
shift are as follows: | ||
|
||
@itemlist[ | ||
|
||
@item{exact integer --- represents an amount to shift a phase level | ||
and no change to the binding space} | ||
|
||
@item{@racket[#f] --- represents a shift to the @tech{label phase level} | ||
and no change to the binding space} | ||
|
||
@item{a pair whose @racket[car] is an exact integer or @racket[#f], | ||
and whose @racket[cdr] is a space (in the sense of | ||
@racket[space?]) --- represents a phase level shift in the | ||
@racket[car] and a change to the binding space that is in the | ||
@racket[cdr]} | ||
|
||
]} | ||
|
||
@defproc[(phase+space+ [p+s phase+space?] [shift phase+space-shift?]) | ||
phase+space?]{ | ||
|
||
Applies @racket[shift] to @racket[p+s] to produce a new combination of | ||
@tech{phase level} and @tech{binding space}.} | ||
|
||
@defproc[(phase+space-shift+ [shift phase+space?] [additional-shift phase+space-shift?]) | ||
phase+space-shift?]{ | ||
|
||
Composes @racket[shift] and @racket[additional-shift] to produce a new | ||
shift that behaves the same as applying @racket[shift] followed by | ||
@racket[additional-shift].} |
What do you think of calling the pair of a phase and a binding space a "binding location" instead of a
phase+space
?