SL.TEX 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263
  1. \documentstyle[11pt,reduce]{article}
  2. \title{The Standard Lisp Report}
  3. \date{}
  4. \author{Jed Marti \\ A. C. Hearn \\ M. L. Griss \\ C. Griss}
  5. %%% Function/method definition.
  6. %%% de{fname}{arglist}{type}{text} For short arg lists.
  7. %%% DE{fname}{arglist}{type}{text} For long arg lists.
  8. \newlength{\argwidth} % Width of argument box.
  9. \setlength{\argwidth}{4in}
  10. \newlength{\dewidth}
  11. \setlength{\dewidth}{4.5in} % Width of text box.
  12. \newcommand{\de}[4]
  13. {\vspace{.25in} \noindent
  14. \begin{minipage}[t]{\textwidth} \index{#1} {\f{#1}}{#2}\hfill{\em #3} \\
  15. \hspace*{.25in}\begin{minipage}[t]{\dewidth} #4 \end{minipage}
  16. \end{minipage} }
  17. %%% Global/fluid variable description.
  18. %%% variable{name}{initial value}{type}{text}
  19. \newcommand{\variable}[4]
  20. {\vspace{.25in} \noindent
  21. \begin{minipage}[t]{\textwidth} \index{#1 (#3)} {\bf #1} = #2 \hfill {\em #3}
  22. \\
  23. \hspace*{.25in} \ \begin{minipage}[t]{\dewidth} #4 \end{minipage}
  24. \end{minipage}}
  25. %%% Command to display an error or warning message in teletype format. Also
  26. %%% leaves blank vertical space around it.
  27. \newcommand{\errormessage}[1]
  28. {\vspace{.1in} \noindent {\tt #1} \\ \vspace{.1in}}
  29. %%% \p is a parameter name (or argument). Just do this as bf.
  30. \newcommand{\p}[1] {{\bf #1}}
  31. %%% \ty is a type - do as italics.
  32. \newcommand{\ty}[1] {{\em #1}}
  33. \begin{document}
  34. \maketitle
  35. \section{Introduction}
  36. Although the programming language LISP was first formulated in
  37. 1960~\cite{LISP1.5}, a widely accepted standard has never appeared. As
  38. a result, various dialects of LISP were
  39. produced~\cite{CDC-LISP,LISP/360,MACLISP,Interlisp,LISPF1,LISP1.6} in
  40. some cases several on the same machine! Consequently, a user often
  41. faces considerable difficulty in moving programs from one system to
  42. another. In addition, it is difficult to write and use programs which
  43. depend on the structure of the source code such as translators,
  44. editors and cross-reference programs.
  45. In 1969, a model for such a standard was produced~\cite{Hearn:69} as
  46. part of a general effort to make a large LISP based algebraic
  47. manipulation program, REDUCE~\cite{REDUCE3.3}, as portable as
  48. possible. The goal of this work was to define a uniform subset of
  49. LISP 1.5 and its variants so that programs written in this subset
  50. could run on any reasonable LISP system.
  51. In the intervening years, two deficiencies in the approach taken in
  52. Ref.~\cite{Hearn:69} have emerged. First in order to be as general as
  53. possible, the specific semantics and values of several key functions
  54. were left undefined. Consequently, programs built on this subset could
  55. not make any assumptions about the form of the values of such
  56. functions. The second deficiency related to the proposed method of
  57. implementation of this language. The model considered in effect two
  58. versions of LISP on any given machine, namely Standard LISP and the
  59. LISP of the host machine (which we shall refer to as Target LISP).
  60. This meant that if any definition was stored in interpretive form, it
  61. would vary from implementation to implementation, and consequently one
  62. could not write programs in Standard LISP which needed to assume any
  63. knowledge about the structure of such forms. This deficiency became
  64. apparent during recent work on the development of a portable compiler
  65. for LISP~\cite{PLC}. Clearly a compiler has to know precisely the
  66. structure of its source code; we concluded that the appropriate source
  67. was Standard LISP and not Target LISP.
  68. With these thoughts in mind we decided to attempt again a definition
  69. of Standard LISP. However, our approach this time is more aggressive.
  70. In this document we define a standard for a reasonably large subset of
  71. LISP with as precise as possible a statement about the semantics of
  72. each function. Secondly, we now require that the target machine
  73. interpreter be modified or written to support this standard, rather
  74. than mapping Standard LISP onto Target LISP as previously.
  75. We have spent countless hours in discussion over many of the
  76. definitions given in this report. We have also drawn on the help and
  77. advice of a lot of friends whose names are given in the
  78. Acknowledgements. Wherever possible, we have used the definition of a
  79. function as given in the LISP 1.5 Programmer's Manual~\cite{LISP1.5}
  80. and have only deviated where we felt it desirable in the light of LISP
  81. programming experience since that time. In particular, we have given
  82. considerable thought to the question of variable bindings and the
  83. definition of the evaluator functions EVAL and APPLY. We have also
  84. abandoned the previous definition of LISP arrays in favor of the more
  85. accepted idea of a vector which most modern LISP systems support.
  86. These are the places where we have strayed furthest from the
  87. conventional definitions, but we feel that the consistency which
  88. results from our approach is worth the redefinition.
  89. We have avoided entirely in this report problems which arise from
  90. environment passing, such as those represented by the FUNARG problem.
  91. We do not necessarily exclude these considerations from our standard,
  92. but in this report have decided to avoid the controversy which they
  93. create. The semantic differences between compiled and interpreted
  94. functions is the topic of another paper~\cite{PLC}. Only functions
  95. which affect the compiler in a general way make reference to it.
  96. This document is not intended as an introduction to LISP rather it is
  97. assumed that the reader is already familiar with some version. The
  98. document is thus intended as an arbiter of the syntax and semantics of
  99. Standard LISP. However, since it is not intended as an implementation
  100. description, we deliberately leave unspecified many of the details on
  101. which an actual implementation depends. For example, while we assume
  102. the existence of a symbol table for atoms (the "object list" in LISP
  103. terminology), we do not specify its structure, since conventional LISP
  104. programming does not require this information. Our ultimate goal,
  105. however, is to remedy this by defining an interpreter for Standard
  106. LISP which is sufficiently complete that its implementation on any
  107. given computer will be straightforward and precise. At that time, we
  108. shall produce an implementation level specification for Standard LISP
  109. which will extend the description of the primitive functions defined
  110. herein by introducing a new set of lower level primitive functions in
  111. which the structure of the symbol table, heap and so on may be
  112. defined.
  113. The plan of this chapter is as follows. In Section~\ref{dtypes} we
  114. describe the various data types used in Standard LISP. In
  115. Section~\ref{slfns}, a description of all Standard LISP functions is
  116. presented, organized by type. These functions are defined in an RLISP
  117. syntax which is easier to read than LISP S-expressions.
  118. Section~\ref{slglobals} describes global variables which control the
  119. operation of Standard LISP.
  120. \section{Preliminaries}
  121. \label{dtypes}
  122. \subsection{Primitive Data Types}
  123. \label{pdat}
  124. \begin{description}
  125. \item[integer] Integers are also called "fixed" numbers. The magnitude of
  126. an integer is unrestricted. Integers in the LISP input stream are
  127. \index{integer ! input} \index{integer ! magnitude}
  128. recognized by the grammar:
  129. \begin{tabbing}
  130. \s{digit} ::= 0$\mid$1$\mid$2$\mid$3$\mid$4$\mid$5$\mid$6$\mid$7$\mid$8$\mid$9
  131. \\
  132. \s{unsigned-integer} ::= \s{digit}$\mid$\s{unsigned-integer}\s{digit} \\
  133. \s{integer} ::= \= \s{unsigned-integer} $\mid$ \\
  134. \> +\s{unsigned-integer} $\mid$ \\
  135. \> ---\s{unsigned-integer}
  136. \end{tabbing}
  137. \item[floating] - Any floating point number. The precision of floating point
  138. \index{floating ! input}
  139. numbers is determined solely by the implementation. In BNF floating
  140. point numbers are recognized by the grammar:
  141. \begin{tabbing}
  142. \s{base} ::= \= \s{unsigned-integer}.$\mid$.\s{unsigned-integer}$\mid$ \\
  143. \> \s{unsigned-integer}.\s{unsigned-integer} \\
  144. \> \s{unsigned-floating} ::= \s{base}$\mid$ \\
  145. \> \s{base}E\s{unsigned-integer}$\mid$ \\
  146. \> \s{base}E-\s{unsigned-integer}$\mid$ \\
  147. \> \s{base}E+\s{unsigned-integer} \\
  148. \s{floating} ::= \= \s{unsigned-floating}$\mid$ \\
  149. \> +\s{unsigned-floating}$\mid$-\s{unsigned-floating}
  150. \end{tabbing}
  151. \item[id] An identifier is a string of characters which may have the
  152. \index{id ! input} \index{identifier (see id)}
  153. following items associated with it.
  154. \begin{description}
  155. \item[print name] \index{print name} The characters of the identifier.
  156. \item[flags] An identifier may be tagged with a flag. Access is by the
  157. FLAG, REMFLAG, and FLAGP functions defined in section~\ref{plist} on
  158. page~\pageref{plist}. \index{FLAG} \index{REMFLAG} \index{FLAGP}
  159. \item[properties] \index{properties} An identifier may have an
  160. indicator-value pair associated with it. Access is by the PUT, GET,
  161. and REMPROP functions defined in section~\ref{plist} on
  162. page~\pageref{plist}.
  163. \index{PUT} \index{GET} \index{REMPROP}
  164. \item[values/functions] An identifier may have a value associated with
  165. \index{values} \index{functions} it. Access to values is by SET and SETQ
  166. defined in \index{SET} \index{SETQ} section~\ref{varsandbinds} on
  167. page~\pageref{varsandbinds}. The method by which the value is attached
  168. to the identifier is known as the binding type, being one of LOCAL,
  169. GLOBAL, or FLUID. Access to the binding type is by the GLOBAL,
  170. GLOBALP, FLUID, FLUIDP, and UNFLUID functions.
  171. \index{GLOBAL} \index{GLOBALP} \index{FLUID} \index{FUIDP} \index{UNFLUID}
  172. An identifier may have a function or macro associated with it. Access
  173. is by the PUTD, GETD, and REMD functions (see ``Function Definition'',
  174. section~\ref{fdef}, on page~\pageref{fdef}). \index{PUTD} \index{GETD}
  175. \index{REMD} An identifier may not have both a function and a value
  176. associated with it.
  177. \item[OBLIST entry] \index{OBLIST entry} An identifier may be entered and
  178. removed from a structure called the OBLIST. Its presence on the OBLIST
  179. does not directly affect the other properties. Access to the OBLIST is
  180. by the INTERN, REMOB, and READ functions. \index{INTERN} \index{REMOB}
  181. \index{READ}
  182. \end{description}
  183. The maximum length of a Standard LISP identifier is 24 characters
  184. \index{id ! maximum length}
  185. (excluding occurrences of the escape character !) but an
  186. \index{id ! escape character}
  187. implementation may allow more. Special characters (digits in the first
  188. position and punctuation) must be prefixed with an escape character,
  189. an ! in Standard LISP. In BNF identifiers are recognized by the
  190. grammar:
  191. \begin{tabbing}
  192. \s{special-character} ::= !\s{any-character} \\
  193. \s{alphabetic} ::= \\
  194. \hspace*{.25in} \= A$\mid$B$\mid$C$\mid$D$\mid$E$\mid$F$\mid$G$\mid$H$
  195. \mid$I$\mid$J$\mid$K$\mid$L$\mid$M$\mid$N$\mid$O$\mid$P$\mid$Q$\mid$R$
  196. \mid$S$\mid$T$\mid$U$\mid$V$\mid$W$\mid$X$\mid$Y$\mid$Z$\mid$ \\
  197. \> a$\mid$b$\mid$c$\mid$d$\mid$e$\mid$f$\mid$g$\mid$h$\mid$i$\mid$j$
  198. \mid$k$\mid$l$\mid$m$\mid$n$\mid$o$\mid$p$\mid$q$\mid$r$\mid$s$\mid$t$
  199. \mid$u$\mid$v$\mid$w$\mid$x$\mid$y$\mid$z \\
  200. \s{lead-character} ::= \s{special-character}$\mid$\s{alphabetic} \\
  201. \s{regular-character} ::= \s{lead-character}$\mid$\s{digit} \\
  202. \s{last-part} ::= \= \s{regular-character} $\mid$ \\
  203. \> \s{last-part}\s{regular-character} \\
  204. \s{id} ::= \s{lead-character}$\mid$\s{lead-character}\s{last-part}
  205. \end{tabbing}
  206. Note: Using lower case letters in identifiers may cause portability
  207. problems. Lower case letters are automatically converted to upper case
  208. when the !*RAISE flag is T. \index{*RAISE (global)}
  209. \item[string] \index{string} A set of characters enclosed in double quotes as
  210. in "THIS IS A STRING". A quote is included by doubling it as in "HE
  211. SAID, ""LISP""". The maximum size of strings is 80 characters but an
  212. implementation may allow more. Strings are not part of the OBLIST and
  213. are considered constants like numbers, vectors, and function-pointers.
  214. \item[dotted-pair] A primitive structure which has a left and right part.
  215. \index{dotted-pair} \index{dot-notation}
  216. A notation called {\em dot-notation} is used for dotted pairs and
  217. takes the form:
  218. \begin{tabbing}
  219. (\s{left-part} . \s{right-part})
  220. \end{tabbing}
  221. The \s{left-part} is known as the CAR portion and the \s{right-part}
  222. as the CDR portion. The left and right parts may be of any type.
  223. Spaces are used to resolve ambiguity with floating point numbers.
  224. \item[vector] \index{vector} A primitive uniform structure in which
  225. an integer index is used to access random values in the structure. The
  226. individual elements of a vector may be of any type. Access to vectors
  227. is restricted to functions defined in ``Vectors''
  228. section~\ref{vectors} on page~\pageref{vectors}. A notation for
  229. vectors, {\em vector-notation}, has the elements of a vector
  230. surrounded
  231. \index{vector-notation}
  232. by square brackets\footnote{Vector elements are not separated by
  233. commas as in the published version of this document.}
  234. \begin{tabbing}
  235. \s{elements} ::= \s{any}$\mid$\s{any} \s{elements} \\
  236. \s{vector} ::= [\s{elements}]
  237. \end{tabbing}
  238. \item[function-pointer] \index{function-pointer} An implementation may have
  239. functions which deal with specific data types other than those listed.
  240. The use of these entities is to be avoided with the exception of a
  241. restricted use of the function-pointer, an access method to compiled
  242. EXPRs and FEXPRs. A particular function-pointer must remain valid
  243. \index{EXPR} \index{FEXPR}
  244. throughout execution. Systems which change the location of a function
  245. must use either an indirect reference or change all occurrences of the
  246. associated value. There are two classes of use of function-pointers,
  247. those which are supported by Standard LISP but are not well defined,
  248. and those which are well defined.
  249. \begin{description}
  250. \item[Not well defined] Function pointers may be displayed by the print
  251. functions or expanded by EXPLODE. \index{EXPLODE} The value appears in
  252. the convention of the implementation site. The value is not defined in
  253. Standard LISP. Function pointers may be created by COMPRESS
  254. \index{COMPRESS} in the format used for printing but the value used is
  255. not defined in Standard LISP. Function pointers may be created by
  256. functions which deal with compiled function loading. Again, the values
  257. created are not well defined in Standard LISP.
  258. \item[Well defined] The function pointer associated with an EXPR or
  259. FEXPR may be retrieved by GETD \index{GETD} and is valid as long as
  260. Standard LISP is in execution. Function pointers may be stored using
  261. \index{PUTD} \index{PUT} \index{SETQ} PUTD, PUT, SETQ and the like or by
  262. being bound to variables. Function pointers may be checked for
  263. equivalence by EQ. \index{EQ ! of function-pointers} The value may be
  264. checked for being a function pointer by the CODEP function.
  265. \index{CODEP}
  266. \end{description}
  267. \end{description}
  268. \subsection{Classes of Primitive Data Types}
  269. \label{pclasses}
  270. The classes of primitive types are a notational convenience for
  271. describing the properties of functions.
  272. \begin{description}
  273. \item[boolean] \index{boolean} The set of global variables \{T,NIL\},
  274. or their respective values, \{T, NIL\}. \index{T (global)} \index{NIL
  275. (global)}
  276. \item[extra-boolean] \index{extra-boolean} Any value in the system.
  277. Anything that is not NIL \index{NIL (global)} has the boolean
  278. interpretation T. \index{T (global)}
  279. \item[ftype] \index{ftype} The class of definable function types. The
  280. set of ids \{EXPR, FEXPR, MACRO\}. \index{EXPR} \index{FEXPR}
  281. \index{MACRO}
  282. \item[number] \index{number} The set of \{integer, floating\}.
  283. \item[constant] \index{constant} The set of \{integer, floating,
  284. string, vector, function-pointer\}. Constants evaluate to themselves
  285. (see the definition of EVAL in ``The Interpreter'',
  286. section~\ref{interpreter} on page~\pageref{interpreter}). \index{EVAL
  287. ! of constants}
  288. \item[any] \index{any} The set of \{integer, floating, string, id,
  289. dotted-pair, vector, function-pointer\}. An S-expression is another
  290. term for any. All Standard LISP entities have some value unless an
  291. ERROR occurs during evaluation or the function causes transfer of
  292. control (such as GO and RETURN).
  293. \item[atom] \index{atom} The set \{any\}-\{dotted-pair\}.
  294. \end{description}
  295. \subsection{Structures}
  296. \index{data structures} \index{structures}
  297. Structures are entities created out of the primitive types by the use
  298. of dotted-pairs. Lists are structures very commonly required as actual
  299. parameters to functions. Where a list of homogeneous entities is
  300. required by a function this class will be denoted by
  301. \s{{\bf xxx}-list} where {\bf \em xxx} is the name of a class of primitives
  302. or structures. Thus a list of ids is an {\em id-list}, a list of
  303. integers an {\em integer-list} and so on. \index{id-list}
  304. \index{integer-list}
  305. \index{-list}
  306. \begin{description}
  307. \item[list] \index{list} A list is recursively defined as NIL or the
  308. \index{list-notation} \index{NIL (global)}
  309. dotted-pair (any~.~list). A special notation called {\em
  310. list-notation} is used to represent lists. List-notation eliminates
  311. extra parentheses and dots. The list (a . (b . (c . NIL))) in list
  312. notation is (a b c).
  313. \index{dot-notation}
  314. List-notation and dot-notation may be mixed as in (a b . c) or (a (b .
  315. c) d) which are (a . (b . c)) and (a . ((b . c) . (d . NIL))). In BNF
  316. lists are recognized by the grammar:
  317. \begin{tabbing}
  318. \s{left-part} ::= ( $\mid$ \s{left-part} \s{any} \\
  319. \s{list} ::= \s{left-part}) $\mid$ \s{left-part} . \s{any})
  320. \end{tabbing}
  321. Note: () is an alternate input representation of NIL. \index{()}
  322. \item[alist] \index{alist} An association list; each element of the list
  323. is a dotted-pair, the CAR part being a key associated with the value
  324. in the CDR part. \index{association list}
  325. \item[cond-form] \index{cond-form} A cond-form is a list of 2 element lists
  326. of the form:
  327. (\p{ANTECEDENT}:{\em any} \p{CONSEQUENT}:{\em any})
  328. The first element will henceforth be known as the antecedent and
  329. \index{antecedent (cond-form)} \index{consequent (cond-form)}
  330. the second as the consequent. The antecedent must have a value. The
  331. consequent may have a value or an occurrence of GO or RETURN
  332. \index{GO} \index{RETURN}
  333. as described in the ``Program Feature Functions'', section~\ref{prog}
  334. on page~\pageref{prog}.
  335. \item[lambda] \index{LAMBDA} A LAMBDA expression which must have the form
  336. (in list notation): (LAMBDA parameters body). ``parameters'' is a list
  337. of formal parameters for ``body'' an S-expression to be evaluated. The
  338. semantics of the evaluation are defined with the EVAL function (see
  339. ``The Interpreter'', section~\ref{interpreter} on \index{EVAL ! lambda
  340. expressions} page~\pageref{interpreter}). \index{lambda expression}
  341. \item[function] \index{function} A LAMBDA expression or a function-pointer
  342. to a function. A function is always evaluated as an EVAL, SPREAD form.
  343. \index{EVAL ! function}
  344. \end{description}
  345. \subsection{Function Descriptions}
  346. Each function is provided with a prototypical header line. Each formal
  347. parameter is given a name and suffixed with its allowed type. Lower
  348. case, italic tokens are names of classes and upper case, bold face,
  349. tokens are parameter names referred to in the definition. The type of
  350. the value returned by the function (if any) is suffixed to the
  351. parameter list. If it is not commonly used the parameter type may be
  352. a specific set enclosed in brackets \{\ldots\}. \index{\{\ldots\} ! as
  353. syntax} For example:
  354. \vspace{.1in}
  355. \noindent \f{PUTD}(\p{FNAME}:\ty{id}, \p{TYPE}:\ty{ftype},
  356. \p{BODY}:\{\ty{lambda, function-pointer}\}):\ty{id}
  357. \vspace{.1in}
  358. PUTD is a function with three parameters. The parameter FNAME is an id
  359. to be the name of the function being defined. TYPE is the type of the
  360. function being defined and BODY is a lambda expression or a
  361. function-pointer. PUTD returns the name of the function being defined.
  362. Functions which accept formal parameter lists of arbitrary length have
  363. the type class and parameter enclosed in square brackets indicating
  364. that zero or more occurrences of that argument are permitted.
  365. \index{[\ldots] syntax} For example:
  366. \vspace{.1in}
  367. \noindent \f{AND}([\p{U}:\ty{any}]):\ty{extra-boolean}
  368. \vspace{.1in}
  369. AND is a function which accepts zero or more arguments which may be of
  370. any type.
  371. \subsection{Function Types}
  372. EVAL type functions are those which are invoked with evaluated
  373. \index{EVAL ! function type}
  374. arguments. NOEVAL functions are invoked with unevaluated arguments.
  375. \index{NOEVAL ! function type}
  376. SPREAD type functions have their arguments passed in one-to-one
  377. \index{SPREAD ! function type}
  378. correspondence with their formal parameters. NOSPREAD functions
  379. \index{NOSPREAD ! function type}
  380. receive their arguments as a single list. EVAL, SPREAD functions are
  381. \index{FEXPR}
  382. associated with EXPRs and NO\-EVAL, NO\-SPREAD functions with FEXPRs.
  383. EVAL, NO\-SPREAD and NOEVAL, SPREAD functions can be simulated using
  384. NOEVAL, NO\-SPREAD functions or MACROs. \index{MACRO}
  385. EVAL, SPREAD type functions may have a maximum of 15 parameters.
  386. \index{formal parameter limit}
  387. There is no limit on the number of parameters a NOEVAL, NOSPREAD
  388. function or MACRO may have.
  389. In the context of the description of an EVAL, SPREAD function, then we
  390. speak of the formal parameters we mean their actual values. However,
  391. in a NOEVAL, NOSPREAD function it is the unevaluated actual
  392. parameters.
  393. A third function type, the MACRO, implements functions which
  394. \index{MACRO}
  395. create S-expressions based on actual parameters. When a macro
  396. invocation is encountered, the body of the macro, a lambda expression,
  397. is invoked as a NOEVAL, NOSPREAD function with the macro's invocation
  398. bound as a list to the macros single formal parameter. When the macro
  399. has been evaluated the resulting S-expression is reevaluated. The
  400. description of the EVAL and EXPAND
  401. \index{EVAL ! MACRO functions}
  402. functions provide precise details.
  403. \subsection{Error and Warning Messages}
  404. \index{error messages}
  405. Many functions detect errors. The description of such functions will
  406. include these error conditions and suggested formats for display
  407. \index{ERROR}
  408. of the generated error messages. A call on the ERROR function is
  409. implied but the error number is not specified by Standard LISP. In
  410. some cases a warning message is sufficient. To distinguish between
  411. \index{warning messages} \index{***** (error message)}
  412. \index{*** (warning message)}
  413. errors and warnings, errors are prefixed with five asterisks and
  414. warnings with only three.
  415. Primitive functions check arguments that must be of a certain
  416. primitive type for being of that type and display an error message if
  417. the argument is not correct. The type mismatch error always takes the
  418. form:
  419. \index{error ! type mismatch error}
  420. \errormessage{***** PARAMETER not TYPE for FN}
  421. Here PARAMETER is the unacceptable actual parameter, TYPE is the type
  422. that PARAMETER was supposed to be. FN is the name of the function that
  423. detected the error.
  424. \subsection{Comments}
  425. \index{comments} \index{\%}
  426. The character \% signals the start of a comment, text to be ignored
  427. during parsing. A comment is terminated by the end of the line it
  428. \index{READCH} \index{READ}
  429. is on. The function READCH must be able to read a comment one
  430. character at a time. Comments are transparent to the function READ.
  431. \% may occur as a character in identifiers by preceding it with the
  432. \index{escape character}
  433. escape character !.
  434. \section{Functions}
  435. \label{slfns}
  436. \subsection{Elementary Predicates}
  437. \label{elpreds}
  438. \index{predicate !}
  439. \index{T (global)} \index{NIL (global)}
  440. Functions in this section return T when the condition defined is met
  441. and NIL when it is not. Defined are type checking functions and
  442. elementary comparisons.
  443. \de{ATOM}{(\p{U}:\ty{any}):{\ty boolean}}{eval, spread}
  444. {Returns T if U is not a pair.
  445. {\tt \begin{tabbing} EXPR PROCEDURE ATOM(U); \\
  446. \hspace*{1em} NULL PAIRP U;
  447. \end{tabbing}}}
  448. \de{CODEP}{(\p{U}:\f{any}):{\ty boolean}}{eval, spread}
  449. {Returns T if U is a function-pointer.}
  450. \de{CONSTANTP}{(\p{U}:\ty{any}):\ty{boolean}}{eval, spread}
  451. {Returns T if U is a constant (a number, string, function-pointer, or
  452. vector).
  453. {\tt \begin{tabbing} EXPR PROCEDURE CONSTANTP(U); \\
  454. \hspace*{1em} NULL OR(PAIRP U, IDP U);
  455. \end{tabbing}}
  456. }
  457. \de{EQ}{(\p{U}:\ty{any}, \p{V}:\ty{any}):\ty{boolean}}{eval, spread}
  458. {Returns T if U points to the same object as V. EQ is \underline{not}
  459. a reliable comparison between numeric arguments. }
  460. \de{EQN}{(\p{U}:\ty{any}, \p{V}:\ty{any}):\ty{boolean}}{eval, spread}
  461. {Returns T if U and V are EQ or if U and V are numbers and have the
  462. same value and type. }
  463. \de{EQUAL}{(\p{U}:\ty{any}, \p{V}:\ty{any}):\ty{boolean}}{eval, spread}
  464. {Returns T if U and V are the same. Dotted-pairs are compared
  465. recursively to the bottom levels of their trees. Vectors must have
  466. identical dimensions and EQUAL values in all positions. Strings must
  467. \index{EQ ! of function-pointers} \index{EQN} have identical characters.
  468. Function pointers must have EQ values. Other atoms must be EQN equal. }
  469. \de{FIXP}{(\p{U}:\ty{any}):\ty{boolean}}{eval, spread}
  470. {Returns T if U is an integer (a fixed number).}
  471. \de{FLOATP}{(\p{U}:\ty{any}):\ty{boolean}}{eval, spread}
  472. {Returns T if U is a floating point number. }
  473. \de{IDP}{(\p{U}:\ty{any}):\ty{boolean}}{eval, spread}
  474. {Returns T if U is an id.}
  475. \de{MINUSP}{(\p{U}:\ty{any}):\ty{boolean}}{eval, spread}
  476. {Returns T if U is a number and less than 0. If U is not a number or
  477. is a positive number, NIL is returned.
  478. {\tt \begin{tabbing} EXPR PROCEDURE MINUSP(U); \\
  479. \hspace*{1em} IF NUMBERP U THEN LESSP(U, 0) ELSE NIL;
  480. \end{tabbing}}}
  481. \de{NULL}{(\p{U}:\ty{any}):\ty{boolean}}{eval, spread}
  482. {Returns T if U is NIL.
  483. {\tt \begin{tabbing} EXPR PROCEDURE NULL(U); \\
  484. \hspace*{1em} U EQ NIL;
  485. \end{tabbing}}}
  486. \de{NUMBERP}{(\p{U}:\ty{any}):\ty{boolean}}{eval, spread}
  487. {Returns T if U is a number (integer or floating).
  488. {\tt \begin{tabbing} EXPR PROCEDURE NUMBERP(U); \\
  489. \hspace*{1em} IF OR(FIXP U, FLOATP U) THEN T ELSE NIL;
  490. \end{tabbing}}}
  491. \de{ONEP}{(\p{U}:\ty{any}):\ty{boolean}}{eval, spread.}
  492. {Returns T if U is a number and has the value 1 or 1.0. Returns NIL
  493. otherwise. \footnote{The definition in the published report is
  494. incorrect as it does not return T for \p{U} of 1.0.}
  495. {\tt \begin{tabbing} EXPR PROCEDURE ONEP(U); \\
  496. \hspace*{1em} OR(EQN(U, 1), EQN(U, 1.0));
  497. \end{tabbing}}}
  498. \de{PAIRP}{(\p{U}:\ty{any}):\ty{boolean}}{eval, spread}
  499. {Returns T if U is a dotted-pair. }
  500. \de{STRINGP}{(\p{U}:\ty{any}):\ty{boolean}}{eval, spread}
  501. {Returns T if U is a string. }
  502. \de{VECTORP}{(\p{U}:\ty{any}):\ty{boolean}}{eval, spread}
  503. {Returns T if U is a vector. }
  504. \de{ZEROP}{(\p{U}:\ty{any}):\ty{boolean}}{eval, spread.}
  505. {Returns T if U is a number and has the value 0 or 0.0. Returns NIL
  506. otherwise.\footnote{The definition in the published report is
  507. incorrect as it does not return T for \p{U} of 0.0.}
  508. {\tt \begin{tabbing} EXPR PROCEDURE ZEROP(U); \\
  509. \hspace*{1em} OR(EQN(U, 0), EQN(U, 0.0));
  510. \end{tabbing}}}
  511. \subsection{Functions on Dotted-Pairs}
  512. \index{dotted-pair}
  513. The following are elementary functions on dotted-pairs. All functions
  514. in this section which require dotted-pairs as parameters detect a type
  515. mismatch error if the actual parameter is not a dotted-pair.
  516. \de{CAR}{(\p{U}:\ty{dotted-pair}):\ty{any}}{eval, spread}
  517. {CAR(CONS(a, b)) $\rightarrow$ a. The left part of U is returned. The
  518. type
  519. \index{CONS}
  520. mismatch error occurs if U is not a dotted-pair.}
  521. \de{CDR}{(\p{U}:\ty{dotted-pair}):\ty{any}}{eval, spread}
  522. {CDR(CONS(a, b)) $\rightarrow$ b. The right part of U is returned. The
  523. type
  524. \index{CONS}
  525. mismatch error occurs if U is not a dotted-pair.}
  526. The composites of CAR and CDR are supported up to 4 levels, namely:
  527. \index{CAR ! composite forms} \index{CDR ! composite forms}
  528. \hspace*{1in}\begin{tabular}{l l l}
  529. CAAAAR & CAAAR & CAAR \\ CAAADR & CAADR & CADR \\ CAADAR & CADAR &
  530. CDAR \\ CAADDR & CADDR & CDDR \\ CADAAR & CDAAR & \\ CADADR & CDADR &
  531. \\ CADDAR & CDDAR & \\ CADDDR & CDDDR & \\ CDAAAR & & \\ CDAADR & & \\
  532. CDADAR & & \\ CDADDR & & \\ CDDAAR & & \\ CDDADR & & \\ CDDDAR & & \\
  533. CDDDDR & &
  534. \end{tabular}
  535. \de{CONS}{(\p{U}:\ty{any}, \p{V}:\ty{any}):\ty{dotted-pair}}{eval, spread}
  536. {Returns a dotted-pair which is not EQ to anything and has U as its
  537. \index{EQ ! of dotted-pairs} \index{dotted-pair}
  538. CAR part and V as its CDR part.}
  539. \de{LIST}{([\p{U}:\ty{any}]):\ty{list}}{noeval, nospread, or macro}
  540. {A list of the evaluation of each element of U is returned. The order
  541. of evaluation need not be first to last as the following definition
  542. implies.\footnote{The published report's definition implies a specific
  543. ordering.}
  544. {\tt \begin{tabbing} FEXPR PROCEDURE LIST(U); \\
  545. \hspace*{1em} EVLIS U;
  546. \end{tabbing}}}
  547. \de{RPLACA}{(\p{U}:\ty{dotted-pair},
  548. \p{V}:\ty{any}):\ty{dotted-pair}}{eval, spread}
  549. {The CAR portion of the dotted-pair U is replaced by V. If dotted-pair
  550. U is (a . b) then (V . b) is returned. The type mismatch error occurs
  551. if U is not a dotted-pair. }
  552. \de{RPLACD}{(\p{U}:\ty{dotted-pair},
  553. \p{V}:\ty{any}):\ty{dotted-pair}}{eval, spread}
  554. {The CDR portion of the dotted-pair U is replaced by V. If dotted-pair
  555. U is (a . b) then (a . V) is returned. The type mismatch error occurs
  556. if U is not a dotted-pair.}
  557. \subsection{Identifiers}
  558. \label{identifiers}
  559. The following functions deal with identifiers and the OBLIST,
  560. \index{OBLIST}
  561. the structure of which is not defined. The function of the OBLIST is
  562. to provide a symbol table for identifiers created during input.
  563. Identifiers created by READ which have the same characters will
  564. \index{READ} \index{EQ ! of identifiers}
  565. therefore refer to the same object (see the EQ function in
  566. ``Elementary Predicates'', section~\ref{elpreds} on
  567. page~\pageref{elpreds}).
  568. \de{COMPRESS}{(\p{U}:\ty{id-list}):\{\ty{atom}-\ty{vector}\}}{eval, spread}
  569. {U is a list of single character identifiers which is built into a
  570. Standard LISP entity and returned. Recognized are numbers, strings,
  571. and identifiers with the escape character prefixing special
  572. characters. The formats of these items appear in ``Primitive Data
  573. Types'' section~\ref{pdat} on page~\pageref{pdat}. Identifiers are not
  574. interned on the OBLIST. Function pointers may be compressed but this
  575. is an undefined use. If an entity cannot be parsed out of U or
  576. characters are left over after parsing an error occurs:
  577. \errormessage{***** Poorly formed atom in COMPRESS}
  578. }
  579. \de{EXPLODE}{(\p{U}:\{\ty{atom}\}-\{\ty{vector}\}):\ty{id-list}}{eval, spread}
  580. {Returned is a list of interned characters representing the characters
  581. to print of the value of U. The primitive data types have these
  582. formats:
  583. \begin{description}
  584. \item[integer] \index{integer ! output} Leading zeroes are suppressed and
  585. a minus sign prefixes the digits if the integer is negative.
  586. \item[floating] \index{floating ! output} The value appears in the format
  587. [-]0.nn...nnE[-]mm if the magnitude of the number is too large or
  588. small to display in [-]nnnn.nnnn format. The crossover point is
  589. determined by the implementation.
  590. \item[id] \index{id ! output} The characters of the print name of the
  591. identifier are produced with special characters prefixed with the
  592. escape character.
  593. \item[string] \index{string ! output} The characters of the string are
  594. produced surrounded by double quotes "\ldots".
  595. \item[function-pointer] \index{function-pointer ! output} The value of the
  596. function-pointer is created as a list of characters conforming to the
  597. conventions of the system site.
  598. \end{description}
  599. The type mismatch error occurs if U is not a number, identifier,
  600. string, or function-pointer. }
  601. \de{GENSYM}{():\ty{identifier}}{eval, spread}
  602. {Creates an identifier which is not interned on the OBLIST and
  603. consequently not EQ to anything else. \index{OBLIST entry} \index{EQ !
  604. of GENSYMs}}
  605. \de{INTERN}{(\p{U}:\{\ty{id,string}\}):\ty{id}}{eval, spread}
  606. {INTERN searches the OBLIST for an identifier with the same print name
  607. \index{OBLIST entry}
  608. as U and returns the identifier on the OBLIST if a match is found.
  609. Any properties and global values associated with U may be lost. If U
  610. does not match any entry, a new one is created and returned. If U has
  611. more than the maximum number of characters permitted by the
  612. implementation (the minimum number is 24) an error occurs:
  613. \index{id ! minimum size}
  614. \errormessage{***** Too many characters to INTERN}
  615. }
  616. \de{REMOB}{(\p{U}:\ty{id}):\ty{id}}{eval, spread}
  617. {If U is present on the OBLIST it is removed. This does not affect U
  618. \index{OBLIST entry}
  619. having properties, flags, functions and the like. U is returned.}
  620. \subsection{Property List Functions}
  621. \label{plist}
  622. \index{property list}
  623. With each id in the system is a ``property list'', a set of entities
  624. which are associated with the id for fast access. These entities are
  625. called ``flags'' if their use gives the id a single valued
  626. \index{flags}
  627. property, and ``properties'' if the id is to have a multivalued
  628. \index{properties}
  629. attribute: an indicator with a property.
  630. Flags and indicators may clash, consequently care should be taken to
  631. avoid this occurrence. Flagging X with an id which already is an
  632. indicator for X may result in that indicator and associated property
  633. being lost. Likewise, adding an indicator which is the same id as a
  634. flag may result in the flag being destroyed.
  635. \de{FLAG}{(\p{U}:\ty{id-list}, \p{V}:\ty{id}):\ty{NIL}}{eval, spread}
  636. {U is a list of ids which are flagged with V. The effect of FLAG is
  637. that FLAGP will have the value T for those ids of U which were
  638. flagged. Both V and all the elements of U must be identifiers or the
  639. type mismatch error occurs.}
  640. \de{FLAGP}{(\p{U}:\ty{any}, \p{V}:\ty{any}):\ty{boolean}}{eval, spread}
  641. {Returns T if U has been previously flagged with V, else NIL. Returns
  642. NIL if either U or V is not an id.}
  643. \de{GET}{(\p{U}:\ty{any}, \p{IND}:\ty{any}):\ty{any}}{eval, spread}
  644. {Returns the property associated with indicator IND from the property
  645. list of U. If U does not have indicator IND, NIL is returned. GET
  646. cannot be used to access functions (use GETD instead).
  647. \index{GET ! not for functions}}
  648. \de{PUT}{(\p{U}:\ty{id}, \p{IND}:\ty{id},
  649. \p{PROP}:\ty{any}):\ty{any}}{eval, spread}
  650. {The indicator IND with the property PROP is placed on the property
  651. list of the id U. If the action of PUT occurs, the value of PROP is
  652. returned. If either of U and IND are not ids the type mismatch error
  653. will occur and no property will be placed. PUT cannot be used to
  654. define functions (use PUTD instead).
  655. \index{PUT ! not for functions}}
  656. \de{REMFLAG}{(\p{U}:\ty{any-list}, \p{V}:\ty{id}):\ty{NIL}}{eval, spread}
  657. {Removes the flag V from the property list of each member of the list
  658. U. Both V and all the elements of U must be ids or the type mismatch
  659. error will occur.}
  660. \de{REMPROP}{(\p{U}:\ty{any}, \p{IND}:\ty{any}):\ty{any}}{eval, spread}
  661. {Removes the property with indicator IND from the property list of U.
  662. Returns the removed property or NIL if there was no such indicator.}
  663. \subsection{Function Definition}
  664. \label{fdef}
  665. Functions in Standard LISP are global entities. To avoid
  666. function-variable naming clashes no variable may have the same name as
  667. a function. \index{function ! as GLOBAL}
  668. \de{DE}{(\p{FNAME}:\ty{id}, \p{PARAMS}:\ty{id-list},
  669. \p{FN}:\ty{any}):\ty{id}}{noeval, nospread}
  670. {The function FN with the formal parameter list PARAMS is added to the
  671. set of defined functions with the name FNAME. Any previous definitions
  672. of the function are lost. The function created is of type
  673. \index{*COMP (fluid)}
  674. EXPR. If the !*COMP variable is non-NIL, the EXPR is first
  675. \index{EXPR}
  676. compiled. The name of the defined function is returned.
  677. {\tt \begin{tabbing} FEXPR PROCEDURE DE(U); \\
  678. \hspace*{1em} PUTD(CAR U, 'EXPR, LIST('LAMBDA, CADR U, CADDR U));
  679. \end{tabbing}}}
  680. \de{DF}{(\p{FNAME}:\ty{id}, \p{PARAM}:\ty{id-list},
  681. \p{FN}:\ty{any}):\ty{id}}{noeval, nospread}
  682. {The function FN with formal parameter PARAM is added to the set of
  683. defined functions with the name FNAME. Any previous definitions of the
  684. function are lost. The function created is of type FEXPR.
  685. \index{*COMP variable} \index{FEXPR}
  686. If the !*COMP variable is T the FEXPR is first compiled. The name of
  687. the defined function is returned.
  688. {\tt \begin{tabbing} FEXPR PROCEDURE DF(U); \\
  689. \hspace*{1em} PUTD(CAR U, 'FEXPR, LIST('LAMBDA, CADR U, CADDR U)); \\
  690. \end{tabbing} }}
  691. \de{DM}{(\p{MNAME}:\ty{id}, \p{PARAM}:\ty{id-list},
  692. \p{FN}:\ty{any}):\ty{id}}{noeval, nospread}
  693. {The macro FN with the formal parameter PARAM is added to the set of
  694. defined functions with the name MNAME. Any previous definitions of the
  695. function are overwritten. The function created is of type MACRO.
  696. \index{MACRO}
  697. The name of the macro is returned.
  698. {\tt \begin{tabbing} FEXPR PROCEDURE DM(U); \\
  699. \hspace*{1em} PUTD(CAR U, 'MACRO, LIST('LAMBDA, CADR U, CADDR U));
  700. \end{tabbing} }
  701. }
  702. \de{GETD}{(\p{FNAME}:\ty{any}):\{NIL, \ty{dotted-pair}\}}{eval, spread}
  703. {If FNAME is not the name of a defined function, NIL is returned. If
  704. FNAME is a defined function then the dotted-pair
  705. \vspace{.15in}
  706. (\p{TYPE}:\ty{ftype} . \p{DEF}:\{\ty{function-pointer, lambda}\})
  707. \vspace{.15in}
  708. is returned.}
  709. \de{PUTD}{(\p{FNAME}:\ty{id}, \p{TYPE}:\ty{ftype},
  710. \p{BODY}:\ty{function}):\ty{id}}{eval, spread}
  711. {Creates a function with name FNAME and definition BODY of type TYPE.
  712. If PUTD succeeds the name of the defined function is returned. The
  713. effect of PUTD is that GETD will return a dotted-pair with the
  714. functions type and definition. Likewise the GLOBALP predicate will
  715. \index{GLOBALP} \index{function ! as global}
  716. return T when queried with the function name.
  717. If the function FNAME has already been declared as a GLOBAL or FLUID
  718. variable the error:
  719. \errormessage{***** FNAME is a non-local variable}
  720. occurs and the function will not be defined. If function FNAME already
  721. exists a warning message will appear:
  722. \errormessage{*** FNAME redefined}
  723. The function defined by PUTD will be compiled before definition
  724. \index{*COMP (fluid)} if the !*COMP global variable is non-NIL.}
  725. \de{REMD}{(\p{FNAME}:\ty{id}):\{NIL, \ty{dotted-pair}\}}{eval, spread}
  726. {Removes the function named FNAME from the set of defined functions.
  727. Returns the (ftype . function) dotted-pair or NIL as does GETD. The
  728. global/function attribute of FNAME is removed and the name may be used
  729. subsequently as a variable.}
  730. \subsection{Variables and Bindings}
  731. \label{varsandbinds}
  732. \index{variable scope} \index{scope}
  733. A variable is a place holder for a Standard LISP entity which is said
  734. to be bound to the variable. The scope of a variable is the range over
  735. which the variable has a defined value. There are three different
  736. binding mechanisms in Standard LISP.
  737. \begin{description}
  738. \item[Local Binding] \index{local binding} This type of binding occurs
  739. \index{scope ! local}
  740. only in compiled functions. Local variables occur as formal parameters
  741. in lambda expressions and as PROG form variables. The binding occurs
  742. when a lambda expression is evaluated or when a PROG form is executed.
  743. The scope of a local variable is the body of the function in which it
  744. is defined.
  745. \item[Global Binding] \index{global binding} Only one binding of a
  746. \index{scope ! global}
  747. global variable exists at any time allowing direct access to the value
  748. bound to the variable. The scope of a global variable is universal.
  749. Variables declared GLOBAL may not appear as parameters in lambda
  750. expressions or as PROG form variables. A variable must be declared
  751. GLOBAL prior to its use as a global variable since the default type
  752. for undeclared variables is FLUID.
  753. \item[Fluid Binding] \index{fluid binding}
  754. \index{fluid binding ! as default} Fluid variables are global
  755. in scope but may occur as \index{scope ! fluid} formal parameters or
  756. PROG form variables. In interpreted functions all formal parameters
  757. and PROG form variables are considered to have fluid binding until
  758. changed to local binding by compilation. When fluid variables are
  759. used as parameters they are rebound in such a way that the previous
  760. binding may be restored. All references to fluid variables are to the
  761. currently active binding.
  762. \end{description}
  763. \de{FLUID}{(\p{IDLIST}:\ty{id-list}):\p{NIL}}{eval, spread}
  764. {The ids in IDLIST are declared as FLUID type variables (ids not
  765. previously declared are initialized to NIL). Variables in IDLIST
  766. already declared FLUID are ignored. Changing a variable's type from
  767. GLOBAL to FLUID is not permissible and results in the error:
  768. \errormessage{***** ID cannot be changed to FLUID}
  769. }
  770. \de{FLUIDP}{(\p{U}:\ty{any}):\ty{boolean}}{eval, spread}
  771. {If U has been declared FLUID (by declaration only) T is returned,
  772. otherwise NIL is returned.}
  773. \de{GLOBAL}{(\p{IDLIST}:\ty{id-list}):\p{NIL}}{eval, spread}
  774. {The ids of IDLIST are declared global type variables. If an id has
  775. not been declared previously it is initialized to NIL. Variables
  776. already declared GLOBAL are ignored. Changing a variables type from
  777. FLUID to GLOBAL is not permissible and results in the error:
  778. \errormessage{***** ID cannot be changed to GLOBAL}
  779. }
  780. \de{GLOBALP}{(\p{U}:\ty{any}):\ty{boolean}}{eval, spread}
  781. {If U has been declared GLOBAL or is the name of a defined function, T
  782. is returned, else NIL is returned.}
  783. \de{SET}{(\p{EXP}:\ty{id}, \p{VALUE}:\ty{any}):\ty{any}}{eval, spread}
  784. {EXP must be an identifier or a type mismatch error occurs. The effect
  785. of SET is replacement of the item bound to the identifier by VALUE.
  786. If the identifier is not a local variable or has not been declared
  787. GLOBAL it is automatically declared FLUID with the resulting warning
  788. message:
  789. \errormessage{*** EXP declared FLUID}
  790. EXP must not evaluate to T or NIL or an error occurs:
  791. \index{T ! cannot be changed} \index{NIL ! cannot be changed}
  792. \errormessage{***** Cannot change T or NIL}
  793. }
  794. \de{SETQ}{(\p{VARIABLE}:\ty{id}, \p{VALUE}:\ty{any}):\ty{any}}{noeval,
  795. nospread}
  796. {If VARIABLE is not local or GLOBAL it is by default declared FLUID
  797. and the warning message:
  798. \errormessage{*** VARIABLE declared FLUID}
  799. appears. The value of the current binding of VARIABLE is replaced by
  800. the value of VALUE. VARIABLE must not be T or NIL or an error occurs:
  801. \index{T ! cannot be changed} \index{NIL ! cannot be changed}
  802. \errormessage{***** Cannot change T or NIL}
  803. {\tt \begin{tabbing} MACRO PROCEDURE SETQ(X); \\
  804. \hspace*{1em} LIST('SET, LIST('QUOTE, CADR X), CADDR X);
  805. \end{tabbing}}
  806. }
  807. \de{UNFLUID}{(\p{IDLIST}:\ty{id-list}):\ty{NIL}}{eval, spread}
  808. {The variables in IDLIST that have been declared as FLUID variables
  809. are no longer considered as fluid variables. Others are ignored. This
  810. affects only compiled functions as free variables in interpreted
  811. functions are automatically considered fluid~\cite{PLC}.
  812. \index{scope ! fluid and compiled}}
  813. \subsection{Program Feature Functions}
  814. \label{prog}
  815. These functions provide for explicit control sequencing, and the
  816. definition of blocks altering the scope of local variables.
  817. \de{GO}{(\p{LABEL}:\ty{id})}{noeval, nospread}
  818. {GO alters the normal flow of control within a PROG function. The next
  819. statement of a PROG function to be evaluated is immediately preceded
  820. by LABEL. A GO may only appear in the following situations:
  821. \begin{enumerate}
  822. \item At the top level of a PROG referencing a label which also
  823. appears at the top level of the same PROG.
  824. \item As the consequent of a COND item of a COND appearing on the top
  825. level of a PROG.
  826. \index{GO ! in COND}
  827. \index{RETURN ! in COND}
  828. \item As the consequent of a COND item which appears as the
  829. consequent of a COND item to any level.
  830. \item As the last statement of a PROGN which appears at the top level
  831. of a PROG or in a PROGN appearing in the consequent of a COND to any
  832. level subject to the restrictions of 2 and 3.
  833. \item As the last statement of a PROGN within a PROGN or as the
  834. consequent of a COND in a PROGN to any level subject to the
  835. restrictions of 2, 3 and 4.
  836. \end{enumerate}
  837. If LABEL does not appear at the top level of the PROG in which the GO
  838. appears, an error occurs:
  839. \errormessage{***** LABEL is not a known label}
  840. If the GO has been placed in a position not defined by rules 1-5,
  841. another error is detected:
  842. \errormessage{***** Illegal use of GO to LABEL}
  843. }
  844. \de{PROG}{(\p{VARS}:\ty{id-list},
  845. [\p{PROGRAM}:\{\ty{id, any}\}]):\ty{any}}{noeval, nospread}
  846. {VARS is a list of ids which are considered fluid when the PROG is
  847. interpreted and local when compiled (see ``Variables and Bindings'',
  848. section~\ref{varsandbinds} on page~\pageref{varsandbinds}). The PROGs
  849. variables are allocated space when the PROG form is invoked and are
  850. deallocated when the PROG is exited. PROG variables are initialized to
  851. \index{PROG ! variables}
  852. NIL. The PROGRAM is a set of expressions to be evaluated in order of
  853. their appearance in the PROG function. Identifiers appearing in the
  854. top level of the PROGRAM are labels which can be referenced by GO. The
  855. value returned by the PROG function is determined by a RETURN function
  856. \index{PROG ! default value}
  857. or NIL if the PROG ``falls through''.}
  858. \de{PROGN}{([\p{U}:\ty{any}]):\ty{any}}{noeval, nospread}
  859. {U is a set of expressions which are executed sequentially. The value
  860. returned is the value of the last expression.}
  861. \de{PROG2}{(A:any, B:any)\ty{any}}{eval, spread}
  862. {Returns the value of B.
  863. {\tt \begin{tabbing} EXPR PROCEDURE PROG2(A, B);\\
  864. \hspace*{1em} B;
  865. \end{tabbing}}}
  866. \de{RETURN}{(\p{U}:\ty{any})}{eval, spread}
  867. {Within a PROG, RETURN terminates the evaluation of a PROG and returns
  868. U as the value of the PROG. The restrictions on the placement of
  869. RETURN are exactly those of GO. Improper placement of RETURN results
  870. in the error:
  871. \errormessage{***** Illegal use of RETURN}
  872. }
  873. \subsection{Error Handling}
  874. \label{errors}
  875. \de{ERROR}{(\p{NUMBER}:\ty{integer}, \p{MESSAGE}:\ty{any})}{eval, spread}
  876. {NUMBER and MESSAGE are passed back to a surrounding ERRORSET (the
  877. Standard LISP reader has an ERRORSET). MESSAGE is placed in the
  878. \index{EMSG* (global)}
  879. global variable EMSG!* and the error number becomes the value of the
  880. surrounding ERRORSET. FLUID variables and local bindings are unbound
  881. \index{fluid ! unbinding by ERROR}
  882. to return to the environment of the ERRORSET. Global variables are not
  883. affected by the process.}
  884. \de{ERRORSET}{(\p{U}:\ty{any}, \p{MSGP}:\ty{boolean},
  885. \p{TR}:\ty{boolean}):\ty{any}}{eval, spread}
  886. {If an error occurs during the evaluation of U, the value of NUMBER
  887. from the ERROR call is returned as the value of ERRORSET. In addition,
  888. if the value of MSGP is non-NIL, the MESSAGE from the ERROR call is
  889. displayed upon both the standard output device and the currently
  890. selected output device unless the standard output device is not open.
  891. The message appears prefixed with 5 asterisks. The MESSAGE
  892. \index{***** (error message)}
  893. list is displayed without top level parentheses. The MESSAGE from the
  894. \index{EMSG* (global)}
  895. ERROR call will be available in the global variable EMSG!*. The exact
  896. format of error messages generated by Standard LISP functions
  897. described in this document are not fixed and should not be relied upon
  898. to be in any particular form. Likewise, error numbers generated by
  899. Standard LISP functions are implementation dependent.
  900. If no error occurs during the evaluation of U, the value of (LIST
  901. (EVAL U)) is returned.
  902. If an error has been signaled and the value of TR is non-NIL a
  903. traceback sequence will be initiated on the selected output device.
  904. The traceback will display information such as unbindings of FLUID
  905. \index{fluid ! in traceback}
  906. variables, argument lists and so on in an implementation dependent
  907. format.}
  908. \subsection{Vectors}
  909. \label{vectors}
  910. \index{vector}
  911. Vectors are structured entities in which random elements may be
  912. accessed with an integer index. A vector has a single dimension. Its
  913. maximum size is determined by the implementation and available space.
  914. A suggested input ``vector notation'' is defined in ``Classes of
  915. Primitive Data Types'', section~\ref{pclasses} on
  916. page~\pageref{pclasses} and output with EXPLODE, ``Identifiers''
  917. section~\ref{identifiers} on page~\pageref{identifiers}.
  918. \index{EXPLODE}
  919. \de{GETV}{(\p{V}:\ty{vector}, \p{INDEX}:\ty{integer}):\ty{any}}{eval, spread}
  920. {Returns the value stored at position INDEX of the vector V. The type
  921. mismatch error may occur. An error occurs if the INDEX does not lie
  922. within 0\ldots UPBV(V) inclusive:
  923. \errormessage{***** INDEX subscript is out of range}
  924. }
  925. \de{MKVECT}{(\p{UPLIM}:\ty{integer}):\ty{vector}}{eval, spread}
  926. {Defines and allocates space for a vector with UPLIM+1 elements
  927. accessed as 0\ldots UPLIM. Each element is initialized to NIL. An
  928. error will occur if UPLIM is $<$ 0 or there is not enough space for a
  929. vector of this size:
  930. \errormessage{***** A vector of size UPLIM cannot be allocated}
  931. }
  932. \de{PUTV}{(\p{V}:\ty{vector}, \p{INDEX}:\ty{integer},
  933. \p{VALUE}:\ty{any}):\ty{any}}{eval, spread}
  934. {Stores VALUE into the vector V at position INDEX. VALUE is returned.
  935. The type mismatch error may occur. If INDEX does not lie in 0\ldots
  936. UPBV(V) an error occurs:
  937. \errormessage{***** INDEX subscript is out of range}
  938. }
  939. \de{UPBV}{(\p{U}:\ty{any}):{NIL,\ty{integer}}}{eval, spread}
  940. {Returns the upper limit of U if U is a vector, or NIL if it is not.}
  941. \subsection{Boolean Functions and Conditionals}
  942. \de{AND}{([\p{U}:\ty{any}]):\ty{extra-boolean}}{noeval, nospread}
  943. {AND evaluates each U until a value of NIL is found or the end of the
  944. list is encountered. If a non-NIL value is the last value it is
  945. returned, or NIL is returned.
  946. {\tt \begin{tabbing} FEXPR PROCEDURE AND(U); \\ BEGIN \\
  947. \hspace*{1em} IF NULL U THEN RETURN NIL; \\
  948. LOOP: IF \= NULL CDR U THEN RETURN EVAL CAR U \\
  949. \> ELSE IF NULL EVAL CAR U THEN RETURN NIL; \\
  950. \hspace*{2em} \= U := CDR U; \\
  951. \> GO LOOP \\
  952. END;
  953. \end{tabbing} }}
  954. \de{COND}{([\p{U}:\ty{cond-form}]):\ty{any}}{noeval, nospread}
  955. {The antecedents of all U's are evaluated in order of their appearance
  956. until a non-NIL value is encountered. The consequent of the selected U
  957. is evaluated and becomes the value of the COND. The consequent may
  958. also contain the special functions GO and RETURN subject to the
  959. restraints given for these functions in ``Program Feature Functions'',
  960. section~\ref{prog} on page~\pageref{prog}.
  961. \index{GO ! in COND} \index{RETUNR ! in CODE} In these cases COND does
  962. not have a defined value, but rather an effect. If no antecedent is
  963. non-NIL the value of COND is NIL. An error is detected if a U is
  964. improperly formed:
  965. \errormessage{***** Improper cond-form as argument of COND}
  966. }
  967. \de{NOT}{(\p{U}:\ty{any}):\ty{boolean}}{eval, spread}
  968. {If U is NIL, return T else return NIL (same as function NULL).
  969. {\tt \begin{tabbing} EXPR PROCEDURE NOT(U); \\
  970. \hspace*{1em} U EQ NIL;
  971. \end{tabbing}}
  972. }
  973. \de{OR}{([\p{U}:\ty{any}]):\ty{extra-boolean}}{noeval, nospread}
  974. {U is any number of expressions which are evaluated in order of their
  975. appearance. When one is found to be non-NIL it is returned as the
  976. value of OR. If all are NIL, NIL is returned.
  977. {\tt \begin{tabbing} FEXPR PROCEDURE OR(U); \\ BEGIN SCALAR X; \\
  978. LOOP: IF \= NULL U THEN RETURN NIL \\
  979. \> ELSE IF (X := EVAL CAR U) THEN RETURN X; \\
  980. \hspace*{2em} \= U := CDR U; \\
  981. \> GO LOOP \\
  982. END;
  983. \end{tabbing} }}
  984. \subsection{Arithmetic Functions}
  985. Conversions between numeric types are provided explicitly by the
  986. \index{FIX} \index{FLOAT}
  987. FIX and FLOAT functions and implicitly by any multi-parameter
  988. \index{mixed-mode arithmetic}
  989. arithmetic function which receives mixed types of arguments. A
  990. conversion from fixed to floating point numbers may result in a loss
  991. of precision without a warning message being generated. Since
  992. \index{integer ! magnitude}
  993. integers may have a greater magnitude that that permitted for floating
  994. numbers, an error may be signaled when the attempted conversion cannot
  995. be done. Because the magnitude of integers is unlimited the conversion
  996. of a floating point number to a fixed number is always possible, the
  997. only loss of precision being the digits to the right of the decimal
  998. point which are truncated. If a function receives mixed types of
  999. arguments the general rule will have the fixed numbers converted to
  1000. floating before arithmetic operations are performed. In all cases an
  1001. error occurs if the parameter to an arithmetic function is not a
  1002. number:
  1003. \errormessage{***** XXX parameter to FUNCTION is not a number}
  1004. XXX is the value of the parameter at fault and FUNCTION is the name of
  1005. the function that detected the error. Exceptions to the rule are noted
  1006. where they occur.
  1007. \de{ABS}{(\p{U}:\ty{number}):\ty{number}}{eval, spread}
  1008. {Returns the absolute value of its argument.
  1009. {\tt \begin{tabbing} EXPR PROCEDURE ABS(U); \\
  1010. \hspace*{1em} IF LESSP(U, 0) THEN MINUS(U) ELSE U;
  1011. \end{tabbing}}}
  1012. \de{ADD1}{(\p{U}:\ty{number}):\ty{number}}{eval, spread}
  1013. {Returns the value of U plus 1 of the same type as U (fixed or
  1014. floating).
  1015. {\tt \begin{tabbing} EXPR PROCEDURE ADD1(U); \\
  1016. % God knows why, but hspace* isn't accepted here.
  1017. \hspace{1em} PLUS2(U, 1);
  1018. \end{tabbing}}
  1019. }
  1020. \de{DIFFERENCE}{(\p{U}:\ty{number}, \p{V}:\ty{number}):\ty{number}}{eval,
  1021. spread}
  1022. {The value U - V is returned.}
  1023. \de{DIVIDE}{(\p{U}:\ty{number}, \p{V}:\ty{number}):\ty{dotted-pair}}{eval,
  1024. spread}
  1025. {The dotted-pair (quotient . remainder) is returned. The quotient part
  1026. is computed the same as by QUOTIENT and the remainder the same as by
  1027. REMAINDER. An error occurs if division by zero is attempted:
  1028. \index{division by zero}
  1029. \errormessage{***** Attempt to divide by 0 in DIVIDE}
  1030. {\tt \begin{tabbing} EXPR PROCEDURE DIVIDE(U, V); \\
  1031. \hspace*{1em} (QUOTIENT(U, V) . REMAINDER(U, V));
  1032. \end{tabbing}}}
  1033. \de{EXPT}{(\p{U}:\ty{number}, \p{V}:\ty{integer}):\ty{number}}{eval, spread}
  1034. {Returns U raised to the V power. A floating point U to an integer
  1035. power V does \underline{not} have V changed to a floating number
  1036. before exponentiation.}
  1037. \de{FIX}{(\p{U}:\ty{number}):\ty{integer}}{eval, spread}
  1038. {Returns an integer which corresponds to the truncated value of U. The
  1039. result of conversion must retain all significant portions of U. If U
  1040. is an integer it is returned unchanged. }
  1041. \de{FLOAT}{(\p{U}:\ty{number}):\ty{floating}}{eval, spread}
  1042. {The floating point number corresponding to the value of the argument
  1043. U is returned. Some of the least significant digits of an integer may
  1044. be lost do to the implementation of floating point numbers. FLOAT of a
  1045. floating point number returns the number unchanged. If U is too large
  1046. to represent in floating point an error occurs:
  1047. \errormessage{***** Argument to FLOAT is too large}
  1048. }
  1049. \de{GREATERP}{(\p{U}:\ty{number}, \p{V}:\ty{number}):\ty{boolean}}{eval,
  1050. spread}
  1051. {Returns T if U is strictly greater than V, otherwise returns NIL.}
  1052. \de{LESSP}{(\p{U}:\ty{number}, \p{V}:\ty{number}):\ty{boolean}}{eval, spread}
  1053. {Returns T if U is strictly less than V, otherwise returns NIL. }
  1054. \de{MAX}{([\p{U}:\ty{number}]):\ty{number}}{noeval, nospread, or macro}
  1055. {Returns the largest of the values in U. If two or more values are the
  1056. same the first is returned.
  1057. {\tt \begin{tabbing} MACRO PROCEDURE MAX(U); \\
  1058. \hspace*{1em} EXPAND(CDR U, 'MAX2);
  1059. \end{tabbing}}}
  1060. \de{MAX2}{(\p{U}:\ty{number}, \p{V}:\ty{number}):\ty{number}}{eval, spread}
  1061. {Returns the larger of U and V. If U and V are the same value U is
  1062. returned (U and V might be of different types).
  1063. {\tt \begin{tabbing} EXPR PROCEDURE MAX2(U, V); \\
  1064. \hspace*{1em} IF LESSP(U, V) THEN V ELSE U;
  1065. \end{tabbing}}}
  1066. \de{MIN}{([\p{U}:\ty{number}]):\ty{number}}{noeval, nospread, or macro}
  1067. {Returns the smallest of the values in U. If two or more values are
  1068. the same the first of these is returned.
  1069. {\tt \begin{tabbing} MACRO PROCEDURE MIN(U); \\
  1070. \hspace*{1em} EXPAND(CDR U, 'MIN2);
  1071. \end{tabbing}}}
  1072. \de{MIN2}{(\p{U}:\ty{number}, \p{V}:\ty{number}):\ty{number}}{eval, spread}
  1073. {Returns the smaller of its arguments. If U and V are the same value,
  1074. U is returned (U and V might be of different types).
  1075. {\tt \begin{tabbing} EXPR PROCEDURE MIN2(U, V); \\
  1076. \hspace*{1em} IF GREATERP(U, V) THEN V ELSE U;
  1077. \end{tabbing}}}
  1078. \de{MINUS}{(\p{U}:\ty{number}):\ty{number}}{eval, spread}
  1079. {Returns -U.
  1080. {\tt \begin{tabbing} EXPR PROCEDURE MINUS(U); \\
  1081. \hspace*{1em} DIFFERENCE(0, U);
  1082. \end{tabbing}}}
  1083. \de{PLUS}{([\p{U}:\ty{number}]):\ty{number}}{noeval, nospread, or macro}
  1084. {Forms the sum of all its arguments.
  1085. {\tt \begin{tabbing} MACRO PROCEDURE PLUS(U); \\
  1086. \hspace*{1em} EXPAND(CDR U, 'PLUS2);
  1087. \end{tabbing}}}
  1088. \de{PLUS2}{(\p{U}:\ty{number}, \p{V}:\ty{number}):\ty{number}}{eval, spread}
  1089. {Returns the sum of U and V.}
  1090. \de{QUOTIENT}{(\p{U}:\ty{number}, \p{V}:\ty{number}):\ty{number}}{eval, spread}
  1091. {The quotient of U divided by V is returned. Division of two positive
  1092. or two negative integers is conventional. When both U and V are
  1093. integers and exactly one of them is negative the value returned is the
  1094. negative truncation of the absolute value of U divided by the absolute
  1095. value of V. An error occurs if division by zero is attempted:
  1096. \index{division by zero}
  1097. \errormessage{***** Attempt to divide by 0 in QUOTIENT}
  1098. }
  1099. \de{REMAINDER}{(\p{U}:\ty{number}, \p{V}:\ty{number}):\ty{number}}{eval,
  1100. spread}
  1101. {If both U and V are integers the result is the integer remainder of U
  1102. divided by V. If either parameter is floating point, the result is the
  1103. difference between U and V*(U/V) all in floating point. If either
  1104. number is negative the remainder is negative. If both are positive or
  1105. both are negative the remainder is positive. An error occurs if V is
  1106. zero: \index{division by zero}
  1107. \errormessage{***** Attempt to divide by 0 in REMAINDER}
  1108. {\tt \begin{tabbing} EXPR PROCEDURE REMAINDER(U, V); \\
  1109. \hspace*{1em} DIFFERENCE(U, TIMES2(QUOTIENT(U, V), V));
  1110. \end{tabbing}}}
  1111. \de{SUB1}{(\p{U}:\ty{number}):\ty{number}}{eval, spread}
  1112. {Returns the value of U less 1. If U is a FLOAT type number, the
  1113. value returned is U less 1.0.
  1114. {\tt \begin{tabbing} EXPR PROCEDURE SUB1(U); \\
  1115. \hspace*{1em} DIFFERENCE(U, 1);
  1116. \end{tabbing}}}
  1117. \de{TIMES}{([\p{U}:\ty{number}]):\ty{number}}{noeval, nospread, or macro}
  1118. {Returns the product of all its arguments.
  1119. {\tt \begin{tabbing} MACRO PROCEDURE TIMES(U); \\
  1120. \hspace*{1em} EXPAND(CDR U, 'TIMES2);
  1121. \end{tabbing}}}
  1122. \de{TIMES2}{(\p{U}:\ty{number}, \p{V}:\ty{number}):\ty{number}}{eval, spread}
  1123. {Returns the product of U and V.}
  1124. \subsection{MAP Composite Functions}
  1125. \de{MAP}{(\p{X}:\ty{list}, F\p{N}:\ty{function}):\ty{any}}{eval, spread}
  1126. {Applies FN to successive CDR segments of X. NIL is returned.
  1127. {\tt \begin{tabbing} EXPR PROCEDURE MAP(X, FN); \\
  1128. \hspace*{1em} WHILE X DO $<<$ FN X; X := CDR X $>>$;
  1129. \end{tabbing}}}
  1130. \de{MAPC}{(X:list, FN:function):\ty{any}}{eval, spread}
  1131. {FN is applied to successive CAR segments of list X. NIL is returned.
  1132. {\tt \begin{tabbing} EXPR PROCEDURE MAPC(X, FN); \\
  1133. \hspace*{1em} WHILE X DO $<<$ FN CAR X; X := CDR X $>>$;
  1134. \end{tabbing}}}
  1135. \de{MAPCAN}{(X:list, FN:function):\ty{any}}{eval, spread}
  1136. {A concatenated list of FN applied to successive CAR elements of X is
  1137. returned.
  1138. {\tt \begin{tabbing} EXPR PROCEDURE MAPCAN(X, FN); \\
  1139. \hspace*{1em} IF\= NULL X THEN NIL \\
  1140. \> ELSE NCONC(FN CAR X, MAPCAN(CDR X, FN));
  1141. \end{tabbing}}}
  1142. \de{MAPCAR}{(X:list, FN:function):\ty{any}}{eval, spread}
  1143. {Returned is a constructed list of FN applied to each CAR of list X.
  1144. {\tt \begin{tabbing} EXPR PROCEDURE MAPCAR(X, FN); \\
  1145. \hspace*{1em} IF\= NULL X THEN NIL \\
  1146. \> ELSE FN CAR X . MAPCAR(CDR X, FN);
  1147. \end{tabbing}}}
  1148. \de{MAPCON}{(X:list, FN:function):\ty{any}}{eval, spread}
  1149. {Returned is a concatenated list of FN applied to successive CDR
  1150. segments of X.
  1151. {\tt \begin{tabbing} EXPR PROCEDURE MAPCON(X, FN); \\
  1152. \hspace*{1em} IF\= NULL X THEN NIL \\
  1153. \> ELSE NCONC(FN X, MAPCON(CDR X, FN));
  1154. \end{tabbing}}}
  1155. \de{MAPLIST}{(X:list, FN:function):\ty{any}}{eval, spread}
  1156. {Returns a constructed list of FN applied to successive CDR segments
  1157. of X.
  1158. {\tt \begin{tabbing} EXPR PROCEDURE MAPLIST(X, FN); \\
  1159. \hspace*{1em} IF\= NULL X THEN NIL \\
  1160. \> ELSE FN X . MAPLIST(CDR X, FN);
  1161. \end{tabbing}}}
  1162. \subsection{Composite Functions}
  1163. \de{APPEND}{(\p{U}:\ty{list}, \p{V}:\ty{list}):\ty{list}}{eval, spread}
  1164. {Returns a constructed list in which the last element of U is followed
  1165. by the first element of V. The list U is copied, V is not.
  1166. {\tt \begin{tabbing} EXPR PROCEDURE APPEND(U, V); \\
  1167. \hspace*{1em} IF\= NULL U THEN V \\
  1168. \> ELSE CAR U . APPEND(CDR U, V);
  1169. \end{tabbing}}}
  1170. \de{ASSOC}{(\p{U}:\ty{any}, \p{V}:\ty{alist}):\{\ty{dotted-pair},
  1171. NIL\}}{eval, spread}
  1172. {If U occurs as the CAR portion of an element of the alist V, the
  1173. dotted-pair in which U occurred is returned, else NIL is returned.
  1174. ASSOC might not detect a poorly formed alist so an invalid
  1175. \index{EQUAL ! in ASSOC} \index{alist ! in ASSOC}
  1176. construction may be detected by CAR or CDR.
  1177. {\tt \begin{tabbing} EXPR PROCEDURE ASSOC(U, V); \\
  1178. \hspace*{1em} IF \= NULL V THEN NIL \\
  1179. \> ELSE \= IF ATOM CAR V THEN \\
  1180. \> \> ERROR(000, LIST(V, "is a poorly formed alist")) \\
  1181. \> ELSE IF U = CAAR V THEN CAR V \\
  1182. \> ELSE ASSOC(U, CDR V);
  1183. \end{tabbing}}
  1184. }
  1185. \de{DEFLIST}{(\p{U}:\ty{dlist}, \p{IND}:\ty{id}):\ty{list}}{eval, spread}
  1186. {A "dlist" is a list in which each element is a two element list:
  1187. \index{dlist}
  1188. (ID:id PROP:any). Each ID in U has the indicator IND with property
  1189. PROP placed on its property list by the PUT function. The value of
  1190. DEFLIST is a list of the first elements of each two element list.
  1191. Like PUT, DEFLIST may not be used to define functions.
  1192. {\tt \begin{tabbing} EXPR PROCEDURE DEFLIST(U, IND); \\
  1193. \hspace*{1em} IF NULL U THEN NIL \\
  1194. \hspace*{2em} ELSE $<<$ \= PUT(CAAR U, IND, CADAR U); \\
  1195. \> CAAR U $>>$ . DEFLIST(CDR U, IND);
  1196. \end{tabbing}}
  1197. }
  1198. \de{DELETE}{(\p{U}:\ty{any}, \p{V}:\ty{list}):\ty{list}}{eval, spread}
  1199. {Returns V with the first top level occurrence of U removed from it.
  1200. \index{EQUAL ! in DELETE}
  1201. {\tt \begin{tabbing} EXPR PROCEDURE DELETE(U, V); \\
  1202. \hspace*{1em} IF NULL V THEN NIL \\
  1203. \hspace*{2em} ELSE IF CAR V = U THEN CDR V \\
  1204. \hspace*{2em} ELSE CAR V . DELETE(U, CDR V);
  1205. \end{tabbing}}}
  1206. \de{DIGIT}{(\p{U}:\ty{any}):\ty{boolean}}{eval, spread}
  1207. {Returns T if U is a digit, otherwise NIL.
  1208. {\tt \begin{tabbing} EXPR PROCEDURE DIGIT(U); \\
  1209. \hspace*{1em} IF MEMQ(U, '(!0 !1 !2 !3 !4 !5 !6 !7 !8 !9)) \\
  1210. \hspace*{2em} THEN T ELSE NIL;
  1211. \end{tabbing}}}
  1212. \de{LENGTH}{(\p{X}:\ty{any}):\ty{integer}}{eval, spread}
  1213. {The top level length of the list X is returned.
  1214. {\tt \begin{tabbing} EXPR PROCEDURE LENGTH(X); \\
  1215. \hspace*{1em} IF ATOM X THEN 0 \\
  1216. \hspace*{2em} ELSE PLUS(1, LENGTH CDR X);
  1217. \end{tabbing}}}
  1218. \de{LITER}{(\p{U}:\ty{any}):\ty{boolean}}{eval, spread}
  1219. {Returns T if U is a character of the alphabet, NIL
  1220. otherwise.\footnote{The published report omits escape characters.
  1221. These are required for both upper and lower case as some systems
  1222. default to lower.}
  1223. {\tt \begin{tabbing} EXPR PROCEDURE LITER(U); \\
  1224. \hspace*{1em} IF \= MEMQ(U, '(\=!A !B !C !D !E !F !G !H !I !J !K !L !M \\
  1225. \> \> !N !O !P !Q !R !S !T !U !V !W !X !Y !Z \\
  1226. \> \> !a !b !c !d !e !f !g !h !i !j !k !l !m \\
  1227. \> \> !n !o !p !q !r !s !t !u !v !w !x !y !z)) \\
  1228. \> THEN T ELSE NIL;
  1229. \end{tabbing}}}
  1230. \de{MEMBER}{(\p{A}:\ty{any}, \p{B}:\ty{list}):\ty{extra-boolean}}{eval, spread}
  1231. {Returns NIL if A is not a member of list B, returns the remainder of
  1232. B whose first element is A. \index{EQUAL ! in MEMBER}
  1233. {\tt \begin{tabbing} EXPR PROCEDURE MEMBER(A, B); \\
  1234. \hspace*{1em} IF NULL B THEN NIL \\
  1235. \hspace*{2em} ELSE IF A = CAR B THEN B \\
  1236. \hspace*{2em} ELSE MEMBER(A, CDR B);
  1237. \end{tabbing}}}
  1238. \de{MEMQ}{(\p{A}:\ty{any}, \p{B}:\ty{list}):\ty{extra-boolean}}{eval, spread}
  1239. {Same as MEMBER but an EQ check is used for comparison. \index{EQ ! in
  1240. MEMQ}
  1241. {\tt \begin{tabbing} EXPR PROCEDURE MEMQ(A, B); \\
  1242. \hspace*{1em} IF \= NULL B THEN NIL \\
  1243. \> ELSE IF A EQ CAR B THEN B \\
  1244. \> ELSE MEMQ(A, CDR B);
  1245. \end{tabbing}}}
  1246. \de{NCONC}{(\p{U}:\ty{list}, \p{V}:\ty{list}):\ty{list}}{eval, spread}
  1247. {Concatenates V to U without copying U. The last CDR of U is modified
  1248. to point to V.
  1249. {\tt \begin{tabbing} EXPR PROCEDURE NCONC(U, V); \\ BEGIN SCALAR W; \\
  1250. \hspace*{2em} \= IF NULL U THEN RETURN V; \\
  1251. \> W := U; \\
  1252. \> WHILE CDR W DO W := CDR W; \\
  1253. \> RPLACD(W, V); \\
  1254. \> RETURN U \\
  1255. END;
  1256. \end{tabbing}}}
  1257. \de{PAIR}{(\p{U}:\ty{list}, \p{V}:\ty{list}):\ty{alist}}{eval, spread}
  1258. {U and V are lists which must have an identical number of elements. If
  1259. not, an error occurs (the 000 used in the ERROR call is arbitrary and
  1260. need not be adhered to). Returned is a list where each element is a
  1261. dotted-pair, the CAR of the pair being from U, and the CDR the
  1262. corresponding element from V.
  1263. {\tt \begin{tabbing} EXPR PROCEDURE PAIR(U, V); \\
  1264. \hspace*{1em} IF AND(U, V) THEN (CAR U . CAR V) . PAIR(CDR U, CDR V) \\
  1265. \hspace*{2em} \= ELSE IF OR(U, V) THEN ERROR(000, \\
  1266. \hspace*{4em} "Different length lists in PAIR") \\
  1267. \> ELSE NIL;
  1268. \end{tabbing}}}
  1269. \de{REVERSE}{(\p{U}:\ty{list}):\ty{list}}{eval, spread}
  1270. {Returns a copy of the top level of U in reverse order.
  1271. {\tt \begin{tabbing} EXPR PROCEDURE REVERSE(U); \\ BEGIN SCALAR W; \\
  1272. \hspace*{2em} \= WHILE U DO $<<$ \= W := CAR U . W; \\
  1273. \> \> U := CDR U $>>$; \\
  1274. \> RETURN W \\
  1275. END;
  1276. \end{tabbing}}}
  1277. \de{SASSOC}{(\p{U}:\ty{any}, \p{V}:\ty{alist},
  1278. \p{FN}:\ty{function}):\ty{any}}{eval, spread}
  1279. {Searches the alist V for an occurrence of U. If U is not in the alist
  1280. the evaluation of function FN is returned. \index{EQUAL ! in SASSOC}
  1281. \index{alist ! in SASSOC}
  1282. {\tt \begin{tabbing} EXPR PROCEDURE SASSOC(U, V, FN); \\
  1283. \hspace*{1em} IF NULL V THEN FN() \\
  1284. \hspace*{2em} \= ELSE IF U = CAAR V THEN CAR V \\
  1285. \> ELSE SASSOC(U, CDR V, FN);
  1286. \end{tabbing}}}
  1287. \de{SUBLIS}{(\p{X}:\ty{alist}, \p{Y}:\ty{any}):\ty{any}}{eval, spread}
  1288. {The value returned is the result of substituting the CDR of each
  1289. element of the alist X for every occurrence of the CAR part of that
  1290. element in Y. \index{alist ! in SUBLIS}
  1291. {\tt \begin{tabbing} EXPR PROCEDURE SUBLIS(X, Y); \\
  1292. \hspace*{1em}IF NULL X THEN Y \\
  1293. \hspace*{2em} ELSE BEGIN \= SCALAR U; \\
  1294. \> U := ASSOC(Y, X); \\
  1295. \> RETURN \= IF U THEN CDR U \\
  1296. \> \> ELSE IF ATOM Y THEN Y \\
  1297. \> \> ELSE \= SUBLIS(X, CAR Y) . \\
  1298. \> \> \> SUBLIS(X, CDR Y) \\
  1299. \> END;
  1300. \end{tabbing}}}
  1301. \de{SUBST}{(\p{U}:\ty{any}, \p{V}:\ty{any}, \p{W}:\ty{any}):\ty{any}}{eval,
  1302. spread}
  1303. {The value returned is the result of substituting U for all
  1304. occurrences of V in W. \index{EQUAL ! in SUBST}
  1305. {\tt \begin{tabbing} EXPR PROCEDURE SUBST(U, V, W); \\
  1306. \hspace*{1em} IF NULL W THEN NIL \\
  1307. \hspace*{2em} \= ELSE IF V = W THEN U \\
  1308. \> ELSE IF ATOM W THEN W \\
  1309. \> ELSE SUBST(U, V, CAR W) . SUBST(U, V, CDR W);
  1310. \end{tabbing}}}
  1311. \subsection{The Interpreter}
  1312. \label{interpreter}
  1313. \de{APPLY}{(\p{FN}:\{\ty{id,function}\},
  1314. \p{ARGS}:\ty{any-list}):\ty{any}}{eval, spread}
  1315. {APPLY returns the value of FN with actual parameters ARGS. The actual
  1316. parameters in ARGS are already in the form required for binding to the
  1317. formal parameters of FN. Implementation specific portions described in
  1318. English are enclosed in boxes.
  1319. {\tt \begin{tabbing} EXPR PROCEDURE APPLY(FN, ARGS); \\ BEGIN SCALAR
  1320. DEFN; \\
  1321. \hspace*{2em}\= IF CODEP FN THEN RETURN \\
  1322. \> \hspace{1em} \framebox[3.25in]{\parbox{3.25in}{Spread the actual
  1323. parameters in ARGS
  1324. following the conventions: for calling functions, transfer to the
  1325. entry point of the function, and return the value returned by the
  1326. function.}}; \\
  1327. \> IF \= IDP FN THEN RETURN \\
  1328. \> \> IF \= NULL(DEFN := GETD FN) THEN \\
  1329. \> \> \> ERROR(000, LIST(FN, "is an undefined function")) \\
  1330. \> \> ELSE IF CAR DEFN EQ 'EXPR THEN \\
  1331. \> \> \> APPLY(CDR DEFN, ARGS) \\
  1332. \> \> ELSE ERROR(000, \\
  1333. \> \> \> LIST(FN, "cannot be evaluated by APPLY")); \\
  1334. \> IF OR(ATOM FN, NOT(CAR FN EQ 'LAMBDA)) THEN \\
  1335. \> \> ERROR(000, \\
  1336. \> \> LIST(FN, "cannot be evaluated by APPLY")); \\
  1337. \> RETURN \\
  1338. \> \> \framebox[3.25in]{\parbox{3.25in}{Bind the actual parameters in ARGS to
  1339. the formal
  1340. parameters of the lambda expression. If the two lists are not of equal
  1341. length then ERROR(000, "Number of parameters do not match"); The value
  1342. returned is EVAL CADDR FN.}} \\ END;
  1343. \end{tabbing}}}
  1344. \de{EVAL}{(\p{U}:\ty{any}):\ty{any}}{eval, spread}
  1345. {The value of the expression U is computed. Error numbers are
  1346. arbitrary. Portions of EVAL involving machine specific coding are
  1347. expressed in English enclosed in boxes.
  1348. {\tt \begin{tabbing} EXPR PROCEDURE EVAL(U); \\ BEGIN SCALAR FN; \\
  1349. \hspace*{2em} \= IF CONSTANTP U THEN RETURN U; \\
  1350. \> IF IDP U THEN RETURN \\
  1351. \> \hspace{1em} \framebox[3.25in]{\parbox{3.25in}{U is an id. Return the
  1352. value most currently
  1353. bound to U or if there is no such binding: ERROR(000, LIST("Unbound:",
  1354. U));}} \\
  1355. \> IF \= PAIRP CAR U THEN RETURN \\
  1356. \> \> IF CAAR U EQ 'LAMBDA THEN APPLY(CAR U, EVLIS CDR U) \\
  1357. \> \> ELSE ERROR(\= 000, LIST(CAR U, \\
  1358. \> \> \> "improperly formed LAMBDA expression")) \\
  1359. \> \> ELSE IF CODEP CAR U THEN \\
  1360. \> \> \> RETURN APPLY(CAR U, EVLIS CDR U); \\
  1361. \> FN := GETD CAR U; \\
  1362. \> IF NULL FN THEN \\
  1363. \> \> ERROR(000, LIST(CAR U, "is an undefined function")) \\
  1364. \> ELSE IF CAR FN EQ 'EXPR THEN \\
  1365. \> \> RETURN APPLY(CDR FN, EVLIS CDR U) \\
  1366. \> ELSE IF CAR FN EQ 'FEXPR THEN \\
  1367. \> \> RETURN APPLY(CDR FN, LIST CDR U) \\
  1368. \> ELSE IF CAR FN EQ 'MACRO THEN \\
  1369. \> \> RETURN EVAL APPLY(CDR FN, LIST U) \\
  1370. END;
  1371. \end{tabbing}}}
  1372. \de{EVLIS}{(\p{U}:\ty{any-list}):\ty{any-list}}{eval, spread}
  1373. {EVLIS returns a list of the evaluation of each element of U.
  1374. {\tt \begin{tabbing} EXPR PROCEDURE EVLIS(U); \\
  1375. \hspace*{1em} IF NULL U THEN NIL \\
  1376. \hspace*{2em} ELSE EVAL CAR U . EVLIS CDR U;
  1377. \end{tabbing}}}
  1378. \de{EXPAND}{(\p{L}:\ty{list}, \p{FN}:\ty{function}):\ty{list}}{eval, spread}
  1379. {FN is a defined function of two arguments to be used in the expansion
  1380. of a MACRO. EXPAND returns a list in the form:
  1381. \vspace{.15in}
  1382. (FN L$_0$ (FN L$_1$ \ldots (FN L$_{n-1}$ L$_n$) \ldots ))
  1383. \vspace{.15in}
  1384. where $n$ is the number of elements in L, L$_i$ is the $i$th element
  1385. of L.
  1386. {\tt \begin{tabbing} EXPR PROCEDURE EXPAND(L,FN); \\
  1387. \hspace*{1em} IF NULL CDR L THEN CAR L \\
  1388. \hspace*{2em} ELSE LIST(FN, CAR L, EXPAND(CDR L, FN));
  1389. \end{tabbing}}}
  1390. \de{FUNCTION}{(\p{FN}:\ty{function}):\ty{function}}{noeval, nospread}
  1391. {The function FN is to be passed to another function. If FN is to have
  1392. side effects its free variables must be fluid or global. FUNCTION is
  1393. like QUOTE but its argument may be affected by compilation. We do not
  1394. \index{FUNARGs not supported}
  1395. consider FUNARGs in this report.}
  1396. \de{QUOTE}{(U:any):\ty{any}}{noeval, nospread}
  1397. {Stops evaluation and returns U unevaluated.
  1398. {\tt \begin{tabbing} FEXPR PROCEDURE QUOTE(U); \\
  1399. \hspace*{2em}CAR U;
  1400. \end{tabbing}}}
  1401. \subsection{Input and Output}
  1402. \label{IO}
  1403. The user normally communicates with Standard LISP through
  1404. \index{standard devices}
  1405. ``standard devices''. The default devices are selected in accordance
  1406. with the conventions of the implementation site. Other input and
  1407. output devices or files may be selected for reading and writing using
  1408. the functions described herein.
  1409. \de{CLOSE}{(\p{FILEHANDLE}:\ty{any}):\ty{any}}{eval, spread}
  1410. {Closes the file with the internal name FILEHANDLE writing any
  1411. necessary end of file marks and such. The value of FILEHANDLE is that
  1412. returned by the corresponding OPEN. \index{OPEN} The value returned is
  1413. the value of FILEHANDLE. An error occurs if the file can not be
  1414. \index{file handle} \index{files}
  1415. closed.
  1416. \errormessage{ ***** FILEHANDLE could not be closed}
  1417. }
  1418. \de{EJECT}{():NIL}{eval, spread}
  1419. {Skip to the top of the next output page. Automatic EJECTs are
  1420. executed by the print functions when the length set by the PAGELENGTH
  1421. \index{PAGELENGTH} function is exceeded.}
  1422. \de{LINELENGTH}{(\p{LEN}:\{\ty{integer}, NIL\}):\ty{integer}}{eval, spread}
  1423. {If LEN is an integer the maximum line length to be printed before the
  1424. print functions initiate an automatic TERPRI is set to the value LEN.
  1425. \index{TERPRI}
  1426. No initial Standard LISP line length is assumed. The previous line
  1427. length is returned except when LEN is NIL. This special case returns
  1428. the current line length and does not cause it to be reset. An error
  1429. occurs if the requested line length is too large for the currently
  1430. selected output file or LEN is negative or zero.
  1431. \errormessage{ ***** LEN is an invalid line length}
  1432. }
  1433. \de{LPOSN}{():\ty{integer}}{eval, spread}
  1434. {Returns the number of lines printed on the current page. At the top
  1435. of a page, 0 is returned. }
  1436. \de{OPEN}{(\p{FILE}:\ty{any}, \p{HOW}:\ty{id}):\ty{any}}{eval, spread}
  1437. {Open the file with the system dependent name FILE for output if HOW
  1438. is EQ to OUTPUT, or input if HOW is EQ to INPUT. If the file is
  1439. \index{file handle} \index{files} \index{OUTPUT} \index{INPUT}
  1440. opened successfully, a value which is internally associated with the
  1441. file is returned. This value must be saved for use by RDS and WRS. An
  1442. error occurs if HOW is something other than INPUT or OUTPUT or the
  1443. file can't be opened.
  1444. \errormessage{***** HOW is not option for OPEN}
  1445. \errormessage{***** FILE could not be opened}
  1446. }
  1447. \de{PAGELENGTH}{(\p{LEN}:\{\ty{integer}, NIL\}):\ty{integer}}{eval, spread}
  1448. {Sets the vertical length (in lines) of an output page. Automatic page
  1449. EJECTs are executed by the print functions when this length is
  1450. \index{EJECT}
  1451. reached. The initial vertical length is implementation specific. The
  1452. previous page length is returned. If LEN is 0, no automatic page
  1453. ejects will occur. }
  1454. \de{POSN}{():\ty{integer}}{eval, spread}
  1455. {Returns the number of characters in the output buffer. When the
  1456. buffer is empty, 0 is returned.}
  1457. \de{PRINC}{(\p{U}:\ty{id}):\ty{id}}{eval, spread}
  1458. {U must be a single character id such as produced by EXPLODE or read
  1459. by READCH or the value of !\$EOL!\$. The effect is the character U
  1460. \index{\$EOL\$ (global)}
  1461. displayed upon the currently selected output device. The value of
  1462. !\$EOL!\$ causes termination of the current line like a call to
  1463. TERPRI.}
  1464. \de{PRINT}{(\p{U}:\ty{any}):\ty{any}}{eval, spread}
  1465. {Displays U in READ readable format and terminates the print line. The
  1466. value of U is returned.
  1467. {\tt \begin{tabbing} EXPR PROCEDURE PRINT(U); \\
  1468. \hspace*{2em} $<<$ PRIN1 U; TERPRI(); U $>>$;
  1469. \end{tabbing}}}
  1470. \de{PRIN1}{(\p{U}:\ty{any}):\ty{any}}{eval, spread}
  1471. {U is displayed in a READ readable form. The format of display is the
  1472. result of EXPLODE expansion; special characters are prefixed with the
  1473. escape character !, and strings are enclosed in "\ldots ". Lists are
  1474. displayed in list-notation and vectors in vector-notation. }
  1475. \de{PRIN2}{(\p{U}:\ty{any}):\ty{any}}{eval, spread}
  1476. {U is displayed upon the currently selected print device but output is
  1477. not READ readable. The value of U is returned. Items are displayed as
  1478. described in the EXPLODE function with the exceptions that the escape
  1479. character does not prefix special characters and strings are not
  1480. enclosed in "\ldots ". Lists are displayed in list-notation and
  1481. vectors in vector-notation. The value of U is returned. }
  1482. \de{RDS}{(\p{FILEHANDLE}:\ty{any}):\ty{any}}{eval, spread}
  1483. {Input from the currently selected input file is suspended and further
  1484. input comes from the file named. FILEHANDLE is a system dependent
  1485. \index{file handle}
  1486. internal name which is a value returned by OPEN. If FILEHANDLE is NIL
  1487. the standard input device is selected. When end of file is reached on
  1488. a non-standard input device, the standard input device is reselected.
  1489. When end of file occurs on the standard input device the Standard LISP
  1490. reader terminates. RDS returns the internal name of the previously
  1491. selected input file.
  1492. \index{standard input}
  1493. \errormessage{***** FILEHANDLE could not be selected for input}
  1494. }
  1495. \de{READ}{():\ty{any}}{}
  1496. {The next expression from the file currently selected for input. Valid
  1497. input forms are: vector-notation, dot-notation, list-notation,
  1498. numbers, function-pointers, strings, and identifiers with escape
  1499. characters. Identifiers are interned onW the OBLIST (see
  1500. \index{INTERN} \index{OBLIST entry}
  1501. the INTERN function in "Identifiers", section~\ref{identifiers} on
  1502. page~\pageref{identifiers}). READ returns the
  1503. \index{\$EOF\$ (global)}
  1504. value of !\$EOF!\$ when the end of the currently selected input file
  1505. is reached. }
  1506. \de{READCH}{():\ty{id}}{}
  1507. {Returns the next interned character from the file currently selected
  1508. for input. Two special cases occur. If all the characters in an input
  1509. \index{\$EOL\$ (global)} \index{\$EOF\$ (global)} record have been read,
  1510. the value of !\$EOL!\$ is returned. If the file selected for input has
  1511. all been read the value of !\$EOF!\$ is returned. Comments delimited
  1512. by \% and end-of-line are not transparent to READCH. \index{\% ! read
  1513. by READCH} }
  1514. \de{TERPRI}{():\p{NIL}}{}
  1515. {The current print line is terminated.}
  1516. \de{WRS}{(\p{FILEHANDLE}:\ty{any}):\ty{any}}{eval, spread}
  1517. {Output to the currently active output file is suspended and further
  1518. output is directed to the file named. FILEHANDLE is an internal name
  1519. which is returned by OPEN. The file named must have been opened for
  1520. output. If FILEHANDLE is NIL the standard output device is selected.
  1521. \index{file handle} \index{standard output}
  1522. WRS returns the internal name of the previously selected output file.
  1523. \errormessage{***** FILEHANDLE could not be selected for output}
  1524. }
  1525. \subsection{LISP Reader}
  1526. An EVAL read loop has been chosen to drive a Standard LISP system to
  1527. provide a continuity in functional syntax. Choices of messages and the
  1528. amount of extra information displayed are decisions left to the
  1529. implementor.
  1530. \index{STANDARD-LISP}
  1531. {\tt \begin{tabbing} EXPR PROCEDURE STANDARD!-LISP(); \\ BEGIN SCALAR
  1532. VALUE; \\
  1533. \hspace*{2em} \= RDS NIL; WRS NIL; \\
  1534. \> PRIN2 "Standard LISP"; TERPRI(); \\
  1535. \> WHILE T DO \\
  1536. \> \hspace*{1em} $<<$ \= PRIN2 "EVAL:"; TERPRI(); \\
  1537. \> \> VALUE := ERRORSET(QUOTE EVAL READ(), T, T); \\
  1538. \> \> IF NOT ATOM VALUE THEN PRINT CAR VALUE; \\
  1539. \> \> TERPRI() $>>$; \\
  1540. END;
  1541. \end{tabbing}}
  1542. \de{QUIT}{()}{}
  1543. {Causes termination of the LISP reader and control to be transferred
  1544. to the operating system.}
  1545. \section{System GLOBAL Variables}
  1546. \label{slglobals}
  1547. These variables provide global control of the LISP system, or
  1548. implement values which are constant throughout execution.\footnote{The
  1549. published document does not specify that all these are GLOBAL.}
  1550. \variable{*COMP}{NIL}{global}
  1551. {The value of !*COMP controls whether or not PUTD compiles the
  1552. function defined in its arguments before defining it. If !*COMP is NIL
  1553. the function is defined as an xEXPR. If !*COMP is something else the
  1554. function is first compiled. Compilation will produce certain changes
  1555. in the semantics of functions particularly FLUID type access.}
  1556. \variable{EMSG*}{NIL}{global}
  1557. {Will contain the MESSAGE generated by the last ERROR call (see
  1558. \index{ERROR}
  1559. ``Error Handling'' section~\ref{errors} on page~\pageref{errors}).}
  1560. \variable{\$EOF\$}{\s{an uninterned identifier}}{global}
  1561. {The value of !\$EOF!\$ is returned by all input functions when the
  1562. end
  1563. \index{end of file}
  1564. of the currently selected input file is reached.}
  1565. \variable{\$EOL\$}{\s{an uninterned identifier}}{global}
  1566. {The value of !\$EOL!\$ is returned by READCH when it reaches the end
  1567. of
  1568. \index{READCH} \index{end of line} \index{PRINC}
  1569. a logical input record. Likewise PRINC will terminate its current line
  1570. (like a call to TERPRI) when !\$EOL!\$ is its argument.}
  1571. \variable{*GC}{NIL}{global}
  1572. {!*GC controls the printing of garbage collector messages. If NIL no
  1573. \index{garbage collector}
  1574. indication of garbage collection may occur. If non-NIL various system
  1575. dependent messages may be displayed.}
  1576. \variable{NIL}{NIL}{global}
  1577. {NIL is a special global variable. It is protected from being modified
  1578. by SET or SETQ.
  1579. \index{NIL ! cannot be changed}}
  1580. \variable{*RAISE}{NIL}{global}
  1581. {If !*RAISE is non-NIL all characters input through Standard LISP
  1582. input/output functions will be raised to upper case. If !*RAISE is NIL
  1583. characters will be input as is.}
  1584. \variable{T}{T}{global}
  1585. {T is a special global variable. It is protected from being modified
  1586. by SET or SETQ. \index{T ! cannot be changed}}
  1587. \section{The Extended Syntax}
  1588. Whenever it is possible to define Standard LISP functions in LISP the
  1589. text of the function will appear in an extended syntax. These
  1590. definitions are supplied as an aid to understanding the behavior of
  1591. functions and not as a strict implementation guide. A formal scheme
  1592. for the translation of extended syntax to Standard LISP is presented
  1593. to eliminate misinterpretation of the definitions.
  1594. \subsection{Definition}
  1595. The goal of the transformation scheme is to produce a PUTD invocation
  1596. which has the function translated from the extended syntax as its
  1597. actual parameter. A rule has a name in brackets
  1598. \s{\ldots} by which it is known and is defined by what follows the meta
  1599. symbol ::=. Each rule of the set consists of one or more
  1600. ``alternatives'' separated by the $\mid$ meta symbol, being the
  1601. different ways in which the rule will be matched by source text. Each
  1602. alternative is composed of a ``recognizer'' and a ``generator''
  1603. separated by the $\Longrightarrow$ meta symbol. The recognizer is a
  1604. concatenation of any of three different forms. 1) Terminals - Upper
  1605. case lexemes and punctuation which is not part of the meta syntax
  1606. represent items which must appear as is in the source text for the
  1607. rule to succeed. 2) Rules - Lower case lexemes enclosed in \s{\ldots}
  1608. are names of other rules. The source text is matched if the named
  1609. rule succeeds. 3) Primitives - Lower case singletons not in brackets
  1610. are names of primitives or primitive classes of Standard LISP. The
  1611. syntax and semantics of the primitives are given in Part I.
  1612. The recognizer portion of the following rule matches an extended
  1613. syntax procedure:
  1614. \s{function} ::= ftype PROCEDURE id (\s{id list}); \\
  1615. \hspace*{2em} \s{statement}; $\Longrightarrow$
  1616. A function is recognized as an ``ftype'' (one of the tokens EXPR,
  1617. FEXPR, etc.) followed by the keyword PROCEDURE, followed by an ``id''
  1618. (the name of the function), followed by an \s{id list} (the formal
  1619. parameter names) enclosed in parentheses. A semicolon terminates the
  1620. title line. The body of the function is a
  1621. \s{statement} followed by a semicolon. For example:
  1622. \begin{verbatim}
  1623. EXPR PROCEDURE NULL(X); EQ(X, NIL);
  1624. \end{verbatim}
  1625. \noindent satisfies the recognizer, causes the generator to be activated and
  1626. the rule to be matched successfully.
  1627. The generator is a template into which generated items are
  1628. substituted. The three syntactic entities have corresponding meanings
  1629. when they appear in the generator portion. 1) Terminals - These
  1630. lexemes are copied as is to the generated text. 2) Rules - If a rule
  1631. has succeeded in the recognizer section then the value of the rule is
  1632. the result of the generator portion of that rule. 3) Primitives -
  1633. When primitives are matched the primitive lexeme replaces its
  1634. occurrence in the generator.
  1635. If more than one occurrence of an item would cause ambiguity in the
  1636. generator portion this entity appears with a bracketed subscript.
  1637. Thus:
  1638. \begin{tabbing}
  1639. \s{conditional} ::= \\
  1640. \hspace*{2em} IF \s{expression} \= THEN \s{statement$_1$} \\
  1641. \> ELSE \s{statement$_2$} \ldots
  1642. \end{tabbing}
  1643. \noindent has occurrences of two different \s{statement}s. The generator
  1644. portion uses the subscripted entities to reference the proper
  1645. generated value.
  1646. The \s{function} rule appears in its entirety as:
  1647. \begin{tabbing}
  1648. \s{function} ::= ftype PROCEDURE id (\s{id list});\s{statement};
  1649. $\Longrightarrow$ \\
  1650. \hspace*{2em} \=(PUTD \= (QUOTE id) \\
  1651. \> \> (QUOTE ftype) \\
  1652. \> \>(QUOTE (LAMBDA (\s{id list}) \s{statement})))
  1653. \end{tabbing}
  1654. If the recognizer succeeds (as it would in the case of the NULL
  1655. procedure example) the generator returns:
  1656. \begin{verbatim}
  1657. (PUTD (QUOTE NULL) (QUOTE EXPR) (QUOTE (LAMBDA (X) (EQ X NIL))))
  1658. \end{verbatim}
  1659. The identifier in the template is replaced by the procedure name NULL,
  1660. \s{id list} by the single formal parameter X, the \s{statement} by (EQ
  1661. X NIL) which is the result of the \s{statement} generator. EXPR
  1662. replaces ftype, the type of the defined procedure.
  1663. \subsection{The Extended Syntax Rules}
  1664. \begin{tabbing}
  1665. \s{function} ::= ftype \k{PROCEDURE} id (\s{id list}); \s{statement};
  1666. $\Longrightarrow$ \\
  1667. \hspace*{2em} \= (PUTD \= (QUOTE id) \\
  1668. \> \> (QUOTE ftype) \\
  1669. \> \> (QUOTE (LAMBDA (\s{id list}) \s{statement}))) \\ \\
  1670. \s{id list} ::= id $\Longrightarrow$ id $\mid$ \\
  1671. \> id, \s{id list} $\Longrightarrow$ id \s{id list} $\mid$ \\
  1672. \> $\Longrightarrow$ NIL \\
  1673. \s{statement} ::= \s{expression} $\Longrightarrow$ \s{expression} $\mid$ \\
  1674. \> \s{proper statement} $\Longrightarrow$ \s{proper statement} \\ \\
  1675. \s{proper statement} ::= \\
  1676. \> \s{assignment statement} $\Longrightarrow$ \s{assignment statement}
  1677. $\mid$ \\
  1678. \> \s{conditional statement} $\Longrightarrow$ \s{conditional statement}
  1679. $\mid$ \\
  1680. \> \s{while statement} $\Longrightarrow$ \s{while statement} $\mid$ \\
  1681. \> \s{compound statement} $\Longrightarrow$ \s{compound statement} \\ \\
  1682. \s{assignment statement} ::= id := \s{expression} $\Longrightarrow$ \\
  1683. \> \> (SETQ id \s{expression}) \\ \\
  1684. \s{conditional statement} ::= \\
  1685. \> \k{IF} \s{expression} \k{THEN} \s{statement$_1$} \k{ELSE}
  1686. \s{statement$_2$} $\Longrightarrow$ \\
  1687. \> \hspace{2em} \= (COND (\s{expression} \s{statement$_1$})(T
  1688. \s{statement$_2$})) $\mid$ \\
  1689. \> \k{IF} \s{expression} \k{THEN} \s{statement} $\Longrightarrow$ \\
  1690. \> \> (COND (\s{expression} \s{statement})) \\ \\
  1691. \s{while statement} ::= \k{WHILE} \s{expression} \k{DO} \s{statement}
  1692. $\Longrightarrow$ \\
  1693. \> \> (PROG NIL \\
  1694. \> \> LBL \= (COND ((NULL \s{expression}) (RETURN NIL))) \\
  1695. \> \> \> \s{statement} \\
  1696. \> \> \> (GO LBL)) \\ \\
  1697. \s{compound statement} ::= \\
  1698. \> \k{BEGIN} \k{SCALAR} \s{id list}; \s{program list} \k{END}
  1699. $\Longrightarrow$ \\
  1700. \> \> (PROG (\s{id list}) \s{program list}) $\mid$ \\
  1701. \> \k{BEGIN} \s{program list} \k{END} $\Longrightarrow$ \\
  1702. \> \> (PROG NIL \s{program list}) $\mid$ \\
  1703. \> \k{$<<$} \s{statement list} \k{$>>$} $\Longrightarrow$ (PROGN
  1704. \s{statement list}) \\ \\
  1705. \s{program list} ::= \s{full statement} $\Longrightarrow$ \s{full statement}
  1706. $\mid$ \\
  1707. \> \s{full statement} \s{program list} $\Longrightarrow$ \\
  1708. \> \> \s{full statement} \s{program list} \\ \\
  1709. \s{full statement} ::= \s{statement} $\Longrightarrow$ \s{statement} $\mid$
  1710. id: $\Longrightarrow$ id \\ \\
  1711. \s{statement list} ::= \s{statement} $\Longrightarrow$ \s{statement} $\mid$ \\
  1712. \> \s{statement}; \s{statement list} $\Longrightarrow$ \\
  1713. \> \> \s{statement} \s{statement list} \\ \\
  1714. \s{expression} ::= \\
  1715. \> \s{expression$_1$} \k{.} \s{expression$_2$} $\Longrightarrow$ \\
  1716. \> \> (CONS \s{expression$_1$} \s{expression$_2$} $\mid$ \\
  1717. \> \s{expression$_1$} \k{=} \s{expression$_2$} $\Longrightarrow$ \\
  1718. \> \> (EQUAL \s{expression$_1$} \s{expression$_2$}) $\mid$ \\
  1719. \> \s{expression$_1$} \k{EQ} \s{expression$_2$} $\Longrightarrow$ \\
  1720. \> \> (EQ \s{expression$_1$} \s{expression$_2$}) $\mid$ \\
  1721. \> '\s{expression} $\Longrightarrow$ (QUOTE \s{expression}) $\mid$ \\
  1722. \> function \s{expression} $\Longrightarrow$ (function \s{expression})
  1723. $\mid$ \\
  1724. \> function(\s{argument list}) $\Longrightarrow$ (function \s{argument list})
  1725. $\mid$ \\
  1726. \> number $\Longrightarrow$ number $\mid$ \\
  1727. \> id $\Longrightarrow$ id \\ \\
  1728. \s{argument list} ::= () $\Longrightarrow$ $\mid$ \\
  1729. \> \s{expression} $\Longrightarrow$ \s{expression} $\mid$ \\
  1730. \> \s{expression}, \s{argument list} $\Longrightarrow$ \s{expression}
  1731. \s{argument list}
  1732. \end{tabbing}
  1733. Notice the three infix operators . EQ and = which are translated into
  1734. calls on CONS, EQ, and EQUAL respectively. Note also that a call on a
  1735. function which has no formal parameters must have () as an argument
  1736. list. The QUOTE function is abbreviated by '.
  1737. \bibliography{sl}
  1738. \bibliographystyle{plain}
  1739. \end{document}
  1740.