On this page:
3.3.1.1 Scope Datatype
scope?
scope-definition-context
scope-expansion-context
current-scope
new-scope
close-scope!
call-with-new-scope
with-new-scope
3.3.1.2 Local Bindings
scope-bind-value!
scope-bind-values!
scope-bind-syntax!
scope-bind-syntaxes!
scope-bind-syntax/  eval!
scope-bind-syntaxes/  eval!
scope-static-binding?
scope-static-value
3.3.1.3 Lexical Context
in-scope
out-of-scope
scope-delta-introducer
3.3.1.4 Local Expansion and Evaluation
expand-in-scope
expand-expression-in-scope
expand-in-scope-for-syntax
eval-in-scope
6.3.90.900
3.3.1 mischief/scope: Managing Internal Definitions

 (require mischief/scope) package: mischief-dev

3.3.1.1 Scope Datatype

procedure

(scope? x)  boolean?

  x : any/c
Recognizes scope values, which encapsulate pairs of internal definition contexts and expansion contexts.

procedure

(scope-definition-context sc)

  (or/c internal-definition-context? #false)
  sc : scope?
Produces the internal definition context encapsulated by a scope.

procedure

(scope-expansion-context sc)

  (or/c 'expression 'top-level 'module 'module-begin list?)
  sc : scope?
Produces the expansion context encapsulated by a scope.

parameter

(current-scope)  scope?

(current-scope sc)  void?
  sc : scope?
The current scope used for expansion and local bindings.

procedure

(new-scope [#:scope sc])  scope?

  sc : scope? = (current-scope)
Produces a scope encapsulating a fresh internal definition context and expansion context, extending the ones in sc.

procedure

(close-scope! [#:scope sc])  scope?

  sc : scope? = (current-scope)
Seals the internal definition context encapsulated by sc.

procedure

(call-with-new-scope [#:scope? sc] proc)  any

  sc : scope? = (current-scope)
  proc : (-> scope? any)
Calls proc with the result of (new-scope #:scope sc), and calls (close-scope! #:scope sc) when proc returns.

syntax

(with-new-scope body ...+)

Executes the body forms with current-scope set to a fresh scope.

3.3.1.2 Local Bindings

procedure

(scope-bind-value! id [#:scope sc])  void?

  id : identifier?
  sc : scope? = (current-scope)

procedure

(scope-bind-values! ids [#:scope sc])  void?

  ids : (listof identifier?)
  sc : scope? = (current-scope)

procedure

(scope-bind-syntax! id val [#:scope sc])  void?

  id : identifier?
  val : any/c
  sc : scope? = (current-scope)

procedure

(scope-bind-syntaxes! ids vals [#:scope sc])  void?

  ids : (listof identifier?)
  vals : list?
  sc : scope? = (current-scope)

procedure

(scope-bind-syntax/eval! id expr [#:scope sc])  void?

  id : identifier?
  expr : syntax?
  sc : scope? = (current-scope)

procedure

(scope-bind-syntaxes/eval! ids    
  expr    
  [#:scope sc])  void?
  ids : (listof identifier?)
  expr : syntax?
  sc : scope? = (current-scope)
Bind one or more identifiers in sc. The procedures scope-bind-value! and scope-bind-values! bind the names of values, while scope-bind-syntax! and scope-bind-syntaxes! bind names as syntax to the provided values. The procedures scope-bind-syntax/eval! and scope-bind-syntaxes/eval! bind names as syntax to one or more values produced by evaluating the provided syntax object.

procedure

(scope-static-binding? id [#:scope sc])  boolean?

  id : identifier?
  sc : scope? = (current-scope)
Reports whether id is bound as syntax in sc.

procedure

(scope-static-value id    
  [#:rename? rename?    
  #:scope sc    
  #:success success    
  #:failure failure])  any
  id : identifier?
  rename? : boolean? = #true
  sc : scope? = (current-scope)
  success : (-> any/c any) = identity
  failure : (-> any)
   = 
(lambda {}
  (wrong-syntax id "expected an identifier with a syntax binding"))
Extracts the value associated with id in sc, if sc is bound as syntax. Recursively follows rename transformers if rename? is #true. If id is bound as syntax, passes its value to success; otherwise invokes failure.

3.3.1.3 Lexical Context

procedure

(in-scope stx [#:scope sc])  syntax?

  stx : syntax?
  sc : scope? = (current-scope)
Adds the bindings encapsulated by sc to the context of stx.

procedure

(out-of-scope stx [#:scope sc])  syntax?

  stx : syntax?
  sc : scope? = (current-scope)
Removes the bindings encapsulated by sc from the context of stx.

procedure

(scope-delta-introducer id [#:scope sc])  (-> syntax? syntax?)

  id : identifier?
  sc : scope? = (current-scope)
Produces a delta introducer that applies any marks on id that were not on its original definition.

3.3.1.4 Local Expansion and Evaluation

procedure

(expand-in-scope stx    
  [#:scope sc    
  #:stop-at stop])  syntax?
  stx : syntax?
  sc : scope? = (current-scope)
  stop : (or/c (listof identifier?) #false)
   = 
(if (memq (scope-expansion-context sc)
      '(expression module-begin))
    #false
    '())
Locally expands stx using the definition and expansion contexts encapsulated by sc. If stop is a list, expansion stops when it encounters any identifier in stop or any identifier in (kernel-form-identifier-list). If stop is #false, expansion does not stop, and recurs into subforms.

Note: the interpretation of '() and #false in stop are reversed from that used in the third argument to local-expand. This change is intended to make the behavior of stop more uniform: any list results in head-expansion, while #false results in recursive expansion.

procedure

(expand-expression-in-scope stx    
  [#:scope sc    
  #:stop-at stop])  syntax?
  stx : syntax?
  sc : scope? = (current-scope)
  stop : (or/c (listof identifier?) #false) = #false
Like expand-in-scope, but sets the expansion context to 'expression while expanding.

procedure

(expand-in-scope-for-syntax stx    
  [#:scope sc    
  #:stop-at stop])  syntax?
  stx : syntax?
  sc : scope? = (current-scope)
  stop : (or/c (listof identifier?) #false) = #false
Like expand-in-scope, but expands compile-time expressions.

procedure

(eval-in-scope stx [#:scope sc])  any

  stx : syntax?
  sc : scope? = (current-scope)
Evaluates stx at compile-time using the bindings in sc.