13 Keyed Variables

A keyed variable is a device that associates a non-symbolic key (in the form of an accessor applicative) with a value depending on the context in which lookup occurs. Kernel provides two types of keyed variables: dynamic & static. Keyed Dynamic Variables use the dynamic extent as context and Keyed Static Variables use the dynamic environment.

13.1 Keyed Dynamic Variables

A keyed dynamic variable is a device that associates a non-symbolic key (in the form of an accessor applicative) with a value depending on the dynamic extent in which lookup occurs.

— Applicative: make-keyed-dynamic-variable (make-keyed-dynamic-variable)

Returns a list of the form (b a), where b and a are applicatives, as follows. Each call to make-keyed-dynamic-variable returns different b and a.

  • b is an applicative that takes two arguments, the second of which must be a combiner. It calls its second argument with no operands (nil operand tree) in a fresh empty environment, and returns the result.
  • a is an applicative that takes zero arguments. If the call to a occurs within the dynamic extent of a call to b, then a returns the value of the first argument passed to b in the smallest enclosing dynamic extent of a call to b. If the call to a is not within the dynamic extent of any call to b, an error is signaled.

 

13.2 Keyed Static Variables

A keyed static variable is a device that binds data in an environment by a non-symbolic key, where the key is an accessor applicative.

— Applicative: make-keyed-static-variable (make-keyed-static-variable)

Returns a list of the form (b a), where b and a are applicatives, as follows. Each call to make-keyed-static-variable returns different b and a.

  • b is an applicative that takes two arguments, the second of which must be an environment. It constructs and returns a child-environment of its second argument, with initially no local bindings.
  • a is an applicative that takes zero arguments. If the dynamic environment e of the call to a has an improper ancestor that was constructed by a call to b, then a returns the value of the first argument passed to b in the first such environment encountered by a depth-first traversal of the improper ancestors of e. If e has no improper ancestors constructed via b, an error is signaled.