Page Numbers: Yes X: 306 Y: 1.0" First Page: 21
Margins: Top: 1.0" Bottom: 1.3"
Heading:
STANDARD PROCEDURE GUIDE3-LISP REFERENCE MANUAL April 16, 1984
————————————————————————————————————————————
2.a.4. NUMBERS and ARITHMETIC
————————————————————————————————————————————
(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
————————————————————————————————————————————
2.a.5. TRUTH-VALUES and BOOLEANS
————————————————————————————————————————————
(TRUTH-VALUE E)
(BOOLEAN E)
True just in case E designates an abstract (external) truth-value, or an internal boolean constant, respectively.
F-Type: [ OBJECTS ] TRUTH-VALUESProperties: Primitive; kernel.
Examples:(TRUTH-VALUE $TRUE)g$TRUE
(TRUTH-VALUE (= 2 3))
g$TRUE
(TRUTH-VALUE ’$TRUE))
g$FALSE
(BOOLEAN ’$TRUE)
g$TRUE
(BOOLEAN ↑(= 2 3))
g$TRUE
(NOT TV)
True if TV designates false, and false if TV designates true.
F-Type: [ TRUTH-VALUES ] TRUTH-VALUES
Examples:(NOT $F)g$TRUE
(NOT (EVEN 102))
g$FALSE
(NOT 1)
g{ERROR: Truth value expected.}
(AND TV1 TV2 ... TVk)
(OR TV1 TV2 ... TVk)
(ANDTV1TV2...TVk) is true just in case all the Ei are true; (ORTV1TV2...TVk) is true just in case at least one of the TVi is true. Procedurally, these forms normalise their arguments one-by-one only until a deciding case is found ($FALSE for AND; $TRUE for OR); thus they may be able to return even if some of their arguments are non-terminating. k may be 0; (AND) returns $T; (OR) returns $F.
F-Type: [ {TRUTH-VALUES}* ] TRUTH-VALUES Properties: Kernel (AND only); abnormal.
Examples:(AND (= 1 1) (= 1 2))g$FALSE
(OR (= 1 0) (= 1 2) (= 1 1))
g$TRUE
(AND)
g$TRUE
(OR)
g$FALSE
(LET [[X 3]]
(BEGIN (AND (= 1 2)
(BEGIN (SET X 4) $T))
X))
g3
————————————————————————————————————————————
2.a.6. TYPING and 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.
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
(= PPROC PARGS)
g{ERROR: = not defined over functions.}
(= PPROC 3)
g$FALSE
(= [+ 2] [+ 3])
g{ERROR: = not defined over functions.}
(= [2 +] [3 +])
g$FALSE
((RLAMBDA [CALL ENV ESC CONT]
(CONT ↑(= ENV ENV))))
g{ERROR: = not defined over environments.}
((RLAMBDA [CALL ENV ESC CONT]
(CONT ↑(= ↑ENV ↑ENV))))
g$TRUE
(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.
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 ’’3)g’HANDLE
(TYPE ’#4)
g’CHARAT(TYPE ’’’’’’’?)g’HANDLE
(TYPE [1 2 3])
g’SEQUENCE(TYPE "Hello There")g’STRING
(TYPE ’[1 2 3])
g’RAIL(TYPE ↑"Yes?")g’STRINGER
(TYPE +)
g’FUNCTION(TYPE GLOBAL)g’ENVIRONMENT
(TYPE ↑+)
g’CLOSURE
(TYPE ↑GLOBAL)
g’ENVIRONMENT-DESIGNATOR
(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)
(ENVIRONMENT-DESIGNATOR
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:
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
(NORMAL S)
True just in case S designates a normal-form internal structure.
F-Type: [ STRUCTURES ] TRUTH-VALUES Properties: Kernel.
Examples:(NORMAL ’3)g$TRUE
(NORMAL ’(+ 2 3))
g$FALSE
(NORMAL ↑(+ 2 3))
g$TRUE
(NORMAL ’[1 2 3])
g$TRUE
(NORMAL ’[1 2 A])
g$FALSE
(NORMAL ’A)
g$FALSE
(NORMAL ’’A)
g$TRUE
(ID E)
ID designates the single argument identity function. (IDE) designates the designation of E, and returns what E normalises to. The primary use is as a null ("throw-back") continuation.
F-Type:[ OBJECTS ] OBJECTS
Examples:(ID 3)g3
(ID (+ 2 2))
g4
(ID ’(+ 2 3))
g’(+ 2 3)
(ID ID)
g{ID closure}
(NORMALISE ’(+ 1 2) GLOBAL
STANDARD-ESCAPE
ID)
g’3
————————————————————————————————————————————