Page Numbers: Yes X: 306 Y: 1.0" First Page: 35
Margins: Top: 1.0" Bottom: 1.3"
Heading:
STANDARD PROCEDURE GUIDE3-LISP REFERENCE MANUAL April 16, 1984
————————————————————————————————————————————
2.b.3. ENVIRONMENTS
————————————————————————————————————————————
(ENVIRONMENT E)
(ENVIRONMENT-DESIGNATOR E)
True just in case E designates an environment or environment designator, respectively.
F-Type: [ OBJECTS ] TRUTH-VALUESProperties: Primitive; kernel.
Examples:(ENVIRONMENT GLOBAL)g$TRUE
(ENVIRONMENT (CLOSURE-ENVIRONMENT ↑+))
g$TRUE
(ENVIRONMENT (ECONS))
g$FALSE
(ENVIRONMENT-DESIGNATOR (ECONS))
g$TRUE
GLOBAL
This atom, bound in the global environment, designates the global environment. The environment designator to which GLOBAL is bound is shared across all reflective levels, and is a tail of the environment designator captured in most closures.
F-Type: ENVIRONMENTSProperties: Variable.
Examples:1> (SET XXXX (+ 2 2))
1=
4
1> (BINDING ’XXXX GLOBAL)
1=
’4
1> (
(BINDING ’+ GLOBAL) 3 4)
1= 7
(NEW-ENVIRONMENT)
(ECONS)
(NEW-ENVIRONMENT) designates an empty environment, returning an otherwise inaccessible environment designator. Can be used with BINDING to build environments from scratch. (NEW-ENVIRONMENT) is defined in terms of (ECONS), as shown below, but the former is the one normally used.
F-Type:[ ] ENVIRONMENTSProperties: Primitive.
[ ] ENVIRONMENT-DESIGNATORS
Definition:(DEFINE NEW-ENVIRONMENT (LAMBDA [] (ECONS)))
Examples:(ECONS)g’{root environment ...}
(BINDING ’FOO (NEW-ENVIRONMENT))
g"unbound variable"
; Empty environments don’t contain bindings for any atoms.
(REBIND VAR BINDING ENV)
Modifies the environment designated by ENV to contain a binding of the structure designated by VAR to the structure designated by BIND. If the structure designated by VAR is already bound, that binding will be modified in place; if not, a new binding of the structure designated by VAR to the structure designated by BIND will be added at the far end of the environment designated by ENV. Environments generated by the 3-LISP processor consist only of atoms bound to normal-form structures, so that VAR should designate an atom and BIND a normal-form internal structure if ENV is intended to continue to designate a well-formed 3-LISP environment. Returns the structure to which BINDING normalises.
F-Type: [ STRUCTURES X STRUCTURES X ENVIRONMENTS ] STRUCTURES
Properties: Cons; Primitive; smash.
Examples:(LETSEQ [[X 1]
[Y 2]
[ENV (CURRENT-ENVIRONMENT)]]
(BEGIN (REBIND ’X ↑(+ 2 3) ENV)
(REBIND ’Y ↑X ENV)
(+ X Y)))
g10
(BINDING VAR ENV)
Designates the binding of the internal structure designated by VAR in the environment designated by ENV. The 3-LISP processor will on its own only establish normal-form bindings for atoms, so VAR should designate an atom unless the user provides his or her own environment structure (in which case BINDING can be used as a 3-LISP analog of LISP 1.5’s ASSOC). Designates the string ‘Unbound variable’ if the designation of VAR is unbound in the environment designated by ENV.
F-Type: [ STRUCTURES X ENVIRONMENTS ] STRUCTURESProperties: Kernel; Primitive.
Examples:(BINDING ’Y (BIND ’Y ’3 (DOWN (ECONS))))g’3
(BINDING ’NORMALIZE GLOBAL)
g’{NORMALIZE closure}
(LET [[X (+ 1 2)]]
((RLAMBDA [CALL ENV ESC CONT]
(CONT (BINDING ’X ENV)))))
g3
(BIND PATTERN ARGS ENV)
Designates an environment obtained by augmenting the environment designated by ENV with the variable bindings that result from matching of the pattern structure designated by PATTERN against the argument structure designated by ARGS. A pattern consisting of a single atom will match any argument structure directly; this results in the atom becoming bound to the entire argument structure. This basic matching process is extended to rail patterns in the usual way: pattern and argument rails must match on an element by element basis.
F-Type: [ STRUCTURES X STRUCTURES X ENVIROMENTS ] ENVIROMENTS
Properties: Kernel; Primitive; cons.
Examples:1> (DEFINE NEW-ENV (BIND ’[X Y Z] ↑[(+ 2 2) "FOO" ’[2 3]] GLOBAL))
1=
’NEW-ENV
1> (BINDING ’X NEW-ENV)
1=
’4
1> (BINDING ’Y NEW-ENV)
1=
’"FOO"
1> (BINDING ’Z NEW-ENV)
1=
’’[2 3]
1> (DEFINE NEW-ENV (BIND ’X ’3 GLOBAL))
1=
’NEW-ENV
1> (BINDING ’X NEW-ENV)
1=
’3
1> (DEFINE NEW-ENV (BIND ’X ’Y GLOBAL))
1=
’NEW-ENV
1> (BINDING ’X NEW-ENV)
1=
’Y; You can bind atoms to non-normal form structures,
; although the 3-LISP processor would never do that.
(CURRENT-ENVIRONMENT)
Designates the environment in effect at the point of call; crosses theoretic levels.
F-Type: [ ] ENVIRONMENTSProperties:
Definition:(DEFINE CURRENT-ENVIRONMENT
(RLAMBDA [CALL ENV ESC CONT]
(CONT ↑ENV)))
(CONTOUR-VARIABLES ENV)
Designates a sequence of the variables (atoms) in the first contour of the environment designated by ENV. Used primarily by debugging and other dynamic code examination procedures.
F-Type: [ ENVIRONMENTS ] SEQUENCESProperties: Primitive.
Examples:(LET [[X 1] [Y (+ 1 2)]]
(CONTOUR-VARIABLES (CURRENT-ENVIRONMENT)))
g[’X ’Y]
(CONTOUR-VARIABLES (NEW-ENVIRONMENT))
g[]
(PREVIOUS-CONTOUR ENV)
Designates the previous contour of the environment designated by ENV.
F-Type: [ ENVIRONMENTS ] ENVIRONMENTSProperties: Primitive.
Examples:((LAMBDA [A B C]
((LAMBDA [X Y Z]
(CONTOUR-VARIABLES (PREVIOUS-CONTOUR (CURRENT-ENVIRONMENT))))
10 20 30))
"This" "is" "it")
g[’A ’B ’C]
(LAST-CONTOUR ENV)
True just in case the environment designated by ENV has no previous contour.
F-Type: [ ENVIRONMENTS ] TRUTH-VALUESProperties: Primitive.
Examples:(LAST-CONTOUR (CURRENT-ENVIRONMENT))g$TRUE
(LAST-CONTOUR GLOBAL)
g$TRUE
(LET [[X 1] [Y (+ 1 2)]]
(LAST-CONTOUR (CURRENT-ENVIRONMENT)))
g$FALSE
————————————————————————————————————————————
2.b.4. CLOSURES
————————————————————————————————————————————
(CLOSURE E)
True just in case E designates a closure.
F-Type: [ OBJECTS ] TRUTH-VALUESProperties: Primitive; kernel.
Examples:(CLOSURE (LAMBDA [N] (* N N)))g$FALSE
(CLOSURE ’(LAMBDA [N] (* N N)))
g$FALSE
(CLOSURE ↑(LAMBDA [N] (* N N)))
g$TRUE
(CLOSURE (CCONS GLOBAL ’[X] ’X "foo"))
g$TRUE
(CLOSURE 3)
g$FALSE
(CCONS ENVIRONMENT PATTERN BODY COMMENT)
Designates an otherwise inaccessible simple closure containing designators of the environment designated by ENVIRONMENT, the pattern designated by PATTERN (either an atom or a sequence of atoms), the body designated by BODY, and a comment (string) designated by COMMENT (which is not used by the system but may be extracted with COMMENT, q.v.). Errors if any argument is of the wrong type.
Properties: Primitive; kernel; cons.
F-Type: [ ENVIRONMENTS X STRUCTURES X STRUCTURES X STRINGS ] CLOSURES
Properties: Primitive; kernel; cons.
Examples:(CCONS GLOBAL ’[X] ’X "A Test")g’{A Test closure ...}
(LAMBDA [N] (* N N))
g’{simple closure}
(
(CCONS GLOBAL ’[X] ’(+ X 1) "") 10)g11
(CLOSURE-ENVIRONMENT CLOSURE)
Designates the environment in the simple closure designated by CLOSURE. Errors if CLOSURE designates a non-simple closure, or another type of object altogether.
F-Type: [ CLOSURES ] ENVIRONMENTSProperties: Primitive; kernel.
Examples:(CLOSURE-ENVIRONMENT
(CCONS GLOBAL ’[X] ’X "A Test"))
g{global environment}
(CLOSURE-ENVIRONMENT +)
g{ERROR: Simple closure expected.}
(CLOSURE-ENVIRONMENT ↑+)
g{global environment}
(CLOSURE-ENVIRONMENT ↑IF)
g{ERROR: Simple closure expected.}
(BINDING ’X
(CLOSURE-ENVIRONMENT
↑(LET [[X 3]]
(LAMBDA [N] (* X N)))))
g’3
(PATTERN CLOSURE)
Designates the structure that is the pattern in the simple closure designated by CLOSURE. Errors if CLOSURE designates a non-simple closure, or another type of object altogether.
F-Type: [ CLOSURES ] STRUCTURESProperties: Primitive; kernel.
Examples:(PATTERN (CCONS GLOBAL ’[X] ’(* X X) ""))g’[X]
(PATTERN ↑(LAMBDA [A B]
(PCONS B A)))
g’[A B]
(PATTERN ↑NORMALIZE)
g’[STRUCTURE ENV ESC CONT]
(PATTERN +)
g{ERROR: Simple closure expected}
(BODY CLOSURE)
Designates the structure that is the body of the simple closure designated by CLOSURE. Errors if CLOSURE designates a non-simple closure, or another type of object altogether.
F-Type: [ CLOSURES ] STRUCTURESProperties: Primitive; kernel.
Examples:(BODY (CCONS GLOBAL ’[X] ’(* X X) ""))g’(* X X)
(BODY ↑(LAMBDA [A B]
(PCONS B A)))
g’(PCONS B A)
(BODY +)
g{ERROR: Closure expected.}
(COMMENT CLOSURE)
Designates the string that is the comment in the simple closure designated by CLOSURE. The comment field of a closure is normally set only by DEFINE (q.v.), and is used only by the print routines, solely as a hint to the user about the origin of the closure.
F-Type: [ CLOSURES ] STRINGSProperties: Primitive.
Examples:(COMMENT (CCONS GLOBAL ’[X] ’(* X X) "A Test"))g"A Test"
(COMMENT ↑(LAMBDA [A B] (PCONS B A)))
g""
(BEGIN (DEFINE INCREMENT
(LAMBDA [N] (+ N 1)))
(COMMENT ↑INCREMENT))
g"INCREMENT"
(COMMENT +)
g{ERROR: Closure expected.}
(SET-COMMENT CLOSURE STRING)
Sets the comment string associated with the closure designated by CLOSURE to be the string designated by STRING. SET-COMMENT is primarily used by DEFINE (q.v.), but is made available for extraordinary user use. Returns ’OK.
F-Type: [ CLOSURES X STRINGS ] STRINGSProperties: Primitive; cons.
Examples:1> (SET FOO (LAMBDA [X] (+ X 100)))
1= ’FOO
1> (COMMENT ↑FOO)
1= ""
1> (SET-COMMENT ↑FOO "Coal miner’s daughter")
1= ’OK
1> (COMMENT ↑FOO)
1= "Coal miner’s daughter"
1> (BEGIN (SET-COMMENT ↑FOO "El Norte")
(COMMENT ↑FOO))
1= "Coal miner’s daughter"
(SIMPLE-CLOSURE CLOSURE)
(MACRO-CLOSURE
CLOSURE)
(REFLECTIVE-CLOSURE
CLOSURE)
(PRIMITIVE-CLOSURE
CLOSURE)
True just in case the closure designated by CLOSURE is reflective, primitive, macro, or simple, respectively. All of these procedures cause an error if CLOSURE does not designate a closure. Note that the simple, macro, and reflective closures are exhaustive and mutually exclusive; the primitive closures are a subset of the simple closures.
F-Type: [ CLOSURES ] TRUTH-VALUESProperties: Kernel; primitive.
Examples:(SIMPLE-CLOSURE ↑+)g$TRUE
(REFLECTIVE-CLOSURE ↑IF)
g$TRUE
(PRIMITIVE-CLOSURE ↑+)
g$TRUE
(PRIMITIVE-CLOSURE ↑NORMALISE)
g$FALSE
(PRIMITIVE-CLOSURE ↑IF)
g$FALSE
(REFLECTIVE-CLOSURE ↑LET)
g$FALSE
(MACRO-CLOSURE ↑LET)
g$TRUE
(REFLECTIVE-CLOSURE
(CCONS GLOBAL ’[X] ’(* X X) "foo"))
g$FALSE
(REFLECTIVE-CLOSURE (LAMBDA [N] (+ N N)))
g$FALSE
(MACROIFY FUN)
(REFLECTIFY
FUN)
Designates an otherwise inaccessible macro or reflective closure, respectively, containing a simple closure designating the function designated by FUN specifically, the simple closure to which FUN normalises. Both of these procedures cross semantic levels; they are the inverses of DE-REFLECT and EXPANDER, q.v. An error is generated if FUN does not normalise to a simple closure. Note that the argument to REFLECTIFY should designate a function of four arguments: a structure, an environment, an escape, and a continuation.
F-Type: [ FUNCTIONS ] CLOSURESProperties: Cons.
Examples:(REFLECTIFY (LAMBDA [S E X C] ’QUIT!))g’{reflective closure}
(= NORMALISE
(REFLECTIFY ID))gTrue, but not computable ...
(MACROIFY IF)
g{Error: Simple function expected}
(EXPANDER CLOSURE)
(DE-REFLECT
CLOSURE)
EXPANDER designates a function that will perform the macro-transformation required in normalising a call that uses the closure CLOSURE. DE-REFLECT designates the function to be used in the reflective processor when processing a call using the closure CLOSURE. In both cases, designates the function designated by the closure stored within the macro or reflective closure designated by CLOSURE, respectively. Note that these procedures cross semantic levels; they are the inverses of REFLECTIFY and MACROIFY, q.v.
F-Type: [ CLOSURES ] FUNCTIONSProperties: Kernel, Cons.
Examples:((EXPANDER ↑DELAY) ’(DELAY (FOO X)))g’(LAMBDA [] (FOO X))
((EXPANDER ↑LET)
’(LET [[X 1]] (+ X 2)))
g’((LAMBDA [X] (+ X 2)) 1)
(DE-REFLECT ↑IF)g{simple IF closure}
(MACRO-CCONS CLOSURE)
(REFLECTIVE-CCONS
CLOSURE)
Designates an otherwise inaccessible macro or reflective closure, respectively, containing the simple closure designated by CLOSURE. Rarely used; see MACROIFY and REFLECTIFY, which could have been defined as follows:
(DEFINE MACROIFY (COMPOSE MACRO-CCONS UP))
(DEFINE REFLECTIFY (COMPOSE REFLECTIVE-CCONS UP))
F-Type: [ CLOSURES ] CLOSURESProperties: Kernel, Primitive, Cons.
Examples:(MACRO-CCONS (CCONS GLOBAL ’[X] ̀ (+ X 1) "FOO"))g’{macro closure}
(REFLECTIVE-CCONS
↑(LAMBDA [S E X C] ’QUIT!))
g’{reflective closure}
(EXTRACT-SIMPLE-CLOSURE CLOSURE)
Designates the simple closure contained within the macro or reflective closure designated by CLOSURE. Errors if CLOSURE designates a simple closure, or another type of object altogether. Rarely used; see instead DE-REFLECT and EXPANDER, which could have been defined as follows:
(DEFINE DE-REFLECT (COMPOSE DOWN EXTRACT-SIMPLE-CLOSURE))
(DEFINE EXPANDER (COMPOSE DOWN EXTRACT-SIMPLE-CLOSURE))
F-Type: [ CLOSURES ] STRUCTURESProperties: Primitive; kernel.
Examples:(PATTERN
(CCONS GLOBAL ’[X] ’(* X X) "FOO"))
g’[X]
(PATTERN ↑(LAMBDA [A B]
(PCONS B A)))
g’[A B]
(PATTERN ↑NORMALIZE)
g’[STRUCTURE ENV ESC CONT]
(PATTERN +)
g{ERROR: Simple closure expected}