scope-operations
scopes/  c
→scopes
->scopes
→scopes*
->scopes*
empty-scopes
empty-scopes-syntax
scopes-add
scopes-remove
scopes-flip
scopes-symmetric-difference
scopes-intersect
single-scope?
zero-scopes?
scopes-equal?
scope-kind
use-site-scope?
macro-scope?
module-scope?
intdef-scope?
local-scope?
top-scope?
all-scopes-in?
any-scope-in?
7.1

scope-operations

Georges Dupéron <[email protected]>

 (require scope-operations) package: scope-operations

procedure

(scopes/c v)  boolean?

  v : any/c
Contract which recognizes a set of scopes, represented as an introducer function. Equivalent to:
(->* (syntax?)
     ([or/c 'add 'remove 'flip])
     syntax?)

procedure

(→scopes stx)  scopes/c

  stx : syntax?
(->scopes stx)  scopes/c
  stx : syntax?
Extracts the scopes present on the topmost syntax object of stx. This is equivalent to:

(make-syntax-delta-introducer (datum->syntax stx 'stx) (datum->syntax #f 'zero))

Unlike a make-syntax-delta-introducer, this procedure does not expect a second argument (always creating an introducer for all the scopes present on stx), and works on syntax objects which are not identifiers.

procedure

(→scopes* stx)  scopes/c

  stx : (or/c syntax? scopes/c)
(->scopes* stx)  scopes/c
  stx : (or/c syntax? scopes/c)
Lenient version of →scopes, which acts as a no-op when passed a set of scopes, instead of raising an error.

value

empty-scopes : "The empty set of scopes, as produced by:"

(→scopes (datum->syntax #f 'zero))

value

empty-scopes-syntax

 : "A syntax object with an empty set of scopes, as produced by:"

(datum->syntax #f 'zero)

procedure

(scopes-add sc1 sc2)  scopes/c

  sc1 : (or/c syntax? scopes/c)
  sc2 : (or/c syntax? scopes/c)
Set union of the given sets of scopes.

procedure

(scopes-remove sc1 sc2)  scopes/c

  sc1 : (or/c syntax? scopes/c)
  sc2 : (or/c syntax? scopes/c)
Set difference of the given sets of scopes.

The resulting set of scopes contains all the scopes present in sc1 which are not present in sc2.

procedure

(scopes-flip sc1 sc2)  scopes/c

  sc1 : (or/c syntax? scopes/c)
  sc2 : (or/c syntax? scopes/c)
(scopes-symmetric-difference sc1 sc2)  scopes/c
  sc1 : (or/c syntax? scopes/c)
  sc2 : (or/c syntax? scopes/c)
Flips the scopes in sc2 on the sc1 set of scopes.

The resulting set of scopes contains all the scopes present in sc1 which are not present in sc2, as well as the scopes present in sc2 which were not present in sc1.

Flipping the sc2 scopes on sc1 has the same effect as computing the symmetric difference of the two sets of scopes.

procedure

(scopes-intersect sc1 sc2)  scopes/c

  sc1 : (or/c syntax? scopes/c)
  sc2 : (or/c syntax? scopes/c)
Set intersection of the given sets of scopes.

procedure

(single-scope? sc)  boolean?

  sc : (or/c syntax? scopes/c)
Predicate which returns #true iff the given set of scopes contains only a single scope.

procedure

(zero-scopes? sc)  boolean?

  sc : (or/c syntax? scopes/c)
Predicate which returns #true iff the given set of scopes contains no scopes (e.g. because sc has been created with (datum->syntax #f 'id)).

procedure

(scopes-equal? sc1 sc2)  boolean?

  sc1 : (or/c syntax? scopes/c)
  sc2 : (or/c syntax? scopes/c)
Predicate which returns #true iff the two given sets of scopes contain the same scopes. It is a generalised form of bound-identifier=?, which also works for scopes represented as functions like the ones created by make-syntax-introducer and make-syntax-delta-introducer.

procedure

(scope-kind sc)  symbol?

  sc : (and/c (or/c syntax? scopes/c) single-scope?)
Returns the kind of the single scope in sc. To my knowledge, this will be one of use-site, macro, module, intdef, local or top.

procedure

(use-site-scope? sc)  boolean?

  sc : (and/c (or/c syntax? scopes/c) single-scope?)
A shorthand for (eq? (scope-kind sc) 'use-site)

procedure

(macro-scope? sc)  boolean?

  sc : (and/c (or/c syntax? scopes/c) single-scope?)
A shorthand for (eq? (scope-kind sc) 'macro)

procedure

(module-scope? sc)  boolean?

  sc : (and/c (or/c syntax? scopes/c) single-scope?)
A shorthand for (eq? (scope-kind sc) 'module)

procedure

(intdef-scope? sc)  boolean?

  sc : (and/c (or/c syntax? scopes/c) single-scope?)
A shorthand for (eq? (scope-kind sc) 'intdef)

procedure

(local-scope? sc)  boolean?

  sc : (and/c (or/c syntax? scopes/c) single-scope?)
A shorthand for (eq? (scope-kind sc) 'local)

procedure

(top-scope? sc)  boolean?

  sc : (and/c (or/c syntax? scopes/c) single-scope?)
A shorthand for (eq? (scope-kind sc) 'top)

procedure

(all-scopes-in? sc1 sc2)  boolean?

  sc1 : (or/c syntax? scopes/c)
  sc2 : (or/c syntax? scopes/c)
Predicate which returns #true iff all the scopes contained within the set of scopes sc1 are present in the set of scopes sc2.

procedure

(any-scope-in? sc1 sc2)  boolean?

  sc1 : (or/c syntax? scopes/c)
  sc2 : (or/c syntax? scopes/c)
Predicate which returns #true iff any of the scopes contained within the set of scopes sc1 are present in the set of scopes sc2.