sl.tex 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551
  1. \begin{document}
  2. \section{Preliminaries}
  3. \subsection{Primitive Data Types}
  4. \begin{Type}{integer}
  5. Integer numbers:
  6. Integers are also called "fixed" numbers. The magnitude of
  7. an integer is unrestricted. Integers in the LISP input stream are
  8. an arbitrary number of integer digits, eventually preceded by
  9. a plus or minus sign.
  10. \begin{Examples}
  11. 22\\
  12. -31415926585\\
  13. \end{Examples}
  14. \end{Type}
  15. \begin{Type}{floating}
  16. Floating point numbers: The precision of floating point
  17. numbers is determined solely by the implementation. In BNF floating
  18. point numbers are recognized by the grammar:
  19. \begin{verbatim}
  20. <base> ::= <unsigned-integer>.|.<unsigned-integer>|
  21. <unsigned-integer>.<unsigned-integer>
  22. <unsigned-floating> ::= <base>|
  23. <base>E<unsigned-integer>|
  24. <base>E-<unsigned-integer>|
  25. <base>E+<unsigned-integer>
  26. <floating> ::= <unsigned-floating>|
  27. +<unsigned-floating>|-<unsigned-floating>
  28. \end{verbatim}
  29. \begin{Examples}
  30. 3.1415\\
  31. 17.0\\
  32. -22e100\\
  33. 1.1e-5
  34. \end{Examples}
  35. \end{Type}
  36. \begin{Type}{id}
  37. An identifier is a string of characters which may have the
  38. following items associated with it.
  39. print name: The characters of the identifier.
  40. flags: An identifier may be tagged with a flag. Access is
  41. by the \nameref{flag}, \nameref{remflag}and
  42. \nameref{flagp} functions.
  43. properties: An identifier may have an indicator-value pair
  44. associated with it. Access is by the
  45. \nameref{put}, \nameref{get}, and \nameref{remprop}
  46. functions.
  47. values: An identifier may have a value associated with
  48. it. Access to values is by \nameref{set} \nameref{setq}
  49. The method by which the value
  50. is attached to the identifier is known as the binding
  51. type, being one of
  52. \nameref{Local Binding}, \nameref{Global Binding},
  53. or \nameref{Fluid Binding}.
  54. functions:
  55. An identifier may have a function or macro associated with
  56. it. Access is by the
  57. \nameref{putd}, \nameref{getd}, and \nameref{remd} functions.
  58. An identifier may not have both a function and a value
  59. associated with it.
  60. \name{oblist} entry: An identifier may be entered and removed from a
  61. structure called the \nameref{oblist}. Its presence on the \name{oblist}
  62. does not directly affect the other properties. Access to
  63. the \name{oblist} is by the
  64. \nameref{intern}, \nameref{remob}, and \nameref{read}
  65. functions.
  66. The maximum length of a Standard LISP identifier is 24
  67. characters (excluding occurrences of the escape character !)
  68. but an implementation may allow more. Special characters
  69. (digits in the first position and punctuation) must be prefixed
  70. with an escape character, an ! in Standard LISP. In BNF
  71. identifiers are recognized by the grammar:
  72. \begin{verbatim}
  73. <special-character> ::= !<any-character>
  74. <alphabetic> ::=
  75. A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|
  76. a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z
  77. <lead-character> ::= <special-character>|<alphabetic>
  78. <regular-character> ::= <lead-character>|<digit>
  79. <last-part> ::= <regular-character> |
  80. <last-part><regular-character>
  81. <id> ::= <lead-character>|<lead-character><last-part>
  82. Note: Using lower case letters in identifiers may cause
  83. portability problems. Lower case letters are automatically
  84. converted to upper case when the \nameref{!*RAISE} flag is T.
  85. \end{verbatim}
  86. \begin{Examples}
  87. a\\
  88. Hugo\\
  89. !1!-otto\\
  90. !*raise\\
  91. this!-is!-a!-long!-id\\
  92. !U!P!P!E!R!-and!-!l!o!w!e!r\\
  93. \end{Examples}
  94. \end{Type}
  95. \begin{Type}{string}
  96. A set of characters enclosed in double quotes as
  97. in "THIS IS A STRING". A quote is included by doubling it as in "HE
  98. SAID, ""LISP""". The maximum size of strings is 80 characters but an
  99. implementation may allow more. Strings are not part of the \nameref{oblist} and
  100. are considered constants like \nameref{number}s, \nameref{vector}s,
  101. and \nameref{function-pointer}s.
  102. \end{Type}
  103. \begin{Type}{dotted-pair}
  104. \index{car}\index{cdr}
  105. A dotted pair is a primitive structure which has a left and right part.
  106. A notation called {\em dot-notation} is used for dotted pairs and
  107. takes the form:
  108. \begin{verbatim}
  109. (<left-part> . <right-part>)
  110. \end{verbatim}
  111. The <left-part> is known as the \nameref{car} portion and the
  112. <right-part> as the \nameref{cdr} portion. The left and right parts may be of any type.
  113. Spaces are used to resolve ambiguity with floating point numbers.
  114. When <left-part> or <right-part> are dotted-pairs themselves,
  115. the \nameref{list-notation} is often more convenient.
  116. \end{Type}
  117. \begin{Type}{vector}
  118. A vector is a primitive uniform structure in which
  119. an integer index is used to access random values in the structure. The
  120. individual elements of a vector may be of any type. Access to vectors
  121. is restricted to functions \nameref{putv}, \nameref{getv}, and
  122. \nameref{upbv}.
  123. A notation for vectors, vector-notation, has the
  124. elements of a vector surrounded by square brackets
  125. \begin{verbatim}
  126. <elements> ::= <any>|<any> <elements>
  127. <vector> ::= [<elements>]
  128. \end{verbatim}
  129. \begin{Examples}
  130. [1 2 3 5 7 11 13 17 19 23]\\
  131. [nil (a) (a . a)]\\
  132. [[1 2 3 4 5][2 4 6 8 10][3 6 9 12 15]]\\
  133. \end{Examples}
  134. \end{Type}
  135. \begin{Type}{function-pointer}
  136. An implementation may have functions which deal
  137. with specific data types other than those listed. The use
  138. of these entities is to be avoided with the exception of a
  139. restricted use of the \name{function-pointer}, an access method to
  140. compiled EXPRs and FEXPRs (see \nameref{Function Types}).
  141. A particular
  142. \name{function-pointer} must
  143. remain valid throughout execution. Systems which change the
  144. location of a function must use either an indirect reference or
  145. change all occurrences of the associated value. There are two
  146. classes of use of function-pointers, those which are supported
  147. by Standard LISP but are not well defined, and those which are
  148. well defined.
  149. \end{Type}
  150. \subsection{Classes of Primitive Data Types}
  151. \begin{Introduction}{Type Classes}
  152. The classes of primitive types are a notational convenience for
  153. describing the properties of functions.
  154. \end{Introduction}
  155. \begin{Type}{boolean}
  156. The set of global variables \{\nameref{T}, \nameref{NIL}\}, or their respective
  157. values, \{T, NIL\}.
  158. \end{Type}
  159. \begin{Type}{extra-boolean}
  160. Any value in the system. Anything that is not \nameref{NIL} has
  161. the boolean interpretation T.
  162. \end{Type}
  163. \begin{Type}{ftype}
  164. The class of definable function types. The set of ids \{EXPR,
  165. FEXPR, MACRO\}. See \nameref{Function Types}.
  166. \end{Type}
  167. \begin{Type}{number}
  168. The set of \{\nameref{integer}, \nameref{floating}\}.
  169. \end{Type}
  170. \begin{Type}{constant}
  171. The set of \{\nameref{integer}, \nameref{floating}, \nameref{string},
  172. \nameref{vector}, \nameref{function-pointer} \}.
  173. Constants evaluate to themselves (see \nameref{eval})
  174. \end{Type}
  175. \begin{Type}{any}
  176. The set of \{\nameref{integer}, \nameref{floating}, \nameref{string},
  177. \nameref{id}, \nameref{dotted-pair}, \nameref{vector},
  178. \nameref{function-pointer}\}. An S-expression is another term for any.
  179. All Standard LISP entities have some value unless an \nameref{error}
  180. occurs during evaluation or the function causes transfer of
  181. control (such as \nameref{go} and \nameref{return}).
  182. \end{Type}
  183. \begin{Type}{atom}
  184. The set \nameref{any} - \{\nameref{dotted-pair}\}. Any item wich is not a \name{dotted-pair}
  185. is considered as \name{atom}.
  186. \end{Type}
  187. \subsection{Structures}
  188. \begin{Introduction}{Structures}
  189. Structures are entities created out of the primitive types by the
  190. use of dotted-pairs. Lists are structures very commonly required
  191. as actual parameters to functions. Where a list of homogeneous
  192. entities is required by a function this class will be denoted
  193. by <xxx-list> where xxx is the name of a class of primitives or
  194. structures. Thus a list of ids is an id-list, a list of integers an
  195. integer-list and so on.
  196. \end{Introduction}
  197. \begin{Concept}{List-Notation}
  198. A \name{list} is recursively defined as \nameref{nil} or the dotted-pair
  199. (\nameref{any} . list). A special notation called list-notation is used
  200. to represent lists. List-notation eliminates extra parentheses
  201. and dots. The structure (a . (b . (c . nil))) in list notation
  202. is (a b c). List-notation and dot-notation may be mixed as in
  203. (a b . c) or (a (b . c) d) which are (a . (b . c)) and (a .
  204. ((b . c) . (d . nil))). In BNF lists are recognized by the
  205. grammar:
  206. \begin{verbatim}
  207. <left-part> ::= ( | <left-part> <any>
  208. <list> ::= <left-part>) | <left-part> . <any>)
  209. \end{verbatim}
  210. Note: () is an alternate input representation of nil.
  211. \end{Concept}
  212. \begin{Concept}{alist}
  213. An association list; each element of the list is a
  214. dotted-pair, the CAR part being a key associated with the value
  215. in the CDR part.
  216. \begin{Examples}
  217. ((a . 17)(b . (expt x 2))(q . nil))\\
  218. \end{Examples}
  219. Here a is associated with 17 while b is linked to the square of x
  220. and q points to nil.
  221. \end{Concept}
  222. \begin{Concept}{cond-form}
  223. A cond-form is a list of 2 element lists of the form:
  224. (ANTECEDENT:any CONSEQUENT:any)
  225. The first element will henceforth be known as the antecedent
  226. and the second as the consequent. The antecedent must have a
  227. value. The consequent may have a value or an occurrence of
  228. \nameref{go} or \nameref{return}.
  229. \begin{Examples}
  230. ((greaterp x 0) 1)\\
  231. (t 0)\\
  232. \end{Examples}
  233. \end{Concept}
  234. \begin{Concept}{lambda}
  235. A LAMBDA expression which must have the form (in list
  236. notation):
  237. (LAMBDA <parameters> <body>).
  238. <parameters> is a
  239. list of formal parameters for <body> an S-expression to be
  240. evaluated. The semantics of the evaluation are defined with
  241. the \nameref{eval}.
  242. \begin{Examples}
  243. (lambda(x y)(cons (car x)(cddr y)))
  244. \end{Examples}
  245. \end{Concept}
  246. \begin{Concept}{function}
  247. A LAMBDA expression or a function-pointer to a function. A
  248. function is always evaluated as an EVAL, SPREAD form.
  249. (see \nameref{Function Types}).
  250. \end{Concept}
  251. \section{Notation}
  252. \begin{Introduction}{Function Descriptions}
  253. Each function is provided with a prototypical header line. Each formal
  254. parameter is given a name and suffixed with its allowed type. Lower
  255. case, italic tokens are names of classes and upper case, bold face,
  256. tokens are parameter names referred to in the definition. The type of
  257. the value returned by the function (if any) is suffixed to the
  258. parameter list.
  259. If it is not commonly used the parameter type
  260. may be a specific set enclosed in brackets {...}. For example:
  261. \begin{verbatim}
  262. PUTD(FNAME:id, TYPE:ftype, BODY:{lambda, function-pointer}):id
  263. \end{verbatim}
  264. PUTD is a function with three parameters. The parameter FNAME is
  265. an id to be the name of the function being defined. TYPE is the
  266. type of the function being defined and BODY is a lambda expression
  267. or a function-pointer. PUTD returns the name of the function being
  268. defined.
  269. Functions which accept formal parameter lists of arbitrary length
  270. have the type class and parameter enclosed in square brackets
  271. indicating that zero or more occurrences of that argument are
  272. permitted. For example:
  273. \begin{verbatim}
  274. AND([U:any]):extra-boolean
  275. \end{verbatim}
  276. AND is a function which accepts zero or more arguments which may be
  277. of any type.
  278. \end{Introduction}
  279. \begin{Introduction}{Function Types}
  280. \index{eval type}\index{noeval type}
  281. \index{spread type}\index{nospread type}
  282. \index{expr type}\index{macro type}
  283. EVAL type functions are those which are invoked with evaluated
  284. arguments. NOEVAL functions are invoked with unevaluated arguments.
  285. SPREAD type functions have their arguments passed in one-to-one
  286. correspondence with their formal parameters. NOSPREAD functions
  287. receive their arguments as a single list. EVAL, SPREAD functions
  288. are associated with EXPRs and NOEVAL, NOSPREAD functions with
  289. FEXPRs. EVAL, NOSPREAD and NOEVAL, SPREAD functions can be
  290. simulated using NOEVAL, NOSPREAD functions or MACROs.
  291. EVAL, SPREAD type functions may have a maximum of 15 parameters.
  292. There is no limit on the number of parameters a NOEVAL, NOSPREAD
  293. function or MACRO may have.
  294. In the context of the description of an EVAL, SPREAD function, then
  295. we speak of the formal parameters we mean their actual values.
  296. However, in a NOEVAL, NOSPREAD function it is the unevaluated actual
  297. parameters.
  298. A third function type, the MACRO, implements functions which create
  299. S-expressions based on actual parameters. When a macro invocation
  300. is encountered, the body of the macro, a lambda expression, is
  301. invoked as a NOEVAL, NOSPREAD function with the macro's invocation
  302. bound as a list to the macros single formal parameter. When the
  303. macro has been evaluated the resulting S-expression is reevaluated.
  304. The description of \nameref{eval} and \nameref{expand} provide precise
  305. details.
  306. \end{Introduction}
  307. \begin{Introduction}{Messages}
  308. \index{error}\index{warning}
  309. Many functions detect errors. The description of such functions
  310. will include these error conditions and suggested formats for
  311. display of the generated error messages. A call on the
  312. \nameref{error}
  313. function is implied but the error number is not specified by
  314. Standard LISP. In some cases a warning message is sufficient. To
  315. distinguish between errors and warnings, errors are prefixed with
  316. five asterisks and warnings with only three.
  317. Primitive functions check arguments that must be of a certain
  318. primitive type for being of that type and display an error message
  319. if the argument is not correct. The type mismatch error always
  320. takes the form:
  321. \begin{verbatim}
  322. ***** PARAMETER not TYPE for FN
  323. \end{verbatim}
  324. Here PARAMETER is the unacceptable actual parameter, TYPE is the
  325. type that PARAMETER was supposed to be. FN is the name of the
  326. function that detected the error.
  327. \end{Introduction}
  328. \begin{Introduction}{Comments}
  329. The character \% signals the start of a comment, text to be ignored during
  330. parsing. A comment is terminated by the end of the line it is on. The
  331. function \nameref{readch}must be able to read a comment one character at a
  332. time. Comments are transparent to the function READ. The percent sign
  333. may occur as a character in identifiers by preceding it with the escape
  334. character.
  335. (setq a 17) \% this is a comment
  336. \end{Introduction}
  337. %-----------------------------------------------------------------
  338. \section{Elementary Predicates}
  339. %-----------------------------------------------------------------
  340. \begin{Introduction}{Elementary Predicates}
  341. Functions in this section return \nameref{T} when the condition defined is met
  342. and \nameref{NIL} when it is not. Defined are type checking functions and
  343. elementary comparisons.
  344. \end{Introduction}
  345. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  346. \begin{Function}{atom}
  347. \begin{verbatim}
  348. ATOM(U:any):boolean eval, spread
  349. \end{verbatim}
  350. Returns T if U is not a \nameref{dotted-pair}.
  351. \begin{verbatim}
  352. EXPR PROCEDURE ATOM(U);
  353. NULL PAIRP U;
  354. \end{verbatim}
  355. \end{Function}
  356. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  357. \begin{Function}{codep}
  358. \begin{verbatim}
  359. CODEP(U:any):boolean eval, spread
  360. \end{verbatim}
  361. Returns T if U is a \nameref{function-pointer}.
  362. \end{Function}
  363. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  364. \begin{Function}{constantp}
  365. \begin{verbatim}
  366. CONSTANTP(U:any):boolean eval, spread
  367. \end{verbatim}
  368. Returns T if U is a constant (a \nameref{number},
  369. \nameref{string}, \nameref{function-pointer}, or \nameref{vector}).
  370. \begin{verbatim}
  371. EXPR PROCEDURE CONSTANTP(U);
  372. NULL OR(PAIRP U, IDP U);
  373. \end{verbatim}
  374. \end{Function}
  375. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  376. \begin{Function}{eq}
  377. \begin{verbatim}
  378. EQ(U:any, V:any):boolean eval, spread
  379. \end{verbatim}
  380. Returns T if U points to the same object as V. EQ is not a
  381. reliable comparison between numeric arguments.
  382. \end{Function}
  383. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  384. \begin{Function}{eqn}
  385. \begin{verbatim}
  386. EQN(U:any, V:any):boolean eval, spread
  387. \end{verbatim}
  388. Returns T if U and V are EQ or if U and V are
  389. \nameref{number}s and have the same value and type.
  390. \end{Function}
  391. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  392. \begin{Function}{equal}
  393. \begin{verbatim}
  394. EQUAL(U:any, V:any):boolean eval, spread
  395. \end{verbatim}
  396. Returns T if U and V are the same. Dotted-pairs are
  397. compared recursively to the bottom levels of their trees.
  398. Vectors must have identical dimensions and EQUAL values in
  399. all positions. Strings must have identical characters.
  400. Function pointers must have \nameref{eq} values. Other atoms must be
  401. \nameref{eqn} equal.
  402. \end{Function}
  403. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  404. \begin{Function}{fixp}
  405. \begin{verbatim}
  406. FIXP(U:any):boolean eval, spread
  407. \end{verbatim}
  408. Returns T if U is an \nameref{integer}.
  409. \end{Function}
  410. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  411. \begin{Function}{floatp}
  412. \begin{verbatim}
  413. FLOATP(U:any):boolean eval, spread
  414. \end{verbatim}
  415. Returns T if U is a \nameref{floating} point number.
  416. \end{Function}
  417. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  418. \begin{Function}{idp}
  419. \begin{verbatim}
  420. IDP(U:any):boolean eval, spread
  421. \end{verbatim}
  422. Returns T if U is an \nameref{id}.
  423. \end{Function}
  424. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  425. \begin{Function}{minusp}
  426. \begin{verbatim}
  427. MINUSP(U:any):boolean eval, spread
  428. \end{verbatim}
  429. Returns T if U is a number and less than 0. If U is not a
  430. \nameref{number} or is a positive number, NIL is returned.
  431. \begin{verbatim}
  432. EXPR PROCEDURE MINUSP(U);
  433. IF NUMBERP U THEN LESSP(U, 0) ELSE NIL;
  434. \end{verbatim}
  435. \end{Function}
  436. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  437. \begin{Function}{null}
  438. \begin{verbatim}
  439. NULL(U:any):boolean eval, spread
  440. \end{verbatim}
  441. Returns T if U is NIL.
  442. \begin{verbatim}
  443. EXPR PROCEDURE NULL(U);
  444. U EQ NIL;
  445. \end{verbatim}
  446. \end{Function}
  447. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  448. \begin{Function}{numberp}
  449. \begin{verbatim}
  450. NUMBERP(U:any):boolean eval, spread
  451. \end{verbatim}
  452. Returns T if U is a \nameref{number}.
  453. \begin{verbatim}
  454. EXPR PROCEDURE NUMBERP(U);
  455. IF OR(FIXP U, FLOATP U) THEN T ELSE NIL;
  456. \end{verbatim}
  457. \end{Function}
  458. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  459. \begin{Function}{onep}
  460. \begin{verbatim}
  461. ONEP(U:any):boolean eval, spread.
  462. \end{verbatim}
  463. Returns T if U is a \nameref{number} and has the value 1 or 1.0.
  464. Returns NIL otherwise.
  465. \begin{verbatim}
  466. EXPR PROCEDURE ONEP(U);
  467. IF EQN(U,1) OR EQN(U,1.0) THEN T ELSE NIL;
  468. \end{verbatim}
  469. The definition in the published report is incorrect as it
  470. does not return T for U of 1.0.
  471. \end{Function}
  472. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  473. \begin{Function}{pairp}
  474. \begin{verbatim}
  475. PAIRP(U:any):boolean eval, spread
  476. \end{verbatim}
  477. Returns T if U is a \nameref{dotted-pair}.
  478. \end{Function}
  479. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  480. \begin{Function}{stringp}
  481. \begin{verbatim}
  482. STRINGP(U:any):boolean eval, spread
  483. \end{verbatim}
  484. Returns T if U is a string.
  485. \end{Function}
  486. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  487. \begin{Function}{vectorp}
  488. \begin{verbatim}
  489. VECTORP(U:any):boolean eval, spread
  490. \end{verbatim}
  491. Returns T if U is a vector.
  492. \end{Function}
  493. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  494. \begin{Function}{zerop}
  495. \begin{verbatim}
  496. ZEROP(U:any):boolean eval, spread.
  497. \end{verbatim}
  498. Returns T if U is a number and has the value 0 or 0.0.
  499. Returns NIL otherwise.
  500. The definition in the published report is incorrect as it
  501. does not return T for U of 0.0.
  502. \end{Function}
  503. \section{Functions on Dotted-Pairs}
  504. \begin{Introduction}{Function on Dotted-Pairs}
  505. \index{dotted-pair}
  506. The following are elementary functions on dotted-pairs. All functions
  507. in this section which require dotted-pairs as parameters detect a type
  508. mismatch error if the actual parameter is not a dotted-pair.
  509. \end{Introduction}
  510. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  511. \begin{Function}{car}
  512. \begin{verbatim}
  513. CAR(U:dotted-pair):any eval, spread
  514. \end{verbatim}
  515. CAR(CONS(a, b)) -> a. The left part of U is returned. The
  516. type mismatch error occurs if U is not a dotted-pair.
  517. \end{Function}
  518. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  519. \begin{Function}{cdr}
  520. \begin{verbatim}
  521. CDR(U:dotted-pair):any eval, spread
  522. \end{verbatim}
  523. CDR(CONS(a, b)) -> b. The right part of U is returned. The
  524. type mismatch error occurs if U is not a dotted-pair.
  525. \end{Function}
  526. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  527. \begin{Function}{caar}
  528. \index{CAAAAR}\index{CAAAR}\index{CAAADR}\index{CAADR}
  529. \index{CADR}\index{CAADAR}\index{CADAR}\index{CDAR}\index{CAADDR}
  530. \index{CADDR}\index{CDDR}\index{CADAAR}\index{CDAAR}\index{CADADR}
  531. \index{CDADR}\index{CADDAR}\index{CDDAR}\index{CADDDR}\index{CDDDR}
  532. \index{CDAAAR}\index{CDAADR}\index{CDADAR}\index{CDADDR}\index{CDDAAR}
  533. \index{CDDADR}\index{CDDDAR}\index{CDDDDR}
  534. The composites of CAR and CDR are supported up to 4 levels, namely:
  535. CAAAAR CAAAR CAAR CAAADR CAADR CADR
  536. CAADAR CADAR CDAR CAADDR CADDR CDDR
  537. CADAAR CDAAR CADADR CDADR CADDAR CDDAR
  538. CADDDR CDDDR CDAAAR CDAADR CDADAR CDADDR
  539. CDDAAR CDDADR CDDDAR CDDDDR
  540. Here e.g. (cdar x) is equivlaent to (cdr (car x)).
  541. \end{Function}
  542. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  543. \begin{Function}{cons}
  544. \begin{verbatim}
  545. CONS(U:any, V:any):dotted-pair eval, spread
  546. \end{verbatim}
  547. Returns a dotted-pair which is not \nameref{eq} to anything and has U
  548. as its \nameref{car} part and V as its nameref(cdr) part.
  549. \end{Function}
  550. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  551. \begin{Function}{list}
  552. \begin{verbatim}
  553. LIST([U:any]):list noeval, nospread, or macro
  554. \end{verbatim}
  555. A list of the evaluation of each element of U is returned.
  556. The order of evaluation nead not be first to last as the
  557. following definition implies.
  558. \begin{verbatim}
  559. FEXPR PROCEDURE LIST(U);
  560. EVLIS U;
  561. \end{verbatim}
  562. The published report's definition implies a specific
  563. ordering.
  564. \end{Function}
  565. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  566. \begin{Function}{rplaca}
  567. \begin{verbatim}
  568. RPLACA(U:dotted-pair, V:any):dotted-pair eval, spread
  569. \end{verbatim}
  570. The \nameref{car} portion of the dotted-pair U is replaced by V. If
  571. dotted-pair U is (a . b) then (V . b) is returned. The type
  572. mismatch error occurs if U is not a dotted-pair.
  573. \end{Function}
  574. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  575. \begin{Function}{rplacd}
  576. \begin{verbatim}
  577. RPLACD(U:dotted-pair, V:any):dotted-pair eval, spread
  578. \end{verbatim}
  579. The \nameref{cdr} portion of the dotted-pair U is replaced by V. If
  580. dotted-pair U is (a . b) then (a . V) is returned. The
  581. type mismatch error occurs if U is not a dotted-pair.
  582. \end{Function}
  583. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  584. \section{Functions for Identifiers}
  585. \begin{Concept}{oblist}
  586. The following functions deal with identifiers and the \nameref{oblist},
  587. the structure of which is not defined.
  588. The \name{oblist} is an internal stucture where \nameref{id}s
  589. are kept. The function of the \name{oblist} is
  590. to provide a symbol table for identifiers created during input.
  591. Identifiers created by \nameref{read} which have the same characters will
  592. therefore refer to the same object (see the \nameref{eq} function).
  593. Identifiers created by \nameref{gensym} or \nameref{compress} are
  594. not member of the \name{oblist} and therefore they are not
  595. unique even if they are represented by the same character
  596. sequence on output. The function \nameref{intern} is used
  597. to create an equivalent unique \name{id} which then is
  598. member of the \name{oblist}.
  599. \end{Concept}
  600. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  601. \begin{Function}{compress}
  602. \begin{verbatim}
  603. COMPRESS(U:id-list):{atom-vector} eval, spread
  604. \end{verbatim}
  605. U is a list of single character identifiers which is built
  606. into a Standard LISP entity and returned. Recognized are
  607. \nameref{number}s, \nameref{string}s,
  608. and identifiers (see \nameref{id}) with the \name{escape} character
  609. prefixing special characters. Function pointers
  610. may be compressed but this is an undefined use. If an entity
  611. cannot be parsed out of U or characters are left over after
  612. parsing an error occurs:
  613. \begin{verbatim}
  614. ***** Poorly formed atom in COMPRESS
  615. \end{verbatim}
  616. \end{Function}
  617. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  618. \begin{Function}{explode}
  619. \begin{verbatim}
  620. EXPLODE(U:{atom}-{vector}):id-list eval, spread
  621. \end{verbatim}
  622. Returned is a list of interned characters representing the
  623. characters to print of the value of U. The primitive data
  624. types have these formats:
  625. \nameref{integer}: Leading zeroes are suppressed and a minus sign
  626. prefixes the digits if the integer is negative.
  627. \nameref{floating}: The value appears in the format [-]0.nn...nnE[-]mm
  628. if the magnitude of the number is too large or small to
  629. display in [-]nnnn.nnnn format. The crossover point is
  630. determined by the implementation.
  631. \nameref{id}: The characters of the print name of the identifier
  632. are produced with special characters prefixed with the
  633. escape character.
  634. \nameref{string}: The characters of the string are produced surrounded
  635. by double quotes "...".
  636. \nameref{function-pointer}: The value of the function-pointer is created
  637. as a list of characters conforming to the conventions of
  638. the system site.
  639. The type mismatch error occurs if U is not a number,
  640. identifier, string, or function-pointer.
  641. \end{Function}
  642. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  643. \begin{Function}{gensym}
  644. \begin{verbatim}
  645. GENSYM():identifier eval, spread
  646. \end{verbatim}
  647. Creates an identifier which is not interned on the \nameref{oblist} and
  648. consequently not \nameref{eq} to anything else.
  649. \end{Function}
  650. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  651. \begin{Function}{intern}
  652. \begin{verbatim}
  653. INTERN(U:{id,string}):id eval, spread
  654. \end{verbatim}
  655. INTERN searches the \nameref{oblist} for an identifier with the same
  656. print name as U and returns the identifier on the \name{oblist} if a
  657. match is found. Any properties and global values associated
  658. with U may be lost. If U does not match any entry, a
  659. new one is created and returned. If U has more than the
  660. maximum number of characters permitted by the implementation
  661. (the minimum number is 24) an error occurs:
  662. \begin{verbatim}
  663. ***** Too many characters to INTERN
  664. \end{verbatim}
  665. \end{Function}
  666. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  667. \begin{Function}{remob}
  668. \begin{verbatim}
  669. REMOB(U:id):id eval, spread
  670. \end{verbatim}
  671. If U is present on the \nameref{oblist} it is removed. This does not
  672. affect U having properties, flags, functions and the like. U
  673. is returned.
  674. \end{Function}
  675. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  676. \section{Property List Functions}
  677. \begin{Introduction}{Property List Functions}
  678. With each id in the system is a \name{property list}, a set of entities
  679. which are associated with the id for fast access. These entities are
  680. called \nameindex{flags} if their use gives the id a single valued
  681. property, and \nameindex{properties} if the id is to have a multivalued
  682. attribute: an indicator with a property.
  683. Flags and indicators may clash, consequently care should be taken to
  684. avoid this occurrence. Flagging X with an id which already is an
  685. indicator for X may result in that indicator and associated property
  686. being lost. Likewise, adding an indicator which is the same id as a
  687. flag may result in the flag being destroyed.
  688. \end{Introduction}
  689. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  690. \begin{Function}{flag}
  691. \begin{verbatim}
  692. FLAG(U:id-list, V:id):NIL eval, spread
  693. \end{verbatim}
  694. U is a list of ids which are flagged with V. The effect of
  695. \name{flag} is that \nameref{flagp} will have the value T for those ids of U
  696. which were flagged. Both V and all the elements of U must be
  697. identifiers or the type mismatch error occurs.
  698. \begin{Examples}
  699. flag('(u v),'symmetric)\\
  700. \end{Examples}
  701. Note: If you want to flag a single \name{id} you must put it into
  702. a list before calling the function \name{flag}. A flag is removed
  703. by \nameref{remflag}
  704. \end{Function}
  705. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  706. \begin{Function}{flagp}
  707. \begin{verbatim}
  708. FLAGP(U:any, V:any):boolean eval, spread
  709. \end{verbatim}
  710. Returns T if U has been previously flagged (see \nameref{flag}}
  711. with V, else NIL. Returns NIL if either U or V is not an \nameref{id}.
  712. \end{Function}
  713. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  714. \begin{Function}{get}
  715. \begin{verbatim}
  716. GET(U:any, IND:any):any eval, spread
  717. \end{verbatim}
  718. Returns the property associated with indicator IND from the
  719. property list of U. If U does not have indicator IND, NIL is
  720. returned. GET cannot be used to access functions (use GETD
  721. instead). For setting a property use the function \nameref{put}.
  722. \end{Function}
  723. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  724. \begin{Function}{put}
  725. \begin{verbatim}
  726. PUT(U:id, IND:id, PROP:any):any eval, spread
  727. \end{verbatim}
  728. The indicator IND with the property PROP is placed on the
  729. property list of the id U. If the action of PUT occurs, the
  730. value of PROP is returned. If either of U and IND are not
  731. ids the type mismatch error will occur and no property will
  732. be placed. PUT cannot be used to define functions
  733. (use \nameref{putd} instead). The values stored on the property
  734. list can be retrieved using \nameref{get}. \nameref{remprop}
  735. removes a property.
  736. \begin{Examples}
  737. put('otto,'hugo,'(a))\\
  738. get('otto,'hugo) & (a)\\
  739. put('otto,'hugo,'(b))\\
  740. get('otto,'hugo) & (b)\\
  741. remprop('otto,'hugo)\\
  742. get('otto,'hugo) & nil\\
  743. \end{Examples}
  744. \end{Function}
  745. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  746. \begin{Function}{remflag}
  747. \begin{verbatim}
  748. REMFLAG(U:any-list, V:id):NIL eval, spread
  749. \end{verbatim}
  750. Removes the flag V from the property list of each member of
  751. the list U. Both V and all the elements of U must be ids or
  752. the type mismatch error will occur (see \nameref{flag}).
  753. \end{Function}
  754. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  755. \begin{Function}{remprop}
  756. \begin{verbatim}
  757. REMPROP(U:any, IND:any):any eval, spread
  758. \end{verbatim}
  759. Removes the property with indicator IND from the property
  760. list of U. Returns the removed property or NIL if there was
  761. no such indicator (see \nameref{put}}.
  762. \end{Function}
  763. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  764. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  765. \section{Function Definition}
  766. \begin{Introduction}{Function Definition}
  767. Functions in Standard LISP are global entities. To avoid
  768. function-variable naming clashes no variable may have the same name as
  769. a function.
  770. \end{Introduction}
  771. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  772. \begin{Function}{de}
  773. \index{expr}
  774. \begin{verbatim}
  775. DE(FNAME:id, PARAMS:id-list, FN:any):id noeval, nospread
  776. \end{verbatim}
  777. The function FN with the formal parameter list PARAMS is
  778. added to the set of defined functions with the name FNAME.
  779. Any previous definitions of the function are lost. The
  780. function created is of type EXPR (see \nameref{Function Types}). If \nameref{*COMP} is
  781. non-NIL, the EXPR is first compiled. The name of the defined
  782. function is returned.
  783. \begin{verbatim}
  784. FEXPR PROCEDURE DE(U);
  785. PUTD(CAR U, 'EXPR, LIST('LAMBDA, CADR U, CADDR U));
  786. \end{verbatim}
  787. \end{Function}
  788. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  789. \begin{Function}{df}
  790. \index{fexpr}
  791. \begin{verbatim}
  792. DF(FNAME:id, PARAM:id-list, FN:any):id noeval, nospread
  793. \end{verbatim}
  794. The function FN with formal parameter PARAM is added to the
  795. set of defined functions with the name FNAME. Any previous
  796. definitions of the function are lost. The function created
  797. is of type FEXPR (see \nameref{Function Types}). If \nameref{*COMP} is T the FEXPR
  798. is first compiled. The name of the defined function is
  799. returned.
  800. \begin{verbatim}
  801. FEXPR PROCEDURE DF(U);
  802. PUTD(CAR U, 'FEXPR, LIST('LAMBDA, CADR U, CADDR U));
  803. \end{verbatim}
  804. \end{Function}
  805. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  806. \begin{Function}{dm}
  807. \index{macro}
  808. \begin{verbatim}
  809. DM(MNAME:id, PARAM:id-list, FN:any):id noeval, nospread
  810. \end{verbatim}
  811. The macro FN with the formal parameter PARAM is added to the
  812. set of defined functions with the name MNAME. Any previous
  813. definitions of the function are overwritten. The function
  814. created is of type MACRO (see \nameref{Function Types}).
  815. The name of the macro is returned.
  816. \begin{verbatim}
  817. FEXPR PROCEDURE DM(U);
  818. PUTD(CAR U, 'MACRO, LIST('LAMBDA, CADR U, CADDR U));
  819. \end{verbatim}
  820. \end{Function}
  821. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  822. \begin{Function}{getd}
  823. \begin{verbatim}
  824. GETD(FNAME:any):{NIL, dotted-pair} eval, spread
  825. \end{verbatim}
  826. If FNAME is not the name of a defined function, NIL
  827. is returned. If FNAME is a defined function then the
  828. dotted-pair
  829. \begin{verbatim}
  830. (TYPE:ftype . DEF:{function-pointer, lambda})
  831. \end{verbatim}
  832. is returned.
  833. \end{Function}
  834. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  835. \begin{Function}{putd}
  836. \begin{verbatim}
  837. PUTD(FNAME:id, TYPE:ftype, BODY:function):id eval, spread
  838. \end{verbatim}
  839. Creates a function with name FNAME and definition BODY of
  840. type TYPE. If PUTD succeeds the name of the defined function
  841. is returned. The effect of PUTD is that GETD will return a
  842. dotted-pair with the functions type and definition. Likewise
  843. the \nameref{globalp} predicate will return T when queried with the
  844. function name.
  845. If the function FNAME has already been declared as a GLOBAL
  846. or FLUID variable the error:
  847. \begin{verbatim}
  848. ***** FNAME is a non-local variable
  849. \end{verbatim}
  850. occurs and the function will not be defined. If function
  851. FNAME already exists a warning message will appear:
  852. \begin{verbatim}
  853. *** FNAME redefined
  854. \end{verbatim}
  855. The function defined by PUTD will be compiled before
  856. definition if \nameref{*COMP} variable is non-NIL.
  857. \end{Function}
  858. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  859. \begin{Function}{remd}
  860. \begin{verbatim}
  861. REMD(FNAME:id):{NIL, dotted-pair} eval, spread
  862. \end{verbatim}
  863. Removes the function named FNAME from the set of defined
  864. functions. Returns the (ftype . function) dotted-pair or
  865. NIL as does \nameref)getd}. The global/function attribute of FNAME is
  866. removed and the name may be used subsequently as a variable.
  867. \end{Function}
  868. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  869. \section{Variables and Bindings}
  870. \begin{Introduction}{Scope}
  871. \index{variables}
  872. A variable is a place holder for a Standard LISP entity which is said
  873. to be bound to the variable. The scope of a variable is the range over
  874. which the variable has a defined value. There are three different
  875. binding mechanisms in Standard LISP:
  876. \nameref{Local Binding}, \nameref{Global Binding}, and
  877. \nameref{Fluid Binding}.
  878. \end{Introduction}
  879. \begin{Concept}{Local Binding}
  880. \index{variables}
  881. This type of binding occurs
  882. only in compiled functions. Local variables occur as formal parameters
  883. in \nameref{lambda} expressions (function arguments)
  884. and as \nameref{prog} form variables. The binding occurs
  885. when a lambda expression is evaluated or when a \name{prog} form is executed.
  886. The scope of a local variable is the body of the function in which it
  887. is defined.
  888. \end{Concept}
  889. \begin{Concept}{Global Binding}
  890. \index{variables}
  891. Only one binding of a
  892. global variable exists at any time allowing direct access to the value
  893. bound to the variable. The scope of a global variable is universal.
  894. Variables declared \nameref{global} may not appear as parameters
  895. in \nameref{lambda} expressions (function arguments)
  896. or as \nameref{prog} form variables. A variable must be declared
  897. \name{global} prior to its use as a global variable since the default type
  898. for undeclared variables is \nameref{fluid}.
  899. \end{Concept}
  900. \begin{Concept}{Fluid Binding}
  901. \index{variables}
  902. Fluid variables are global
  903. in scope but may occur as \name{fluid} formal parameters or
  904. \nameref{prog} form variables. In interpreted functions all formal parameters
  905. and \name{prog} form variables are considered to have fluid binding until
  906. changed to local binding by compilation. When \name{fluid} variables are
  907. used as parameters (\nameref{lambda} expressions}
  908. they are rebound in such a way that the previous
  909. binding may be restored. All references to \name{fluid} variables are to the
  910. currently active binding.
  911. \end{Concept}
  912. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  913. \begin{Function}{fluid}
  914. \index{variables}
  915. \begin{verbatim}
  916. FLUID(IDLIST:id-list):NIL eval, spread
  917. \end{verbatim}
  918. The ids in IDLIST are declared as FLUID type variables (ids
  919. not previously declared are initialized to NIL). Variables
  920. in IDLIST already declared FLUID are ignored. Changing a
  921. variable's type from GLOBAL to FLUID is not permissible and
  922. results in the error:
  923. \begin{verbatim}
  924. ***** ID cannot be changed to FLUID
  925. \end{verbatim}
  926. \end{Function}
  927. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  928. \begin{Function}{fluidp}
  929. \index{variables}
  930. \begin{verbatim}
  931. FLUIDP(U:any):boolean eval, spread
  932. \end{verbatim}
  933. If U has been declared by \nameref{fluid} T is
  934. returned, otherwise NIL is returned.
  935. \end{Function}
  936. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  937. \begin{Function}{global}
  938. \index{variables}
  939. \begin{verbatim}
  940. GLOBAL(IDLIST:id-list):NIL eval, spread
  941. \end{verbatim}
  942. The ids of IDLIST are declared global type variables. If
  943. an id has not been declared previously it is initialized to
  944. NIL. Variables already declared GLOBAL are ignored. Changing
  945. a variables type from FLUID to GLOBAL is not permissible and
  946. results in the error:
  947. \begin{verbatim}
  948. ***** ID cannot be changed to GLOBAL
  949. \end{verbatim}
  950. \end{Function}
  951. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  952. \begin{Function}{globalp}
  953. \index{variables}
  954. \begin{verbatim}
  955. GLOBALP(U:any):boolean eval, spread
  956. \end{verbatim}
  957. If U has been declared GLOBAL or is the name of a defined
  958. function, T is returned, else NIL is returned.
  959. \end{Function}
  960. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  961. \begin{Function}{set}
  962. \index{variables}
  963. \begin{verbatim}
  964. SET(EXP:id, VALUE:any):any eval, spread
  965. \end{verbatim}
  966. EXP must be an identifier or a type mismatch error occurs.
  967. The effect of SET is replacement of the item bound to
  968. the identifier by VALUE. If the identifier is not a local
  969. variable or has not been declared GLOBAL it is automatically
  970. declared FLUID with the resulting warning message:
  971. \begin{verbatim}
  972. *** EXP declared FLUID
  973. \end{verbatim}
  974. EXP must not evaluate to T or NIL or an error occurs:
  975. \begin{verbatim}
  976. ***** Cannot change T or NIL
  977. \end{verbatim}
  978. \end{Function}
  979. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  980. \begin{Function}{setq}
  981. \index{variables}
  982. \begin{verbatim}
  983. SETQ(VARIABLE:id, VALUE:any):any noeval, nospread
  984. \end{verbatim}
  985. If VARIABLE is not local or GLOBAL it is by default declared
  986. FLUID and the warning message:
  987. \begin{verbatim}
  988. *** VARIABLE declared FLUID
  989. \end{verbatim}
  990. appears. The value of the current binding of VARIABLE is
  991. replaced by the value of VALUE. VARIABLE must not be T or NIL
  992. or an error occurs:
  993. \begin{verbatim}
  994. ***** Cannot change T or NIL
  995. \end{verbatim}
  996. \begin{verbatim}
  997. MACRO PROCEDURE SETQ(X);
  998. LIST('SET, LIST('QUOTE, CADR X), CADDR X);
  999. \end{verbatim}
  1000. \end{Function}
  1001. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1002. \begin{Function}{unfluid}
  1003. \index{variables}
  1004. \begin{verbatim}
  1005. UNFLUID(IDLIST:id-list):NIL eval, spread
  1006. \end{verbatim}
  1007. The variables in IDLIST that have been declared as \nameref{fluid}
  1008. variables are no longer considered as fluid variables.
  1009. Others are ignored. This affects only compiled functions
  1010. as free variables in interpreted functions are automatically
  1011. considered fluid.
  1012. \end{Function}
  1013. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1014. \section{Program Feature Functions}
  1015. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1016. \begin{Function}{go}
  1017. \index{program control}
  1018. \index{label}
  1019. \begin{verbatim}
  1020. GO(LABEL:id) noeval, nospread
  1021. \end{verbatim}
  1022. GO alters the normal flow of control within a \nameref{prog} function.
  1023. The next statement of a PROG function to be evaluated is
  1024. immediately preceded by LABEL. A GO may only appear in the
  1025. following situations:
  1026. 1. At the top level of a \nameref{prog} referencing a label which
  1027. also appears at the top level of the same prog.
  1028. 2. As the consequent of a \nameref{cond} item of a \name{cond} appearing on
  1029. the top level of a \nameref{prog}.
  1030. 3. As the consequent of a \nameref{cond} item which appears as the
  1031. consequent of a \name{cond} item to any level.
  1032. 4. As the last statement of a \nameref{progn} which appears at
  1033. the top level of a \nameref{prog} or in a \name{progn} appearing in
  1034. the consequent of a \nameref(cond} to any level subject to the
  1035. restrictions of 2 and 3.
  1036. 5. As the last statement of a \nameref{progn}
  1037. within a \name{progn} or as
  1038. the consequent of a \nameref{prog}in a \name{progn}to any level subject
  1039. to the restrictions of 2, 3 and 4.
  1040. If LABEL does not appear at the top level of the \name{prog} in
  1041. which the \name{go} appears, an error occurs:
  1042. \begin{verbatim}
  1043. ***** LABEL is not a known label
  1044. \end{verbatim}
  1045. If the \name{go} has been placed in a position not defined by rules
  1046. 1-5, another error is detected:
  1047. \begin{verbatim}
  1048. ***** Illegal use of GO to LABEL
  1049. \end{verbatim}
  1050. \end{Function}
  1051. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1052. \begin{Function}{prog}
  1053. \index{program control}
  1054. \begin{verbatim}
  1055. PROG(VARS:id-list, [PROGRAM:{id, any}]):any noeval, nospread
  1056. \end{verbatim}
  1057. VARS is a list of ids which are considered fluid when the
  1058. PROG is interpreted and local when compiled (see ``Variables
  1059. and Bindings'', section 3.6 on page 22). The PROGs variables
  1060. are allocated space when the PROG form is invoked and are
  1061. deallocated when the PROG is exited. PROG variables are
  1062. initialized to NIL. The PROGRAM is a set of expressions to be
  1063. evaluated in order of their appearance in the PROG function.
  1064. Identifiers appearing in the top level of the PROGRAM are
  1065. labels which can be referenced by GO. The value returned by
  1066. the PROG function is determined by a \nameref{return} function or NIL
  1067. if the PROG falls through.
  1068. \end{Function}
  1069. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1070. \begin{Function}{progn}
  1071. \index{program control}
  1072. \begin{verbatim}
  1073. PROGN([U:any]):any noeval, nospread
  1074. \end{verbatim}
  1075. U is a set of expressions which are executed sequentially.
  1076. The value returned is the value of the last expression.
  1077. \end{Function}
  1078. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1079. \begin{Function}{prog2}
  1080. \index{program control}
  1081. \begin{verbatim}
  1082. PROG2(A:any, B:any)any eval, spread
  1083. \end{verbatim}
  1084. Returns the value of B.
  1085. \begin{verbatim}
  1086. EXPR PROCEDURE PROG2(A, B);
  1087. B;
  1088. \end{verbatim}
  1089. \end{Function}
  1090. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1091. \begin{Function}{return}
  1092. \index{program control}
  1093. \begin{verbatim}
  1094. RETURN(U:any) eval, spread
  1095. \end{verbatim}
  1096. Within a \nameref{prog}, RETURN terminates the evaluation of a PROG
  1097. and returns U as the value of the PROG. The restrictions on
  1098. the placement of RETURN are exactly those of nameref{go}. Improper
  1099. placement of RETURN results in the error:
  1100. \begin{verbatim}
  1101. ***** Illegal use of RETURN
  1102. \end{verbatim}
  1103. \end{Function}
  1104. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1105. \section{Error Handling}
  1106. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1107. \begin{Function}{error}
  1108. \index{error handling}
  1109. \begin{verbatim}
  1110. ERROR(NUMBER:integer, MESSAGE:any) eval, spread
  1111. \end{verbatim}
  1112. NUMBER and MESSAGE are passed back to a surrounding \nameref{errorset}
  1113. (the Standard LISP reader has an ERRORSET). MESSAGE is placed
  1114. in the global variable \nameref{emsg*} and the error number becomes
  1115. the value of the surrounding ERRORSET. \nameref{fluid} variables and
  1116. local bindings are unbound to return to the environment
  1117. of the ERRORSET. Global variables are not affected by the
  1118. process.
  1119. \end{Function}
  1120. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1121. \begin{Function}{errorset}
  1122. \index{error handling}
  1123. \begin{verbatim}
  1124. ERRORSET(U:any, MSGP:boolean, TR:boolean):any eval, spread
  1125. \end{verbatim}
  1126. If an error occurs during the evaluation of U, the value
  1127. of NUMBER from the \nameref{error} call is returned as the value of
  1128. ERRORSET. In addition, if the value of MSGP is non-NIL,
  1129. the MESSAGE from the ERROR call is displayed upon both the
  1130. standard output device and the currently selected output
  1131. device unless the standard output device is not open. The
  1132. message appears prefixed with 5 asterisks. The MESSAGE list
  1133. is displayed without top level parentheses. The MESSAGE
  1134. from the ERROR call will be available in the global variable
  1135. \nameref{emsg*}. The exact format of error messages generated by
  1136. Standard LISP functions described in this document are not
  1137. fixed and should not be relied upon to be in any particular
  1138. form. Likewise, error numbers generated by Standard LISP
  1139. functions are implementation dependent.
  1140. If no error occurs during the evaluation of U, the value of
  1141. (LIST (EVAL U)) is returned.
  1142. If an error has been signaled and the value of TR is non-NIL
  1143. a traceback sequence will be initiated on the selected output
  1144. device. The traceback will display information such as
  1145. unbindings of \nameref{fluid} variables, argument lists and so on in an
  1146. implementation dependent format.
  1147. \end{Function}
  1148. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1149. \section{Functions for Vectors}
  1150. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1151. \begin{Function}{getv}
  1152. \index{vector}
  1153. \begin{verbatim}
  1154. GETV(V:vector, INDEX:integer):any eval, spread
  1155. \end{verbatim}
  1156. Returns the value stored at position INDEX of the \nameref{vector} V.
  1157. The type mismatch error may occur. An error occurs if the
  1158. INDEX does not lie within 0... UPBV(V) inclusive:
  1159. \begin{verbatim}
  1160. ***** INDEX subscript is out of range
  1161. \end{verbatim}
  1162. \end{Function}
  1163. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1164. \begin{Function}{mkvect}
  1165. \index{vector}
  1166. \begin{verbatim}
  1167. MKVECT(UPLIM:integer):vector eval, spread
  1168. \end{verbatim}
  1169. Defines and allocates space for a \nameref{vector} with UPLIM+1
  1170. elements accessed as 0... UPLIM. Each element is initialized
  1171. to NIL. An error will occur if UPLIM is < 0 or there is not
  1172. enough space for a vector of this size:
  1173. \begin{verbatim}
  1174. ***** A vector of size UPLIM cannot be allocated
  1175. \end{verbatim}
  1176. \end{Function}
  1177. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1178. \begin{Function}{putv}
  1179. \index{vector}
  1180. \begin{verbatim}
  1181. PUTV(V:vector, INDEX:integer, VALUE:any):any eval, spread
  1182. \end{verbatim}
  1183. Stores VALUE into the \nameref{vector} V at position INDEX. VALUE is
  1184. returned. The type mismatch error may occur. If INDEX does
  1185. not lie in 0... UPBV(V) an error occurs:
  1186. \begin{verbatim}
  1187. ***** INDEX subscript is out of range
  1188. \end{verbatim}
  1189. \end{Function}
  1190. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1191. \begin{Function}{upbv}
  1192. \index{vector}
  1193. \begin{verbatim}
  1194. UPBV(U:any):NIL,integer eval, spread
  1195. \end{verbatim}
  1196. Returns the upper limit of U if U is a \nameref{vector}, or NIL if it
  1197. is not.
  1198. \end{Function}
  1199. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1200. \section{Boolean Functions, Conditionals}
  1201. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1202. \begin{Function}{and}
  1203. \index{boolean}
  1204. \begin{verbatim}
  1205. AND([U:any]):extra-boolean noeval, nospread
  1206. \end{verbatim}
  1207. AND evaluates each U until a value of NIL is found or the end
  1208. of the list is encountered. If a non-NIL value is the last
  1209. value it is returned, or NIL is returned.
  1210. \begin{verbatim}
  1211. FEXPR PROCEDURE AND(U);
  1212. BEGIN
  1213. IF NULL U THEN RETURN NIL;
  1214. LOOP: IF NULL CDR U THEN RETURN EVAL CAR U
  1215. ELSE IF NULL EVAL CAR U THEN RETURN NIL;
  1216. U := CDR U;
  1217. GO LOOP
  1218. END;
  1219. \end{verbatim}
  1220. \end{Function}
  1221. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1222. \begin{Function}{cond}
  1223. \index{boolean}
  1224. \begin{verbatim}
  1225. COND([U:cond-form]):any noeval, nospread
  1226. \end{verbatim}
  1227. The antecedents of all U's (\nameref{cond-form}s) are evaluated in order of their
  1228. appearance until a non-NIL value is encountered. The
  1229. consequent of the selected U is evaluated and becomes the
  1230. value of the COND. The consequent may also contain the
  1231. special functions \nameref{go} and \nameref{return} subject to the restraints
  1232. given for these functions. In these cases COND does not have
  1233. a defined value, but rather an effect. If no antecedent is
  1234. non-NIL the value of COND is NIL. An error is detected if a U
  1235. is improperly formed:
  1236. \begin{verbatim}
  1237. ***** Improper cond-form as argument of COND
  1238. \end{verbatim}
  1239. \end{Function}
  1240. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1241. \begin{Function}{not}
  1242. \index{boolean}
  1243. \begin{verbatim}
  1244. NOT(U:any):boolean eval, spread
  1245. \end{verbatim}
  1246. If U is NIL, return T else return NIL (same as function
  1247. NULL).
  1248. \begin{verbatim}
  1249. EXPR PROCEDURE NOT(U);
  1250. U EQ NIL;
  1251. \end{verbatim}
  1252. \end{Function}
  1253. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1254. \begin{Function}{or}
  1255. \index{boolean}
  1256. \begin{verbatim}
  1257. OR([U:any]):extra-boolean noeval, nospread
  1258. \end{verbatim}
  1259. U is any number of expressions which are evaluated in order
  1260. of their appearance. When one is found to be non-NIL it is
  1261. returned as the value of OR. If all are NIL, NIL is returned.
  1262. \begin{verbatim}
  1263. FEXPR PROCEDURE OR(U);
  1264. BEGIN SCALAR X;
  1265. LOOP: IF NULL U THEN RETURN NIL
  1266. ELSE IF (X := EVAL CAR U) THEN RETURN X;
  1267. U := CDR U;
  1268. GO LOOP
  1269. END;
  1270. \end{verbatim}
  1271. \end{Function}
  1272. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1273. \section{Arithmetic Functions}
  1274. \begin{Introduction}{Conversion}
  1275. \index{mixed-mode arithmetic}
  1276. Conversions between numeric types are provided explicitly by the
  1277. \nameref{fix} and \nameref{float} functions and implicitly by any
  1278. multi-parameter arithmetic function which receives mixed types of arguments. A
  1279. conversion from fixed to floating point numbers may result in a loss
  1280. of precision without a warning message being generated. Since
  1281. integers may have a greater magnitude that that permitted for floating
  1282. numbers, an error may be signaled when the attempted conversion cannot
  1283. be done.
  1284. Because the magnitude of integers is unlimited the conversion
  1285. of a floating point number to a fixed number is always possible, the
  1286. only loss of precision being the digits to the right of the decimal
  1287. point which are truncated. If a function receives mixed types of
  1288. arguments the general rule will have the fixed numbers converted to
  1289. floating before arithmetic operations are performed. In all cases an
  1290. error occurs if the parameter to an arithmetic function is not a
  1291. number:
  1292. \begin{verbatim}
  1293. \errormessage{***** XXX parameter to FUNCTION is not a number}
  1294. \end{verbatim}
  1295. XXX is the value of the parameter at fault and FUNCTION is the name of
  1296. the function that detected the error. Exceptions to the rule are noted
  1297. where they occur.
  1298. \end{Introduction}
  1299. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1300. \begin{Function}{abs}
  1301. \index{arithmetic}
  1302. \begin{verbatim}
  1303. ABS(U:number):number eval, spread
  1304. \end{verbatim}
  1305. Returns the absolute value of its argument.
  1306. \begin{verbatim}
  1307. EXPR PROCEDURE ABS(U);
  1308. IF LESSP(U, 0) THEN MINUS(U) ELSE U;
  1309. \end{verbatim}
  1310. \end{Function}
  1311. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1312. \begin{Function}{add1}
  1313. \index{arithmetic}
  1314. \begin{verbatim}
  1315. ADD1(U:number):number eval, spread
  1316. \end{verbatim}
  1317. Returns the value of U plus 1 of the same type as U (fixed or
  1318. floating).
  1319. \begin{verbatim}
  1320. EXPR PROCEDURE ADD1(U);
  1321. PLUS2(U, 1);
  1322. \end{verbatim}
  1323. \end{Function}
  1324. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1325. \begin{Function}{difference}
  1326. \index{arithmetic}
  1327. \begin{verbatim}
  1328. DIFFERENCE(U:number, V:number):number eval, spread
  1329. \end{verbatim}
  1330. The value U - V is returned.
  1331. \end{Function}
  1332. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1333. \begin{Function}{divide}
  1334. \index{arithmetic}
  1335. \begin{verbatim}
  1336. DIVIDE(U:number, V:number):dotted-pair eval, spread
  1337. \end{verbatim}
  1338. The dotted-pair (quotient . remainder) is returned. The
  1339. quotient part is computed the same as by QUOTIENT and the
  1340. remainder the same as by REMAINDER. An error occurs if
  1341. division by zero is attempted:
  1342. \begin{verbatim}
  1343. ***** Attempt to divide by 0 in DIVIDE
  1344. \end{verbatim}
  1345. \begin{verbatim}
  1346. EXPR PROCEDURE DIVIDE(U, V);
  1347. (QUOTIENT(U, V) . REMAINDER(U, V));
  1348. \end{verbatim}
  1349. \end{Function}
  1350. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1351. \begin{Function}{expt}
  1352. \index{arithmetic}
  1353. \begin{verbatim}
  1354. EXPT(U:number, V:integer):number eval, spread
  1355. \end{verbatim}
  1356. Returns U raised to the V power. A floating point U to an
  1357. integer power V does not have V changed to a floating number
  1358. before exponentiation.
  1359. \end{Function}
  1360. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1361. \begin{Function}{fix}
  1362. \index{arithmetic}
  1363. \begin{verbatim}
  1364. FIX(U:number):integer eval, spread
  1365. \end{verbatim}
  1366. Returns an integer which corresponds to the truncated value
  1367. of U. The result of conversion must retain all significant
  1368. portions of U. If U is an integer it is returned unchanged.
  1369. \end{Function}
  1370. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1371. \begin{Function}{float}
  1372. \index{arithmetic}
  1373. \begin{verbatim}
  1374. FLOAT(U:number):floating eval, spread
  1375. \end{verbatim}
  1376. The floating point number corresponding to the value of the
  1377. argument U is returned. Some of the least significant
  1378. digits of an integer may be lost do to the implementation of
  1379. floating point numbers. FLOAT of a floating point number
  1380. returns the number unchanged. If U is too large to represent
  1381. in floating point an error occurs:
  1382. \begin{verbatim}
  1383. ***** Argument to FLOAT is too large
  1384. \end{verbatim}
  1385. \end{Function}
  1386. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1387. \begin{Function}{greaterp}
  1388. \index{arithmetic}\index{boolean}
  1389. \begin{verbatim}
  1390. GREATERP(U:number, V:number):boolean eval, spread
  1391. \end{verbatim}
  1392. Returns T if U is strictly greater than V, otherwise returns
  1393. NIL.
  1394. \end{Function}
  1395. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1396. \begin{Function}{lessp}
  1397. \index{arithmetic}\index{boolean}
  1398. \begin{verbatim}
  1399. LESSP(U:number, V:number):boolean eval, spread
  1400. \end{verbatim}
  1401. Returns T if U is strictly less than V, otherwise returns
  1402. NIL.
  1403. \end{Function}
  1404. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1405. \begin{Function}{max}
  1406. \index{arithmetic}
  1407. \begin{verbatim}
  1408. MAX([U:number]):number noeval, nospread, or macro
  1409. \end{verbatim}
  1410. Returns the largest of the values in U. If two or more values
  1411. are the same the first is returned.
  1412. \begin{verbatim}
  1413. MACRO PROCEDURE MAX(U);
  1414. EXPAND(CDR U, 'MAX2);
  1415. \end{verbatim}
  1416. \end{Function}
  1417. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1418. \begin{Function}{max2}
  1419. \index{arithmetic}
  1420. \begin{verbatim}
  1421. MAX2(U:number, V:number):number eval, spread
  1422. \end{verbatim}
  1423. Returns the larger of U and V. If U and V are the same value
  1424. U is returned (U and V might be of different types).
  1425. \begin{verbatim}
  1426. EXPR PROCEDURE MAX2(U, V);
  1427. IF LESSP(U, V) THEN V ELSE U;
  1428. \end{verbatim}
  1429. \end{Function}
  1430. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1431. \begin{Function}{min}
  1432. \index{arithmetic}
  1433. \begin{verbatim}
  1434. MIN([U:number]):number noeval, nospread, or macro
  1435. \end{verbatim}
  1436. Returns the smallest of the values in U. If two or more
  1437. values are the same the first of these is returned.
  1438. \begin{verbatim}
  1439. MACRO PROCEDURE MIN(U);
  1440. EXPAND(CDR U, 'MIN2);
  1441. \end{verbatim}
  1442. \end{Function}
  1443. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1444. \begin{Function}{min2}
  1445. \index{arithmetic}
  1446. \begin{verbatim}
  1447. MIN2(U:number, V:number):number eval, spread
  1448. \end{verbatim}
  1449. Returns the smaller of its arguments. If U and V are the
  1450. same value, U is returned (U and V might be of different
  1451. types).
  1452. \begin{verbatim}
  1453. EXPR PROCEDURE MIN2(U, V);
  1454. IF GREATERP(U, V) THEN V ELSE U;
  1455. \end{verbatim}
  1456. \end{Function}
  1457. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1458. \begin{Function}{minus}
  1459. \index{arithmetic}
  1460. \begin{verbatim}
  1461. MINUS(U:number):number eval, spread
  1462. \end{verbatim}
  1463. Returns -U.
  1464. \begin{verbatim}
  1465. EXPR PROCEDURE MINUS(U);
  1466. DIFFERENCE(0, U);
  1467. \end{verbatim}
  1468. \end{Function}
  1469. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1470. \begin{Function}{plus}
  1471. \index{arithmetic}
  1472. \begin{verbatim}
  1473. PLUS([U:number]):number noeval, nospread, or macro
  1474. \end{verbatim}
  1475. Forms the sum of all its arguments.
  1476. \begin{verbatim}
  1477. MACRO PROCEDURE PLUS(U);
  1478. EXPAND(CDR U, 'PLUS2);
  1479. \end{verbatim}
  1480. \end{Function}
  1481. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1482. \begin{Function}{plus2}
  1483. \index{arithmetic}
  1484. \begin{verbatim}
  1485. PLUS2(U:number, V:number):number eval, spread
  1486. \end{verbatim}
  1487. Returns the sum of U and V.
  1488. \end{Function}
  1489. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1490. \begin{Function}{quotient}
  1491. \index{arithmetic}
  1492. \begin{verbatim}
  1493. QUOTIENT(U:number, V:number):number eval, spread
  1494. \end{verbatim}
  1495. The quotient of U divided by V is returned. Division of
  1496. two positive or two negative integers is conventional. When
  1497. both U and V are integers and exactly one of them is negative
  1498. the value returned is the negative truncation of the absolute
  1499. value of U divided by the absolute value of V. An error
  1500. occurs if division by zero is attempted:
  1501. \begin{verbatim}
  1502. ***** Attempt to divide by 0 in QUOTIENT
  1503. \end{verbatim}
  1504. \end{Function}
  1505. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1506. \begin{Function}{remainder}
  1507. \index{arithmetic}
  1508. \begin{verbatim}
  1509. REMAINDER(U:number, V:number):number eval, spread
  1510. \end{verbatim}
  1511. If both U and V are integers the result is the integer
  1512. remainder of U divided by V. If either parameter is floating
  1513. point, the result is the difference between U and V*(U/V)
  1514. all in floating point. If either number is negative the
  1515. remainder is negative. If both are positive or both are
  1516. negative the remainder is positive. An error occurs if V is
  1517. zero:
  1518. \begin{verbatim}
  1519. ***** Attempt to divide by 0 in REMAINDER
  1520. \end{verbatim}
  1521. \begin{verbatim}
  1522. EXPR PROCEDURE REMAINDER(U, V);
  1523. DIFFERENCE(U, TIMES2(QUOTIENT(U, V), V));
  1524. \end{verbatim}
  1525. \end{Function}
  1526. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1527. \begin{Function}{sub1}
  1528. \index{arithmetic}
  1529. \begin{verbatim}
  1530. SUB1(U:number):number eval, spread
  1531. \end{verbatim}
  1532. Returns the value of U less 1. If U is a FLOAT type number,
  1533. the value returned is U less 1.0.
  1534. \begin{verbatim}
  1535. EXPR PROCEDURE SUB1(U);
  1536. DIFFERENCE(U, 1);
  1537. \end{verbatim}
  1538. \end{Function}
  1539. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1540. \begin{Function}{times}
  1541. \index{arithmetic}
  1542. \begin{verbatim}
  1543. TIMES([U:number]):number noeval, nospread, or macro
  1544. \end{verbatim}
  1545. Returns the product of all its arguments.
  1546. \begin{verbatim}
  1547. MACRO PROCEDURE TIMES(U);
  1548. EXPAND(CDR U, 'TIMES2);
  1549. \end{verbatim}
  1550. \end{Function}
  1551. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1552. \begin{Function}{times2}
  1553. \index{arithmetic}
  1554. \begin{verbatim}
  1555. TIMES2(U:number, V:number):number eval, spread
  1556. \end{verbatim}
  1557. Returns the product of U and V.
  1558. \end{Function}
  1559. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1560. \section{MAP Composite Functions}
  1561. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1562. \begin{Function}{map}
  1563. \begin{verbatim}
  1564. MAP(X:list, FN:function):any eval, spread
  1565. \end{verbatim}
  1566. Applies FN to successive CDR segments of X. NIL is returned.
  1567. \begin{verbatim}
  1568. EXPR PROCEDURE MAP(X, FN);
  1569. WHILE X DO << FN X; X := CDR X >>;
  1570. \end{verbatim}
  1571. \end{Function}
  1572. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1573. \begin{Function}{mapc}
  1574. \begin{verbatim}
  1575. MAPC(X:list, FN:function):any eval, spread
  1576. \end{verbatim}
  1577. FN is applied to successive CAR segments of list X. NIL is
  1578. returned.
  1579. \begin{verbatim}
  1580. EXPR PROCEDURE MAPC(X, FN);
  1581. WHILE X DO << FN CAR X; X := CDR X >>;
  1582. \end{verbatim}
  1583. \end{Function}
  1584. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1585. \begin{Function}{mapcan}
  1586. \begin{verbatim}
  1587. MAPCAN(X:list, FN:function):any eval, spread
  1588. \end{verbatim}
  1589. A concatenated list of FN applied to successive CAR elements
  1590. of X is returned.
  1591. \begin{verbatim}
  1592. EXPR PROCEDURE MAPCAN(X, FN);
  1593. IF NULL X THEN NIL
  1594. ELSE NCONC(FN CAR X, MAPCAN(CDR X, FN));
  1595. \end{verbatim}
  1596. \end{Function}
  1597. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1598. \begin{Function}{mapcar}
  1599. \begin{verbatim}
  1600. MAPCAR(X:list, FN:function):any eval, spread
  1601. \end{verbatim}
  1602. Returned is a constructed list of FN applied to each CAR of
  1603. list X.
  1604. \begin{verbatim}
  1605. EXPR PROCEDURE MAPCAR(X, FN);
  1606. IF NULL X THEN NIL
  1607. ELSE FN CAR X . MAPCAR(CDR X, FN);
  1608. \end{verbatim}
  1609. \end{Function}
  1610. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1611. \begin{Function}{mapcon}
  1612. \begin{verbatim}
  1613. MAPCON(X:list, FN:function):any eval, spread
  1614. \end{verbatim}
  1615. Returned is a concatenated list of FN applied to successive
  1616. CDR segments of X.
  1617. \begin{verbatim}
  1618. EXPR PROCEDURE MAPCON(X, FN);
  1619. IF NULL X THEN NIL
  1620. ELSE NCONC(FN X, MAPCON(CDR X, FN));
  1621. \end{verbatim}
  1622. \end{Function}
  1623. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1624. \begin{Function}{maplist}
  1625. \begin{verbatim}
  1626. MAPLIST(X:list, FN:function):any eval, spread
  1627. \end{verbatim}
  1628. Returns a constructed list of FN applied to successive CDR
  1629. segments of X.
  1630. \begin{verbatim}
  1631. EXPR PROCEDURE MAPLIST(X, FN);
  1632. IFNULL X THEN NIL
  1633. ELSE FN X . MAPLIST(CDR X, FN);
  1634. \end{verbatim}
  1635. \end{Function}
  1636. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1637. \section{Composite Functions}
  1638. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1639. \begin{Function}{apend}
  1640. \begin{verbatim}
  1641. APPEND(U:list, V:list):list eval, spread
  1642. \end{verbatim}
  1643. Returns a constructed list in which the last element of U is
  1644. followed by the first element of V. The list U is copied, V
  1645. is not.
  1646. \begin{verbatim}
  1647. EXPR PROCEDURE APPEND(U, V);
  1648. IF NULL U THEN V
  1649. ELSE CAR U . APPEND(CDR U, V);
  1650. \end{verbatim}
  1651. \end{Function}
  1652. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1653. \begin{Function}{assoc}
  1654. \begin{verbatim}
  1655. ASSOC(U:any, V:alist):{dotted-pair, NIL} eval, spread
  1656. \end{verbatim}
  1657. If U occurs as the CAR portion of an element of the \nameref{alist} V,
  1658. the dotted-pair in which U occurred is returned, else NIL is
  1659. returned. ASSOC might not detect a poorly formed alist so an
  1660. invalid construction may be detected by CAR or CDR.
  1661. \begin{verbatim}
  1662. EXPR PROCEDURE ASSOC(U, V);
  1663. IF NULL V THEN NIL
  1664. ELSE IF ATOM CAR V THEN
  1665. ERROR(000, LIST(V, "is a poorly formed alist"))
  1666. ELSE IF U = CAAR V THEN CAR V
  1667. ELSE ASSOC(U, CDR V);
  1668. \end{verbatim}
  1669. \end{Function}
  1670. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1671. \begin{Function}{deflist}
  1672. \begin{verbatim}
  1673. DEFLIST(U:dlist, IND:id):list eval, spread
  1674. \end{verbatim}
  1675. A "dlist" is a list in which each element is a two element
  1676. list: (ID:id PROP:any). Each ID in U has the indicator
  1677. IND with property PROP placed on its property list by the
  1678. PUT function. The value of DEFLIST is a list of the first
  1679. elements of each two element list. Like \nameref{put}, DEFLIST may not
  1680. be used to define functions.
  1681. \begin{verbatim}
  1682. EXPR PROCEDURE DEFLIST(U, IND);
  1683. IF NULL U THEN NIL
  1684. ELSE << PUT(CAAR U, IND, CADAR U);
  1685. CAAR U >> . DEFLIST(CDR U, IND);
  1686. \end{verbatim}
  1687. \end{Function}
  1688. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1689. \begin{Function}{delete}
  1690. \begin{verbatim}
  1691. DELETE(U:any, V:list):list eval, spread
  1692. \end{verbatim}
  1693. Returns V with the first top level occurrence of U removed
  1694. from it.
  1695. \begin{verbatim}
  1696. EXPR PROCEDURE DELETE(U, V);
  1697. IF NULL V THEN NIL
  1698. ELSE IF CAR V = U THEN CDR V
  1699. ELSE CAR V . DELETE(U, CDR V);
  1700. \end{verbatim}
  1701. \end{Function}
  1702. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1703. \begin{Function}{digit}
  1704. \begin{verbatim}
  1705. DIGIT(U:any):boolean eval, spread
  1706. \end{verbatim}
  1707. Returns T if U is a digit, otherwise NIL.
  1708. \begin{verbatim}
  1709. EXPR PROCEDURE DIGIT(U);
  1710. IF MEMQ(U, '(!0 !1 !2 !3 !4 !5 !6 !7 !8 !9))
  1711. THEN T ELSE NIL;
  1712. \end{verbatim}
  1713. \end{Function}
  1714. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1715. \begin{Function}{length}
  1716. \begin{verbatim}
  1717. LENGTH(X:any):integer eval, spread
  1718. \end{verbatim}
  1719. The top level length of the list X is returned.
  1720. \begin{verbatim}
  1721. EXPR PROCEDURE LENGTH(X);
  1722. IF ATOM X THEN 0
  1723. ELSE PLUS(1, LENGTH CDR X);
  1724. \end{verbatim}
  1725. \end{Function}
  1726. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1727. \begin{Function}{liter}
  1728. \begin{verbatim}
  1729. LITER(U:any):boolean eval, spread
  1730. \end{verbatim}
  1731. Returns T if U is a character of the alphabet, NIL
  1732. otherwise.
  1733. \begin{verbatim}
  1734. EXPR PROCEDURE LITER(U);
  1735. IF MEMQ(U, '(!A !B !C !D !E !F !G !H !I !J !K !L !M
  1736. !N !O !P !Q !R !S !T !U !V !W !X !Y !Z
  1737. !a !b !c !d !e !f !g !h !i !j !k !l !m
  1738. !n !o !p !q !r !s !t !u !v !w !x !y !z))
  1739. \end{verbatim}
  1740. The published report omits escape characters. These are
  1741. required for both upper and lower case as some systems
  1742. default to lower.
  1743. \end{Function}
  1744. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1745. \begin{Function}{member}
  1746. \begin{verbatim}
  1747. MEMBER(A:any, B:list):extra-boolean eval, spread
  1748. \end{verbatim}
  1749. Returns NIL if A is not a member of list B, returns the
  1750. remainder of B whose first element is A.
  1751. \begin{verbatim}
  1752. EXPR PROCEDURE MEMBER(A, B);
  1753. IF NULL B THEN NIL
  1754. ELSE IF A = CAR B THEN B
  1755. ELSE MEMBER(A, CDR B);
  1756. \end{verbatim}
  1757. \end{Function}
  1758. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1759. \begin{Function}{memq}
  1760. \begin{verbatim}
  1761. MEMQ(A:any, B:list):extra-boolean eval, spread
  1762. \end{verbatim}
  1763. Same as \nameref{member} but an \nameref{eq} check is used for comparison.
  1764. \begin{verbatim}
  1765. EXPR PROCEDURE MEMQ(A, B);
  1766. IF NULL B THEN NIL
  1767. ELSE IF A EQ CAR B THEN B
  1768. ELSE MEMQ(A, CDR B);
  1769. \end{verbatim}
  1770. \end{Function}
  1771. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1772. \begin{Function}{nconc}
  1773. \begin{verbatim}
  1774. NCONC(U:list, V:list):list eval, spread
  1775. \end{verbatim}
  1776. Concatenates V to U without copying U. The last CDR of U is
  1777. modified to point to V.
  1778. \begin{verbatim}
  1779. EXPR PROCEDURE NCONC(U, V);
  1780. BEGIN SCALAR W;
  1781. IF NULL U THEN RETURN V;
  1782. W := U;
  1783. WHILE CDR W DO W := CDR W;
  1784. RPLACD(W, V);
  1785. RETURN U
  1786. END;
  1787. \end{verbatim}
  1788. \end{Function}
  1789. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1790. \begin{Function}{pair}
  1791. \begin{verbatim}
  1792. PAIR(U:list, V:list):alist eval, spread
  1793. \end{verbatim}
  1794. U and V are lists which must have an identical number of
  1795. elements. If not, an error occurs (the 000 used in the \nameref{error}
  1796. call is arbitrary and need not be adhered to). Returned is a
  1797. list where each element is a dotted-pair, the CAR of the pair
  1798. being from U, and the CDR the corresponding element from V.
  1799. \begin{verbatim}
  1800. EXPR PROCEDURE PAIR(U, V);
  1801. IF AND(U, V) THEN (CAR U . CAR V) . PAIR(CDR U, CDR V)
  1802. ELSE IF OR(U, V) THEN ERROR(000,
  1803. "Different length lists in PAIR")
  1804. ELSE NIL;
  1805. \end{verbatim}
  1806. \end{Function}
  1807. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1808. \begin{Function}{reverse}
  1809. \begin{verbatim}
  1810. REVERSE(U:list):list eval, spread
  1811. \end{verbatim}
  1812. Returns a copy of the top level of U in reverse order.
  1813. \begin{verbatim}
  1814. EXPR PROCEDURE REVERSE(U);
  1815. BEGIN SCALAR W;
  1816. WHILE U DO << W := CAR U . W;
  1817. U := CDR U >>;
  1818. RETURN W
  1819. END;
  1820. \end{verbatim}
  1821. \end{Function}
  1822. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1823. \begin{Function}{sassoc}
  1824. \begin{verbatim}
  1825. SASSOC(U:any, V:alist, FN:function):any eval, spread
  1826. \end{verbatim}
  1827. Searches the \nameref{alist} V for an occurrence of U. If U is not in
  1828. the alist the evaluation of function FN is returned.
  1829. \begin{verbatim}
  1830. EXPR PROCEDURE SASSOC(U, V, FN);
  1831. IF NULL V THEN FN()
  1832. ELSE IF U = CAAR V THEN CAR V
  1833. ELSE SASSOC(U, CDR V, FN);
  1834. \end{verbatim}
  1835. \end{Function}
  1836. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1837. \begin{Function}{sublis}
  1838. \index{substitution}
  1839. \begin{verbatim}
  1840. SUBLIS(X:alist, Y:any):any eval, spread
  1841. \end{verbatim}
  1842. The value returned is the result of substituting the CDR of
  1843. each element of the alist X for every occurrence of the CAR
  1844. part of that element in Y.
  1845. \begin{verbatim}
  1846. EXPR PROCEDURE SUBLIS(X, Y);
  1847. IF NULL X THEN Y
  1848. ELSE BEGIN SCALAR U;
  1849. U := ASSOC(Y, X);
  1850. RETURN IF U THEN CDR U
  1851. ELSE IF ATOM Y THEN Y
  1852. ELSE SUBLIS(X, CAR Y) .
  1853. SUBLIS(X, CDR Y)
  1854. END;
  1855. \end{verbatim}
  1856. \end{Function}
  1857. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1858. \begin{Function}{subst}
  1859. \index{substitution}
  1860. \begin{verbatim}
  1861. SUBST(U:any, V:any, W:any):any eval, spread
  1862. \end{verbatim}
  1863. The value returned is the result of substituting U for all
  1864. occurrences of V in W.
  1865. \begin{verbatim}
  1866. EXPR PROCEDURE SUBST(U, V, W);
  1867. IF NULL W THEN NIL
  1868. ELSE IF V = W THEN U
  1869. ELSE IF ATOM W THEN W
  1870. ELSE SUBST(U, V, CAR W) . SUBST(U, V, CDR W);
  1871. \end{verbatim}
  1872. \end{Function}
  1873. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1874. \section{Interpreter}
  1875. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1876. \begin{Function}{apply}
  1877. \begin{verbatim}
  1878. APPLY(FN:{id,function}, ARGS:any-list):any eval, spread
  1879. \end{verbatim}
  1880. APPLY returns the value of FN with actual parameters
  1881. ARGS. The actual parameters in ARGS are already in the
  1882. form required for binding to the formal parameters of FN.
  1883. Implementation specific portions described in English are
  1884. enclosed in boxes.
  1885. \begin{verbatim}
  1886. EXPR PROCEDURE APPLY(FN, ARGS);
  1887. BEGIN SCALAR DEFN;
  1888. IF---------------------------------------------
  1889. -Spread the actual parameters in ARGS-
  1890. -following the conventions: for calling-
  1891. -functions, transfer to the entry point of;
  1892. - -
  1893. -the function, and return the value returned-
  1894. ----------------------------------------------
  1895. IF IDP FN THEN RETURN
  1896. IF NULL(DEFN := GETD FN) THEN
  1897. ERROR(000, LIST(FN, "is an undefined function"))
  1898. ELSE IF CAR DEFN EQ 'EXPR THEN
  1899. APPLY(CDR DEFN, ARGS)
  1900. ELSE ERROR(000,
  1901. LIST(FN, "cannot be evaluated by APPLY"));
  1902. IF OR(ATOM FN, NOT(CAR FN EQ 'LAMBDA)) THEN
  1903. ERROR(000,
  1904. LIST(FN, "cannot be evaluated by APPLY"));
  1905. RETURN
  1906. -Bind-the--actual-parameters--in-ARGS--to-the-
  1907. - -
  1908. -formal parameters of the lambda expression.-
  1909. -If the two lists are not of equal length-
  1910. -then ERROR(000, "Number of parameters do not-
  1911. -match"); The value returned is EVAL CADDR-
  1912. ----------------------------------------------
  1913. END;
  1914. \end{verbatim}
  1915. \end{Function}
  1916. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1917. \begin{Function}{eval}
  1918. \begin{verbatim}
  1919. EVAL(U:any):any eval, spread
  1920. \end{verbatim}
  1921. The value of the expression U is computed. Error numbers
  1922. are arbitrary. Portions of EVAL involving machine specific
  1923. coding are expressed in English enclosed in boxes.
  1924. \begin{verbatim}
  1925. EXPR PROCEDURE EVAL(U);
  1926. BEGIN SCALAR FN;
  1927. IF CONSTANTP U THEN RETURN U;
  1928. IF IDP U THEN RETURN
  1929. -U-is-an-id.--Return-the-value-most-currently-
  1930. -bound to U or if there is no such binding:-
  1931. - -
  1932. ----------------------------------------------
  1933. IF PAIRP CAR U THEN RETURN
  1934. IF CAAR U EQ 'LAMBDA THEN APPLY(CAR U, EVLIS CDR U)
  1935. ELSE ERROR(000, LIST(CAR U,
  1936. "improperly formed LAMBDA expression"))
  1937. ELSE IF CODEP CAR U THEN
  1938. RETURN APPLY(CAR U, EVLIS CDR U);
  1939. FN := GETD CAR U;
  1940. IF NULL FN THEN
  1941. ERROR(000, LIST(CAR U, "is an undefined function"))
  1942. ELSE IF CAR FN EQ 'EXPR THEN
  1943. RETURN APPLY(CDR FN, EVLIS CDR U)
  1944. ELSE IF CAR FN EQ 'FEXPR THEN
  1945. RETURN APPLY(CDR FN, LIST CDR U)
  1946. ELSE IF CAR FN EQ 'MACRO THEN
  1947. RETURN EVAL APPLY(CDR FN, LIST U)
  1948. END;
  1949. \end{verbatim}
  1950. see also \nameref{constantp}, \nameref{idp}, \nameref{pairp},
  1951. \nameref{evlis}, nameref{apply}, nameref{getd}
  1952. \end{Function}
  1953. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1954. \begin{Function}{evlis}
  1955. \begin{verbatim}
  1956. EVLIS(U:any-list):any-list eval, spread
  1957. \end{verbatim}
  1958. EVLIS returns a list of the evaluation of each element of U.
  1959. \begin{verbatim}
  1960. EXPR PROCEDURE EVLIS(U);
  1961. IF NULL U THEN NIL
  1962. ELSE EVAL CAR U . EVLIS CDR U;
  1963. \end{verbatim}
  1964. see also \nameref{eval}
  1965. \end{Function}
  1966. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1967. \begin{Function}{expand}
  1968. \index{macro}
  1969. \begin{verbatim}
  1970. EXPAND(L:list, FN:function):list eval, spread
  1971. \end{verbatim}
  1972. FN is a defined function of two arguments to be used in the
  1973. expansion of a \name{macro} defined by \nameref{dm}. EXPAND returns a list in the form:
  1974. \begin{verbatim}
  1975. (FN L (FN L ...(FN L L ) ... ))
  1976. 0 1 n-1 n
  1977. \end{verbatim}
  1978. where n is the number of elements in L, Li is the ith element
  1979. of L.
  1980. \begin{verbatim}
  1981. EXPR PROCEDURE EXPAND(L,FN);
  1982. IF NULL CDR L THEN CAR L
  1983. ELSE LIST(FN, CAR L, EXPAND(CDR L, FN));
  1984. \end{verbatim}
  1985. \end{Function}
  1986. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1987. \begin{Function}{function}
  1988. \begin{verbatim}
  1989. FUNCTION(FN:function):function noeval, nospread
  1990. \end{verbatim}
  1991. The function FN is to be passed to another function. If
  1992. FN is to have side effects its free variables must be \nameref{fluid}
  1993. or \nameref{global}. FUNCTION is like \nameref{quote} but its argument may be
  1994. affected by compilation. We do not consider \nameindex{FUNARG}s in this
  1995. report.
  1996. \end{Function}
  1997. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1998. \begin{Function}{quote}
  1999. \begin{verbatim}
  2000. QUOTE(U:any):any noeval, nospread
  2001. \end{verbatim}
  2002. Stops evaluation and returns U unevaluated.
  2003. \begin{verbatim}
  2004. FEXPR PROCEDURE QUOTE(U);
  2005. CAR U;
  2006. \end{verbatim}
  2007. \end{Function}
  2008. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2009. \section{Input and Output}
  2010. \begin{Introduction}{IO}
  2011. The user normally communicates with Standard LISP through
  2012. \nameindex{standard devices}. The default devices are selected in accordance
  2013. with the conventions of the implementation site. Other input and
  2014. output devices or files may be selected for reading and writing using
  2015. the functions described herein.
  2016. \end{Introduction}
  2017. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2018. \begin{Function}{close}
  2019. \begin{verbatim}
  2020. CLOSE(FILEHANDLE:any):any eval, spread
  2021. \end{verbatim}
  2022. Closes the file with the internal name FILEHANDLE writing
  2023. any necessary end of file marks and such. The value of
  2024. FILEHANDLE is that returned by the corresponding OPEN. The
  2025. value returned is the value of FILEHANDLE. An error occurs if
  2026. the file can not be closed.
  2027. \begin{verbatim}
  2028. ***** FILEHANDLE could not be closed
  2029. \end{verbatim}
  2030. \end{Function}
  2031. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2032. \begin{Function}{eject}
  2033. \begin{verbatim}
  2034. EJECT():NIL eval, spread
  2035. \end{verbatim}
  2036. Skip to the top of the next output page. Automatic EJECTs
  2037. are executed by the print functions when the length set by
  2038. the \nameref{pagelength} function is exceeded.
  2039. \end{Function}
  2040. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2041. \begin{Function}{linelength}
  2042. \begin{verbatim}
  2043. LINELENGTH(LEN:{integer, NIL}):integer eval, spread
  2044. \end{verbatim}
  2045. If LEN is an integer the maximum line length to be printed
  2046. before the print functions initiate an automatic nameref{terpri} is
  2047. set to the value LEN. No initial Standard LISP line length is
  2048. assumed. The previous line length is returned except when
  2049. LEN is NIL. This special case returns the current line length
  2050. and does not cause it to be reset. An error occurs if the
  2051. requested line length is too large for the currently selected
  2052. output file or LEN is negative or zero.
  2053. \begin{verbatim}
  2054. ***** LEN is an invalid line length
  2055. \end{verbatim}
  2056. \end{Function}
  2057. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2058. \begin{Function}{lposn}
  2059. \begin{verbatim}
  2060. LPOSN():integer eval, spread
  2061. \end{verbatim}
  2062. Returns the number of lines printed on the current page. At
  2063. the top of a page, 0 is returned.
  2064. \end{Function}
  2065. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2066. \begin{Function}{open}
  2067. \index{input}\index{output}
  2068. \begin{verbatim}
  2069. OPEN(FILE:any, HOW:id):any eval, spread
  2070. \end{verbatim}
  2071. Open the file with the system dependent name FILE for output
  2072. if HOW is \nameref{eq} to OUTPUT, or input if HOW is \name{eq} to INPUT. If
  2073. the file is opened successfully, a value which is internally
  2074. associated with the file is returned. This value must be
  2075. saved for use by \nameref{wrs} and \nameref{rds}. An error occurs if HOW is
  2076. something other than INPUT or OUTPUT or the file can't be
  2077. opened.
  2078. \begin{verbatim}
  2079. ***** HOW is not option for OPEN
  2080. ***** FILE could not be opened
  2081. \end{verbatim}
  2082. Use the \nameref{close} function to close a file.
  2083. \end{Function}
  2084. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2085. \begin{Function}{pagelength}
  2086. \begin{verbatim}
  2087. PAGELENGTH(LEN:{integer, NIL}):integer eval, spread
  2088. \end{verbatim}
  2089. Sets the vertical length (in lines) of an output page.
  2090. Automatic page \nameref{eject}s are executed by the print functions
  2091. when this length is reached. The initial vertical length
  2092. is implementation specific. The previous page length is
  2093. returned. If LEN is 0, no automatic page ejects will
  2094. occur.
  2095. \end{Function}
  2096. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2097. \begin{Function}{posn}
  2098. \begin{verbatim}
  2099. POSN():integer eval, spread
  2100. \end{verbatim}
  2101. Returns the number of characters in the output buffer. When
  2102. the buffer is empty, 0 is returned.
  2103. \end{Function}
  2104. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2105. \begin{Function}{princ}
  2106. \begin{verbatim}
  2107. PRINC(U:id):id eval, spread
  2108. \end{verbatim}
  2109. U must be a single character id such as produced by \nameref{explode}
  2110. or read by \nameref{readch} or the value of \nameref{$eol$}. The effect is
  2111. the character U displayed upon the currently selected output
  2112. device. The value of \name{!$EOL!$} causes termination of the
  2113. current line like a call to \nameref{terpri}.
  2114. \end{Function}
  2115. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2116. \begin{Function}{print}
  2117. \begin{verbatim}
  2118. PRINT(U:any):any eval, spread
  2119. \end{verbatim}
  2120. Displays U in \nameref{read} readable format and terminates the print
  2121. line. The value of U is returned.
  2122. \begin{verbatim}
  2123. EXPR PROCEDURE PRINT(U);
  2124. << PRIN1 U; TERPRI(); U >>;
  2125. \end{verbatim}
  2126. \end{Function}
  2127. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2128. \begin{Function}{prin1}
  2129. \begin{verbatim}
  2130. PRIN1(U:any):any eval, spread
  2131. \end{verbatim}
  2132. U is displayed in a \nameref{read} readable form. The format
  2133. of display is the result of \nameref{explode} expansion; special
  2134. characters are prefixed with the escape character !, and
  2135. strings are enclosed in "... ". Lists are displayed in
  2136. list-notation and vectors in vector-notation.
  2137. \end{Function}
  2138. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2139. \begin{Function}{prin2}
  2140. \begin{verbatim}
  2141. PRIN2(U:any):any eval, spread
  2142. \end{verbatim}
  2143. U is displayed upon the currently selected print device
  2144. but output is not \nameref{read} readable. The value of U is
  2145. returned. Items are displayed as described in the \nameref{explode}
  2146. function with the exceptions that the escape character does
  2147. not prefix special characters and strings are not enclosed in
  2148. "... ". Lists are displayed in list-notation and vectors in
  2149. vector-notation. The value of U is returned.
  2150. \end{Function}
  2151. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2152. \begin{Function}{rds}
  2153. \begin{verbatim}
  2154. RDS(FILEHANDLE:any):any eval, spread
  2155. \end{verbatim}
  2156. Input from the currently selected input file is suspended
  2157. and further input comes from the file named. FILEHANDLE is
  2158. a system dependent internal name which is a value returned
  2159. by \nameref{open}. If FILEHANDLE is NIL the standard input device is
  2160. selected. When end of file is reached on a non-standard
  2161. input device, the standard input device is reselected. When
  2162. end of file occurs on the standard input device the Standard
  2163. LISP reader terminates. RDS returns the internal name of the
  2164. previously selected input file.
  2165. \begin{verbatim}
  2166. ***** FILEHANDLE could not be selected for input
  2167. \end{verbatim}
  2168. The function name RDS goes back to "read select";
  2169. \end{Function}
  2170. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2171. \begin{Function}{read}
  2172. \begin{verbatim}
  2173. READ():any
  2174. \end{verbatim}
  2175. The next expression from the file currently selected for
  2176. input. Valid input forms are: vector-notation, dot-
  2177. notation, list-notation, numbers, function-pointers, strings,
  2178. and identifiers with escape characters. Identifiers are
  2179. interned on the \name{oblist} (see \nameref{intern})
  2180. READ returns the
  2181. value of \nameref{\$eof\$} when the end of the currently selected input
  2182. file is reached.
  2183. \end{Function}
  2184. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2185. \begin{Function}{readch}
  2186. \begin{verbatim}
  2187. READCH():id
  2188. \end{verbatim}
  2189. Returns the next interned character from the file currently
  2190. selected for input. Two special cases occur. If all the
  2191. characters in an input record have been read, the value of
  2192. \nameref{\$eol\$} is returned. If the file selected for input has
  2193. all been read the value of \nameref{\$eof\$} is returned. Comments
  2194. delimited by % and end-of-line are not transparent to \nameref{readch}.
  2195. \end{Function}
  2196. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2197. \begin{Function}{terpri}
  2198. \begin{verbatim}
  2199. TERPRI():NIL
  2200. \end{verbatim}
  2201. The current print line is terminated. The following output
  2202. begins on a new line.
  2203. \end{Function}
  2204. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2205. \begin{Function}{wrs}
  2206. \begin{verbatim}
  2207. WRS(FILEHANDLE:any):any eval, spread
  2208. \end{verbatim}
  2209. Output to the currently active output file is suspended and
  2210. further output is directed to the file named. FILEHANDLE is
  2211. an internal name which is returned by \nameref{open}. The file named
  2212. must have been opened for output. If FILEHANDLE is NIL the
  2213. standard output device is selected. WRS returns the internal
  2214. name of the previously selected output file.
  2215. \begin{verbatim}
  2216. ***** FILEHANDLE could not be selected for output
  2217. \end{verbatim}
  2218. The function name WRS goes back to "write select".
  2219. \end{Function}
  2220. %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2221. \section{LISP Reader}
  2222. \begin{Introduction}{LISP Reader}
  2223. An EVAL read loop has been chosen to drive a Standard LISP system to
  2224. provide a continuity in functional syntax. Choices of messages and the
  2225. amount of extra information displayed are decisions left to the
  2226. implementor.
  2227. \end{Introduction}
  2228. \begin{Function}{quit}
  2229. \begin{verbatim}
  2230. QUIT()
  2231. \end{verbatim}
  2232. Causes termination of the LISP reader and control to be transferred
  2233. to the operating system.
  2234. \end{Function}
  2235. \section{System GLOBAL Variables}
  2236. \begin{Variable}{*comp}
  2237. \index{expr}
  2238. The value of the global variable !*comp controls whether or not
  2239. \nameref{putd} compiles the
  2240. function defined in its arguments before defining it. If !*comp is NIL
  2241. the function is defined as an \name{expr}. If !*comp is something else the
  2242. function is first compiled. Compilation will produce certain changes
  2243. in the semantics of functions particularly \nameref{fluid} type access.
  2244. \end{Variable}
  2245. \begin{Variable}{emsg*}
  2246. Will contain the MESSAGE generated by the last \nameref{error} call.
  2247. \end{Variable}
  2248. \begin{Variable}{$eof$}
  2249. The value of !\$eof!\$ is returned by all input functions when the
  2250. end \index{end of file}
  2251. of the currently selected input file is reached.
  2252. \end{Variable}
  2253. \begin{Variable}{$eol$}
  2254. The value of !\$eol!\$ is returned by \nameref{readch} when it reaches the end
  2255. of \name{readch} \index{end of line}
  2256. a logical input record. Likewise \nameref{princ} will terminate its current line
  2257. (like a call to \nameref{terpri}) when !\$eol!\$ is its argument.
  2258. \end{Variable}
  2259. \begin{Variable}{*gc}
  2260. \index{garbage collector}
  2261. !*gc controls the printing of garbage collector messages. If NIL no
  2262. indication of garbage collection may occur. If non-NIL various system
  2263. dependent messages may be displayed.
  2264. \end{Variable}
  2265. \begin{Variable}{nil}
  2266. \name{nil} is a special global variable. It is protected from being modified
  2267. by \nameref{set} or \nameref{setq}. Its value is \name{nil}.
  2268. \end{Variable}
  2269. \begin{Variable}{*raise}
  2270. If \name{!*raise} is non-NIL all characters input through Standard LISP
  2271. input/output functions will be raised to upper case. If \name{!*RAISE} is NIL
  2272. characters will be input as is.
  2273. \end{Variable}
  2274. \begin{Variable}{t}
  2275. \name{t} is a special global variable. It is protected from being modified
  2276. by \nameref{set} or \nameref{setq}. Its value is \name{t}.
  2277. \end{Variable}
  2278. \end{document}