(original) (raw)
Page Numbers: Yes X: 306 Y: 1.0" First Page: 33 Margins: Top: 1.0" Bottom: 1.3" Heading: z18344l3000x3e4qk40(0,65535) STANDARD PROCEDURES 3-LISP REFERENCE MANUAL March 11, 1984l3000d2469y756x3e4qk40(0,2999)(1,8678)(2,16381)(13,0)\f7 1f1 x3e38ck40(1270)\14f5b 4. Standard Proceduresx3ck40\f5b x3ck40\14f5b There are about 150 standard procedures in 3-LISP: procedures that are described in this manual, used without comment in utility packages, and so forth (we also expect to compile' these procedures into the standard implementation). A 3-LISP programmer should consider these to be the base set, on top of which to define other functionality as desired. Within the set of standard procedures, however, are two important sub-classes: primitive procedures that provide access to the structural field and to the external world (e.g., I/O); and kernel procedures that are essential to the workings of the system. These two sets are neither mutually exclusive nor exhaustive: many of the primitives are kernel procedures as well (NULL, for example), but there are some non-kernel primitives (LENGTH, +, ACONS, etc.). In addition, it is clear that many kernel procedures are not primitive (LAMBDA, BINDING, NORMALISE, and NORMAL, to name a few). Finally, there are about 90 other standard procedures (MAX, LETSEQ, DO, etc.) that are neither primitive nor kernel.x3e10jk40\20ubi19UBI4f7 6f0 187f7 6f0 192i9I90f8 1f0 9i6I179f3 4f0 58f3 6f0 2f3 1f0 2f3 5f0 82f3 6f0 2f3 7f0 2f3 9f0 6f3 6f0 74f3 3f0 2f3 6f0 2f3 2f0 46i 4.a. Primitive Proceduresx3e10\f9b27B There are a number of primitive procedures (listed below) that have no definition within 3-LISP, and that are reduced with arguments in "unit time", in the sense that from no level of reflective access is there any visible grain to their operation. All the 3-LISP primitives are simple: there are no primitive reflectives. To a certain extent the particular set is arbitrary, and it is certainly not minimal: LIST, for example, could be defined in terms of RCONS, UP, and DOWN; LENGTH could be defined in terms of NULL and +; etc..x3e10jk40\22ubi20UBI47f7 6f0 163f7 6f0 147f3 4f0 44f3 9f0 6f3 4f0 2f3 6f0 30f3 4f0 5f3 1f0 Category Standard Name Functionalityl4057x3e10(0,6400)(1,10752)(2,65535)(13,65535)\ui8UI1ui13UI1ui13UI Identity: = defined all types except functions Structural: LIST, CONS, RCONS to construct and examine LENGTH, NTH, TAIL, NULL sequences and rails CCONS, PATTERN, BODY to construct and ENVIRONMENT-DESIGNATOR examine closures ACONS to construct atoms PCONS, PPROC, PARGS to construct and examine pairs Control: EF an "extensional" if-then-else conditional Semantics: UP (^), DOWN (^) to mediate between designator & designation Arithmetic: +, -, *, /, <, >,<=,>=, <> as you would expect I/O: CHAR-IN, CHAR-OUT primitive operations on streams READ, PRINT to read or print structures INTERNALISE, EXTERNALISE to mediate between notation and structure PRESENT, OBTAIN to communicate about arbitary objects [[[[System: LOADFILE, EDITDEF system support]]]] Typing: TYPE defined on 18 types (10 internal, 8 external) SIMPLE, REFLECTIVE, to distinguish different types of closures MACRO, PRIMITIVE SEQUENCE, NUMBER, STRING, characteristic functions on all types FUNCTION, CHARACTER, TRUTH-VALUE, STREAM, ATOM, PAIR, RAIL, BOOLEAN, CLOSURE, HANDLE, NUMERAL, ...l4057x3(1,10849)\10f3 1f0 48f3 4f0 3f3 4f0 2f3 5f0 28f3 8f0 3f3 3f0 3f3 4f0 3f3 4f0 28f3 5f0 2f3 7f0 2f3 4f0 19f3 1f0 1f3 24f0 3f3 3f0 18f3 5f0 21f3 5f0 3f3 5f0 3f3 5f0 41f3 2f0 4f8 1f0 11f8 1f0 37f3 2f0 2f3 1f0 4f3 4f0 2f4 1f0 58f3 1f0 2f3 1f0 2f3 1f0 2f3 1f0 2f3 1f0 2f3 1f0 1f3 2f0 1f3 2f0 2f3 2f0 22f8 1f0 3f3 7f0 2f3 8f0 34f3 4f0 2f3 5f0 30f3 11f0 2f3 11f0 44f3 7f0 2f3 6f0 51f3 8f0 1f3 8f0 28f3 4f0 48f3 6f0 2f3 10f0 47f3 7f0 2f3 9f0 2f3 8f0 2f3 6f0 2f3 6f0 41f3 10f0 2f3 9f0 2f3 11f0 2f3 6f0 2f3 4f0 2f3 4f0 3f3 6f0 2f3 7f0 2f3 7f0 2f3 6f0 2f3 7f0 4.b. Kernel Proceduresx3e10(1270)\f9b24B The kernel procedures are those that are used crucially in the 3-LISP reflective processor (i.e., they are used by the reflective processor to process the reflective processor). As a consequence, rebinding the standard name of one of these closures in the global environment (more accurately: in any environment captured inside any of the kernel closures) would cause the reflective tower to fall. Thus for all practical purposes the kernel procedures are as wired-in' to 3-LISP as are the primitives, even though in a strict sense they have visible definitions, and are compositionally executed by the processor (by expanding closures). Note that there are reflective kernel procedures as well as simple ones. It turns out that the kernel procedures are exactly the acquaintances of NORMALISE, although this needn't have been so (they could have been a subset, since there might have been code in the reflective processor that, although used when processing some forms of user code, didn't happen to be used to process the processor itself).x3e10jk40\4ubi17UBI20i22f7I6f0i21I385f7 6f0 308f3 9f0 Kernel Primitivesl4057x3e10(0,6400)(1,10752)\ui17UI PPROC, PARGS, RCONS, LIST, PREP, NTH, TAIL, NULL, CCONS, REFLECTIVE, MACRO, ENVIRONMENT-DESIGNATOR, PATTERN, BODY, TYPE, =, EF, UP, DOWNl4586x3e3j\f3 5f0 2f3 5f0 2f3 5f0 2f3 4f0 2f3 4f0 2f3 3f0 2f3 4f0 2f3 4f0 2f3 5f0 2f3 10f0 2f3 5f0 2f3 22f0 2f3 7f0 2f3 4f0 2f3 4f0 2f3 1f0 2f3 2f0 2f3 2f0 2f3 4f0 Kernel Non-primitivesl4057x3e10\ui21UI UNIT, DOUBLE, REST, 1ST, 2ND, MEMBER, VECTOR-CONSTRUCTOR, MAP, ENVIRONMENT, REFLECTIVE, DE-REFLECT, ATOM, PAIR, RAIL, HANDLE, EXTERNAL, LAMBDA, SIMPLE, BINDING, BIND, LET, IF, COND, COND-HELPER, AND, AND-HELPER, NORMALISE, REDUCE, NORMALISE-RAIL, NORMAL, NORMAL-RAIL, PRIMITIVEl4586x3e3j\f3 4f0 2f3 6f0 2f3 4f0 2f3 3f0 2f3 3f0 2f3 6f0 2f3 18f0 2f3 3f0 2f3 11f0 2f3 10f0 2f3 11f0 2f3 4f0 2f3 4f0 2f3 4f0 2f3 6f0 2f3 8f0 2f3 6f0 2f3 6f0 2f3 7f0 2f3 4f0 2f3 3f0 2f3 2f0 2f3 4f0 2f3 11f0 2f3 3f0 2f3 10f0 2f3 9f0 2f3 6f0 2f3 14f0 2f3 6f0 2f3 11f0 2f3 9f0 4.c. Standard Procedure Guidex3e10(1270)\f9b31B The remainder of this section is taken up with descriptions of each of the standard procedures. The 3-LISP code for the standard procedures can be found in Appendix A. Notes on the format of these descriptions:x3e10jk40\101f7 6f0 1. Each procedure is illustrated with non-objectified arguments, but many can be used in other ways (for example: (PCONS.(REST['A'B'C])) g '(B.C)).z17709l4057d3528x3e3j(0,4057)(1,65535)\f7 2f0 112f3 6f7 1f3 1f7 1f3 5f7 1f3 3f7 1f3 2f7 1f3 6f4 1f3 4f7 1f3 1f7 1f3 2f0 2. For each procedure, we give the declarative import. In many cases that is the only semantical information provided, since if the designation has a canonical normal-form designator, what is returned (i.e., the result) can be determined from this designation. For example, since (+ 23) designates the number 5, it will return the numeral 5; since (='A'B) designatos falsity, it will return the boolean $FALSE. If, however, the normal-form designator is not canonical, or if there are side effects, the relevant parts of the procedural significance are described as well.z17709l4057d3528x3e3j\f7 2f0 191i8I12i6I63f3 4f7 1f3 2f0 53f3 1f0 8f3 2f7 1f3 2f7 1f3 3f0 48f3 6f0 3. Typing information is typically given only in terms of what we call the functions "F-type". Thus for example the division function / would be said to have F-type of [NUMBERSXNUMBERS] _ NUMBERS. In some cases, the typing restrictions specified in this section are stricter than one would expect given the appendix A definitions.z17709l4057d3528x3e3j\f7 2f0 84f2 1f0 48f3 1f0 23f2 1f0 9f3i1f7I1f3i7f7I1f4 1f7 1f3i7f7I1f3i2f4I1f3i8f0I 4. On the format of the definitions: Each procedure is introduced with something like the following schema:z17709l4057d3528x3e3j\f7 2f0 (IF PREMISE E1 E2)z17709l5115d4586x3e3j\f8b4i7I1i1o254 1o0I1i1o254 1o0I1f0B If no more descriptive term is used (such as PREMISE in the above), the schematic variable names indicate the argument's (F-)type either the type name directly, or one of the following abbreviations:z17709l4057d3528x3e3j\46f3 7f0 70f2 1f0 E Object of any type S (Internal) structure CH Character SEQ Sequence (or rail) ENV Environment ST String FUN Function TV Truth value N Numberz16933l4928x3e3j(0,6173)(1,6879)(2,11296)(3,12523)(4,13229)\f3bi1f0BI22f3bi1f0BI24f3bi2f0BI13f3bi3f0BI22f3bi3f0BI15f3bi2f0BI10f3bi3f0BI12f3bi2f0BI15f3bi1f0BI Italics are used for meta-linguistic schematic variables; underlined arguments indicate those positions that are normalised tail recursively with respect to the procedure call. Intensional positions (positions that are or may not necessarily be normalised) are indicated with <<>>>.z17709l4057d3528x3e3j(0,4057)(1,65535)(2,65535)(3,65535)(4,65535) 5. Several one-word attributes are associated with each procedure that can provide a quick reference for determining the nature of the procedure. The following keywords are used:z17709l4057d3528x3e3j\f7 2f0 Cons This procedure may create new structures that will be accessible from the result. E.g., APPEND.z16933l7072d4939x3e3j(0,7056)\b4B90f3 6f0 Env Some of the arguments to this procedure may be normalised in some environment other that the current one; however, these environment manipulations are accomplished through non-destructive means. E.g., LET. z16933l7072d4939x3e3j\b3B203f3 3f0 Smash-env This procedure may destructively change the current environment. E.g., SET, REBIND.z16933l7072d4939x3e3j\b9B73f3 3f0 2f3 6f0 I/O This procedure may side effect the outside world by doing I/O. E.g., CHAR-IN.z16933l7072d4939x3e3j\b3B71f3 7f0 CPS This procedure is written in the continuation-passing style instead of returning, the result will be explicitly passed to the continuation (usually as the last argument). E.g., NORMALISE.z16933l7072d4939x3e3j\b3B181f3 9f0 Abnormal Some of the arguments may not always be normalised. E.g., IF.z16933l7072d4939x3e3j\b8B60f3 2f0 6. Still other keywords are used to indicate the nature of the procedure's status within the implementation:z17709l4057d3528x3e3jk80(0,4057)\f7 2f0 Primitive This procedure is one of the primitives that have only viciously circular definitions within the 3-LISP system. All non-primitives have complete and accurate descriptions in terms of the primitives.z16933l7072d4939x3e3j(0,7056)\b9B98f7 6f0 Kernel This procedure is an essential part of 3-LISP because it is used regularly by the reflective processors at all levels. z16933l7072d4939x3e3j\b6B40f7 6f0 7. The symbol g' (used in examples) means "normalises to"; W>' means approximately "expands to", and is used for macro redexes. Generally, illustrations of macro expansion are mild white lies: for example, in order to avoid unexpected environment dependencies, we would define INCREMENT as (MLAMBDA[N]'(,^+1,N)), rather than as (MLAMBDA[N]'(+1,N)). Nonetheless, we would still say that (INCREMENTEXP)W> (+1EXP), whereas it would be more accurate to say that (INCREMENTEXP)W> ({primitive+closure}1EXP). I.e., the W>' notation may be slightly inaccurate on hyperintensional properties of the expansion.z17709l4057d3528x3e3jk80(0,4057)\f7 2f0 13f4 1f0 45f4 1f3 1f0 217f3 9f0 4f3 8f7 1f3 3f7 1f3 5f7 1f3 1f7 1f3 4f0 17f3 8f7 1f3 3f7 1f3 3f7 1f3 1f7 1f3 4f0 40f3 10f7 1f3i3I1f7 1f4 1f3 4f7 1f3 1f7 1f3i3I1f0 48f3 10f7 1f3i3I1f7 1f4 1f3 13f7 1f3 1f7 1f3 8f7 1f3 1f7 1f3i3I1f0 14f4 1f3 1f0 8. Some comments in regard to examples involving I/O. All output expressions are printed in italics following the level 1 processor's 1=' prompt. Input expression appear unitalicised following the 1>' prompt. z17709l4057d3528x3e3jk80\f7 2f0 134f3 2f0 63f3 2f0 1> 'HELLO 1= 'HELLOz17709l4928x2e5k40(0,4576)(1,5088)(2,5600)(3,6112)(4,6624)(5,7168)(6,7680)(7,8192)(8,8704)(9,9216)(10,9728)(11,10240)(12,10752)(13,8819)(14,17639)\f3 13i6I Input destined for an explicit call to OBTAIN (or READ, CHAR-IN, etc.) are underlined.z17709l4057x3e3jk40(1270)\39f3 6f0 5f3 4f0 2f3 7f0 1> (READ PRIMARY-STREAM) HELLO 1= 'HELLOz17709l4928x2e5k40(0,4586)(1,5080)(2,5609)(3,6103)(4,6632)(5,7161)(6,7691)(7,8184)(8,8714)(9,9208)(10,9737)(11,10231)(12,10760)(13,10848)(14,17463)\f3 24i1uI5U4i6I Output produced by an explicit call to PRINT (or OUTPUT, etc.) is italicised and underlined.z17709l4057x3e3jk40(1270)\39f3 5f0 5f3 6f0 1> (PRINT 'HELLO PRIMARY-STREAM) HELLO 1= 'OKz17709l4928x2e5k40(0,4586)\f3 32b1uBi5UI4i3I Note that in the interest of readability several liberties have been taken with the formatting of output expressions actual results may vary.z17709l4057x3e3jk40(1270) 9. To facilitate the writing of macros and other reflective procedures, the argument-to-parameter pattern matcher (BIND) will convert a rail-designating argument into a sequence of designators. For example, '[123] will be converted to ['1'2'3] in order to fit the pattern [ABC]. This is consistent with the polymorphism of 1ST and REST, etc. (1ST '[1 2 3]) and (1ST ['1 '2 '3]) both normalise to '1. z17709l4057d3528x3e3jk80(0,4057)(1,65535)(2,65535)(3,65535)(4,65535)(5,65535)(6,65535)(7,65535)(8,65535)(9,65535)(10,65535)(11,65535)(12,65535)(13,65535)(14,65535)\f7 2f0 113f3 4f0 89f3 3f7 1f3 1f7 1f3 2f0 22f3 3f7 1f3 2f7 1f3 3f0 29f3 2f7 1f3 1f7 1f3 1f0 48f3 3f0 5f3 4f0 9f3 14f0 5f3 16f0 19f3 2f0 10. All standard procedures return a result. Those that accomplish a side-effect on environments (SET, REBIND, etc.) return the newly-bound value; others (e.g., OUTPUT) return a gratuitous 'OK. z17709l4057d3352x3e3j\f7 3f0 96f3 3f0 2f3 6f0 52f3 6f0 22f3 3f0 11. Errors: <<< ??? >>>z17709l4057d3352x3e3j\f7 3f0