sl.tex 87 KB

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