Page Numbers: Yes X: 306 Y: 1.0" First Page: 43
Margins: Top: 1.0" Bottom: 1.3"
Heading:
STANDARD PROCEDURES3-LISP REFERENCE MANUAL March 17, 1984
————————————————————————————————————————————
4.c.3. FUNCTIONS and CLOSURES
————————————————————————————————————————————
(FUNCTION E)
(CLOSURE E)
True just in case E designates a function or closure, respectively.
F-Type: [ OBJECTS ] TRUTH-VALUESProperties: Primitive; kernel.
Examples:(FUNCTION (LAMBDA [N] (* N N)))g$TRUE
(CLOSURE (LAMBDA [N] (* N N)))
g$FALSE
(CLOSURE ↑(LAMBDA [N] (* N N)))
g$TRUE
(CLOSURE (CCONS GLOBAL ’[X] ’X ))
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’{simple closure: "A Test"}
(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{the global environment}
(CLOSURE-ENVIRONMENT +)
g{ERROR: Simple closure expected.}
(CLOSURE-ENVIRONMENT ↑+)
g{the 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 SIMPLE [A B]
(PCONS B A)))
g’[A B]
(PATTERN ↑NORMALISE)
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 SIMPLE [A B]
(PCONS B A)))
g’(PCONS B A)
(BODY ↑REST)
g’(TAIL 1 VECTOR)
(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 be 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.}
(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)))
g$FALSE
(REFLECTIVE-CLOSURE (LAMBDA [N] (+ N N)))
g{ERROR: Closure expected.}
(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: Primitive, 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, Primitive, Cons.
Examples:((EXPANDER ↑DELAY) ’[(FOO X)])g’(LAMBDA [] (FOO X))
((EXPANDER ↑LET) ’[[[X 1] (+ X 2)])
g’((LAMBDA [X] (+ X 2)) 1)
(DE-REFLECT (CCONS GLOBAL ’Y ’Z))g{simple closure}
(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)))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)))g’[X]
(PATTERN ↑(LAMBDA SIMPLE [A B]
(PCONS B A)))
g’[A B]
(PATTERN ↑NORMALISE)
g’[STRUCTURE ENV ESC CONT]
(PATTERN +)
g{ERROR: Simple closure expected}
————————————————————————————————————————————
4.c.4. ATOMS
————————————————————————————————————————————
(ATOM E)
True just in case E designates an atom.
F-Type: [ OBJECTS ] TRUTH-VALUESProperties: Primitive; kernel.
Examples:(ATOM ’Hello)g$TRUE
(ATOM ’$TRUE)g$FALSE
(ACONS)
Designates a nameless and otherwise inaccessible atom.
F-Type: [ ] ATOMSProperties: Primitive; cons.
Examples:(ACONS)g’{atom}
(= (ACONS) (ACONS))g$FALSE
(ATOM-NOTATION ATOM)
Designates the string that is the notation of the atom designated by ATOM.
F-Type: [ ATOMS ] STRINGSProperties: Primitive.
Examples:(ATOM-NOTATION ’Curious)g"CURIOUS"
(ATOM-NOTATION (ACONS))g{Error: Unnamed atom encountered}
(ATOM-NOTATED STRING)
Designates the atom whose notation is the string designated by STRING.
F-Type: [ STRINGS ] ATOMSProperties: Primitive; cons.
Examples:(ATOM-NOTATED "Lambda")g’LAMBDA
(ATOM-NOTATED "")g{Error: ...}
————————————————————————————————————————————
4.c.5. TYPING
————————————————————————————————————————————
(TYPE E)
Designates the atom associated with the type of the object designated by A (chosen from the standard 18, and possibly others if other types are added to the system).
F-Type: [ OBJECTS ] ATOMS Properties: Primitive; kernel.
Examples:(TYPE 3)g’NUMBER(TYPE PRIMARY-STREAM)g’STREAM
(TYPE ’3)
g’NUMERAL(TYPE ↑PRIMARY-STREAM)g’STREAMER
(TYPE $TRUE)
g’TRUTH-VALUE(TYPE ’(= 2 3))g’PAIR
(TYPE ’$FALSE)
g’BOOLEAN(TYPE ’A)g’ATOM
(TYPE #A)
g’CHARACTER(TYPE ’A)g’ATOM
(TYPE ’#4)
g’CHARAT(TYPE ’’3)g’HANDLE
(TYPE [1 2 3])
g’SEQUENCE(TYPE ’’’’’’’?)g’HANDLE
(TYPE ’[1 2 3])
g’RAIL(TYPE "Hello There")g’STRING
(TYPE +)
g’FUNCTION(TYPE ↑"Yes?")g’STRINGER
(TYPE ↑+)
g’CLOSURE(TYPE GLOBAL)g’ENVIRONMENT
(ATOM E)(FUNCTION E)(SEQUENCE E)
(BOOLEAN
E)(HANDLE E)(STREAM E)
(CHARACTER
E)(NUMBER E)(STREAMER E)
(CHARAT
E)(NUMERAL E)(STRING E)
(CLOSURE
E)(PAIR E)(STRINGER E)
(ENVIRONMENT
E)(RAIL E)(TRUTH-VALUE E)
Each of these type predicates (characteristic functions) are true just of elements of each of the corresponding semantic categories, and false otherwise. Specifically, (ATOME) is true iff E designates an atom, etc.
F-Type: [ OBJECTS ] TRUTH-VALUES Properties: Kernel (ATOM, PAIR, RAIL, HANDLE only).
Examples:(ATOM ’A)g$TRUE
(PAIR ’(1ST ’[A B]))
g$TRUE
(FUNCTION +)
g$TRUE
(CLOSURE ’+)
g$FALSE
(VECTOR E)
True if and only if E designates either a rail or a sequence; false otherwise.
F-Type: [ OBJECTS ] TRUTH-VALUES
Examples:(VECTOR [1 2 3])g$TRUE
(VECTOR ’[A B])
g$TRUE
(VECTOR ’(1 2 3))
g$FALSE
(VECTOR "String")
g$FALSE
(STRUCTURE E)
(EXTERNAL E)
(STRUCTUREE) is true if and only if E designates an internal structure such as a numeral or a rail; false otherwise. Similarly, (EXTERNALE) is true just in case E designates an external or mathematical abstraction, such as a number or a sequence; false otherwise.
F-Type: [ OBJECTS ] TRUTH-VALUES Properties: Kernel (EXTERNAL only).
Examples:(EXTERNAL 123)g$TRUE
(STRUCTURE (+ 2 2))
g$FALSE
(EXTERNAL +)
g$TRUE
(STRUCTURE ’+)
g$TRUE
(STRUCTURE ↑+)
g$TRUE
(STRUCTURE "String")
g$FALSE
(STRUCTURE ’"String")
g$TRUE
————————————————————————————————————————————
4.c.6. IDENTITY
————————————————————————————————————————————
(= E1 E2)
True if E1 and E2 designate the same object; false otherwise, except that an error will be detected if both E1 and E2 designate functions. When both E1 and E2 designate sequences, corresponding elements are compared (using =) from left to right until it can be established that the two sequences differ, or until an error is detected. Consequently, (=E1E2) may fail to terminate when E1 and E2 designate infinite sequences or otherwise represent infinite computations. Note that although equality is defined over closures, it is too fine-grained to be used for function identity.
F-Type: [ OBJECTS X OBJECTS ] TRUTH-VALUES Properties: Primitive; kernel.
Examples:(= 3 (+ 1 2))g$TRUE
(= 5 ’5)g$FALSE
(= ’5 ’5)g$TRUE
(= $FALSE $FALSE)g$TRUE
(= [10 20] [10 20])g$TRUE
(= ’[10 20] ’[10 20])
g$FALSE
(= [’10 ’20] ’[10 20])
g$FALSE
(= ’[10 20] [’10 ’20])
g$FALSE
(= CAR CDR)
g{ERROR: = not defined over functions.}
(= CAR 3)
g$FALSE
(= [+ 2] [+ 3])
g{ERROR: = not defined over functions.}
(= [2 +] [3 +])
g$FALSE
————————————————————————————————————————————
4.c.7. ARITHMETIC OPERATIONS and NUMBERS
————————————————————————————————————————————
(NUMBER E)
(NUMERAL E)
True just in case E designates a number or numeral, respectively.
F-Type: [ OBJECTS ] TRUTH-VALUESProperties: Primitive; kernel.
Examples:(NUMBER 3)g$TRUE
(NUMBER (IF $TRUE (+ 2 3) (* 2 3)))
g$TRUE
(NUMBER (FIRST ’[10 20 30]))
g$FALSE
(NUMERAL ’1234567)
g$TRUE
(NUMERAL (FIRST ’[10 20 30]))
g$TRUE
(+ N1 N2)
(* N1 N2)
(- N1 N2)
(/ N1 N2)
Designate, respectively, the sum, product, difference, and quotient of the numbers designated by N1 and N2. (/N1N2) will cause an error if N2 designates zero. Currently, arithmetic is defined only on integers (ultimately we intend to define full rational, or repeating fraction, arithmetic, with no upper limit on numeral size, and no limit on precision).
F-Type: [ NUMBERS X NUMBERS ] NUMBERSProperties: Primitive.
Examples:(* 2 2)g4
(+ 10 30)
g40
(+ ’1 ’2)
g{ERROR: Number expected.}
(- 100 2)
g98
(- 10 20)
g-10
(/ 10 3)
g3
(/ -10 3)
g-3
(/ 10 -3)
g-3
(/ -10 -3)
g3
(/ 100 0)
g{ERROR: Division by zero.}
(REMAINDER N1 N2)
Designates the remainder upon dividing N1 by N2; error if N2 designates zero. The sign of a non-zero remainder is that of the first argument.
F-Type: [ NUMBER X NUMBERS ] NUMBERS
Examples:(REMAINDER 10 3)g1
(REMAINDER 10 -3)
g1
(REMAINDER -10 -3)
g-1
(REMAINDER -10 -3)
g-1
(REMAINDER 10 0)
g{ERROR: Division by zero.}
(1+ N)
(1- N)
Designates the number one greater or one less than the number designated by N, respectively.
F-Type: [ NUMBERS ] NUMBERS
Examples:(1+ 20)g21
(MAP 1- [2 3 4])
g[1 2 3]
(< N1 N2)
(<= N1 N2)
(> N1 N2)
(>= N1 N2)
(<> N1 N2)
True if and only if relationship between the two numbers designated by N1 and N2 is that of being less than, less than or equal (<=), greater than (>), greater than or equal (>=), or not equal (<>).
F-Type: [ NUMBERS X NUMBERS ] TRUTH-VALUESProperties: Primitive.
Examples:(< 2 3)g$TRUE
(>= 5 4)
g$TRUE
(<= 99 ’1)
g{ERROR: Number expected.}
(> 100 1000)
g$FALSE
(ABS N)
Designates the absolute value of the number designated by N.
F-Type: [ NUMBER ] NUMBERS
Examples:(ABS 100)g100
(ABS -100)
g100
(ABS 0)
g0
(ABS ’1)
g{ERROR: Number expected.}
(MIN N1 N2 ... Nk)
(MAX N1 N2 ... Nk)
Designate, respectively, the minimum and maximum of the numbers designated by N1 through Nk (K>𔁇).
F-Type: [ NUMBERS X {NUMBERS}* ] NUMBERS
Examples:(MIN 3 1 4)g1
(MIN 0 1 -7)
g-7
(MAX 4)
g4
(ODD N)
(EVEN N)
True if N designates an odd or even number, respectively.
F-Type: [ NUMBERS ] TRUTH-VALUES
Examples:(ODD 100)g$FALSE
(EVEN 100)
g$TRUE
(ODD -1)
g$TRUE
(ZERO N)
(NEGATIVE N)
(POSITIVE N)
(NON-NEGATIVE N)
True if the number N designates is equal to, less than, greater than, or greater than or equal to zero, respectively.
F-Type: [ NUMBERS ] TRUTH-VALUES
Examples:(ZERO 1)g$FALSE
(NEGATIVE -1)
g$TRUE
(POSITIVE 0)
g$FALSE
(NON-NEGATIVE 0)
g$TRUE
(** N1 N2)
Designates the N2-fold product of the number designated by N1 with itself. N2 must designate a non-negative number.
F-Type: [ NUMBERS X NUMBERS ] NUMBERS
Examples:(** 2 10)g1024
(** 10 0)
g1
(** -5 3)
g-125