vslfunctions.tex 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981
  1. \begin{description}
  2. \item[{\tx !\$eof!\$~~~~~~} \hspace{1cm} {\em predefined variable}]\index{"!\$eof"!\$}~\newline
  3. When the {\tx read} function (or its relatives) detect and end of file
  4. condition it returns this value of this variable. So a code fragment such as
  5. {\tx (eq (setq x (read)) !\$eof!\$))} will read a Lisp expression,
  6. store it in a variable called {\tx x} and test if it was in fact
  7. an end of file marker.
  8. \item[{\tx !\$eol!\$~~~~~~} \hspace{1cm} {\em predefined variable}]\index{"!\$eol"!\$}~\newline
  9. This value of this predefined variable is a newline character, so if you
  10. use {\tx readch} it may be convenient to compare the result against this.
  11. See {\tx blank}, {\tx lpar} and {\tx rpar} for other character values where
  12. it is convenient to have a name rather than needing to enter the (escaped)
  13. character directly.
  14. \item[{\tx !*echo~~~~~~~} \hspace{1cm} {\em variable}]\index{"!*echo}~\newline
  15. When Lisp reads in any input the variable {\tx !*echo} is inspected. If
  16. its value is non-nil then the characters that are read get echoed to the
  17. current Lisp output stream. This is often useful when reading from a file. But
  18. often if you are accepting input in an interactive manner from the keyboard
  19. you would prefer {\tx !*echo} to be {\tx nil}. So \vsl{} arranges that if
  20. it is started up with a file to read specified on its command line it
  21. makes {\tx echo} default to {\tx t}, while if no command-line arguments are
  22. given it defaults to \nil. This often results in comfortable behaviour, but
  23. the user is free to set the variable explicity at any time to make things
  24. fit their needs.
  25. \item[{\tx !,~~~~~~~~~~~} \hspace{1cm} {\em marker}]\index{", (comma)}~\newline
  26. See the backquote entry.
  27. \item[{\tx !,!@~~~~~~~~~} \hspace{1cm} {\em marker}]\index{","@ (comma-at)}~\newline
  28. See the backquote entry.
  29. \item[{\tx `~~~~~~~~~~~~} \hspace{1cm} {\em marker}]\index{{\tx `} (backquote)}~\newline
  30. Lisp input can contain an ordinary Lisp expression preceeded by a backquote
  31. mark. Within the expression various sub-parts can be marked with
  32. either a comma, or a comma followed by an ``at'' sign. This notation is
  33. commonly used when defining Lisp macros. The effect is as if a longer
  34. segment of Lisp had been written to create a structures that is the same
  35. shape as the one given, but with the comma-introduced sub-parts expanded.
  36. This may be shown with an example. The form {\tx `(a ,b c ,(car d))}
  37. might behave like {\tx (list 'a b 'c (car d))}. The rules for backquote
  38. do not guarantee exactly what expansion will be generated -- just that when
  39. it is executed it will construct the required structure. In \vsl{} the code
  40. will in fact use many calls to {\tx cons} rather than the neat use of
  41. {\tx list} shown here. An embedded ``{\tx ,@}'' within a backquoted
  42. expression is expected to stand for a list, whose values are spliced into
  43. the evantual result. This {\tx `(a ,@(car b) c)} might expand as
  44. {\tx (append '(a) (append (car b) '(c)))}. In many some Lisp
  45. systems the full expansion is performed while reading the input. In \vsl{} the
  46. reader leaves backquote and comma markers in the structure it returns, and
  47. macros expand those when it is time to execute them.
  48. \item[{\tx add1~~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{add1}~\newline
  49. {\tx (add1 n)} is merely a shorthand for {\tx (plus n 1)}, in
  50. other words it adds one to its argument. It is often useful when counting. See
  51. alse {\tx sub1}.
  52. \item[{\tx and~~~~~~~~~~} \hspace{1cm} {\em function n args}]\index{and}~\newline
  53. In \vsl{} {\tx and} is implemented as a special form. If evaluates its
  54. arguments one at a time, and returns \nil{} if one of them evaluates
  55. to \nil. If none of them yield \nil{} its value if the value of the final
  56. argument. If you interpret \nil{} as {\em false} and anything else as
  57. {\em true} then this matches a simple understanding of the of an operation that
  58. could reasonably called {\tx and}. See also {\tx or}.
  59. A different way of explaining {\tx and} would be to give an
  60. equivalence: {\tx (and a b c)} could be replaced by
  61. {\tx (if a (if b c nil) nil)}, with similar expansion for cases with
  62. larger or smaller number of arguments. In \vsl{} {\tx (and)} (ie without
  63. any arguments) yields {\tx t}.
  64. \item[{\tx append~~~~~~~} \hspace{1cm} {\em function 2 args}]\index{append}~\newline
  65. If you have two lists then {\tx append} can form their concatenation.
  66. So {\tx (append '(a b) '(c d))} yields {\tx (a b c d)}. The
  67. result will share structure with the second argument -- a fact that only
  68. matters if you later use {\tx rplaca} or {\tx rplacd}. Some
  69. other Lisps may permit you to give {\tx append} more than two arguments,
  70. and will then append all the lists into one, but \vsl{} does not.
  71. \item[{\tx apply~~~~~~~~} \hspace{1cm} {\em function 2 args}]\index{apply}~\newline
  72. If you have either the name of a function or a lambda-expression (see
  73. {\tx lambda} for more explanation) you can call it on a collection of
  74. arguments that are provided in a list. The function {\tx apply} that
  75. does this is really there just because its capability has to be part of the
  76. Lisp interpreter. For instance since {\tx cons} takes just two
  77. arguments you could invoke it by giving the symbol {\tx cons} as
  78. {\tx apply}'s first argument and a list of length two as its second:
  79. {\tx (apply 'cons '(a b))}. This would return {\tx (a . b)}.
  80. If the first argument to {\tx apply} is a macro rather than an ordinary
  81. function this can be used to perform macro expansion. You should not
  82. try using {\tx apply} on a special form ({\tx fsubr}).
  83. \item[{\tx assoc~~~~~~~~} \hspace{1cm} {\em function 2 args}]\index{assoc}~\newline
  84. An association list is a list of pairs, and each pair ({\tx cons}) is
  85. though of as constisting of a key and a value. {\tx assoc} searches
  86. an association list looking for a given key. If it find it then it returns
  87. the pair that contains it. Othewise it returns \nil. Thus
  88. {\tx (assoc 'b '((a . 1) (b . 2) (c . 3)))} will return
  89. {\tx (b . 2)}. The test for keys is make using the {\tx equal}
  90. function.
  91. \item[{\tx atan~~~~~~~~~} \hspace{1cm} {\em special form}]\index{atan}~\newline
  92. The arctangent function, working in radians. See {\tx sin} and {\tx cos}.
  93. \item[{\tx atom~~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{atom}~\newline
  94. Any Lisp object that is not a list or a pair -- that is to say that could
  95. not have been created by the {\tx cons} function, is known as an {\em atom}.
  96. Thus symbols, numbers, strings and vectors are all atoms. The function
  97. {\tx atom} checks its argument and returns {\tx t} (for {\em true})
  98. if it is atomic and \nil{} otherwise.
  99. \item[{\tx blank~~~~~~~~} \hspace{1cm} {\em predefined variable}]\index{blank}~\newline
  100. A predefined variable whose value is the symbol whose name is a single
  101. space character. One could otherwise refer to that symbol by writing
  102. {\tx '!\textvisiblespace}, but many people find writing the
  103. word {\tx blank} makes things clearer because it does not involve
  104. having a significant but non-printing character.
  105. \item[{\tx caaar~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{caaar}~\newline
  106. A range of names of the form {\tx c}{\em xxx}{\tx r} with the
  107. intermediate letters being either {\tx a} or {\tx d} are
  108. provided as functions that are merely combinations of uses of {\tx car}
  109. and {\tx cdr}. Thus {\tx (caaar x)} means just the same
  110. as {\tx (car (car (car x)))}, and {\tx (caddr x)} means
  111. {\tx (car (cdr (cdr x)))}. In \vsl{} these are provided for up to three
  112. intermediate letters.
  113. \item[{\tx caadr~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{caadr}~\newline
  114. See {\tx caaar}.
  115. \item[{\tx caar~~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{caar}~\newline
  116. See {\tx caaar}.
  117. \item[{\tx cadar~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{cadar}~\newline
  118. See {\tx caaar}.
  119. \item[{\tx caddr~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{caddr}~\newline
  120. See {\tx caaar}. Can be though of as returning the third item in a list.
  121. \item[{\tx cadr~~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{cadr}~\newline
  122. See {\tx caaar}. Can be though of as returning the second item in a list.
  123. \item[{\tx car~~~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{car}~\newline
  124. Data structures in Lisp are made up with the various sorts of atom (symbols,
  125. numbers, strings and so on) as basic elements and with {\tx cons} cells
  126. used to build them up into potentially large and complicated lists and trees.
  127. If you think of a structure as a list then {\tx car} extracts its first
  128. element (and {\tx cdr} its tail). If you think of it as a binary
  129. tree then {\tx car} gets the left part and {\tx cdr} the right.
  130. The basic identity is that {\tx (car (cons a b))} = {\tx a}.
  131. See also {\tx cdr}.
  132. \item[{\tx cdaar~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{cdaar}~\newline
  133. See {\tx caaar}.
  134. \item[{\tx cdadr~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{cdadr}~\newline
  135. See {\tx caaar}.
  136. \item[{\tx cdar~~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{cdar}~\newline
  137. See {\tx caaar}.
  138. \item[{\tx cddar~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{cddar}~\newline
  139. See {\tx caaar}.
  140. \item[{\tx cdddr~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{cdddr}~\newline
  141. See {\tx caaar}.
  142. \item[{\tx cddr~~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{cddr}~\newline
  143. See {\tx caaar}.
  144. \item[{\tx cdr~~~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{cdr}~\newline
  145. {\tx (cdr (cons a b))} = {\tx b}. See {\tx car}.
  146. \item[{\tx char!-code~~~} \hspace{1cm} {\em function 1 arg}]\index{char"!-code}~\newline
  147. If you have a symbol or a string denoting a single character then the function
  148. {\tx char!-code} will return a numeric code for it. The code used in
  149. \vsl{} is ASCII so for instance the code for a blank character is 32, that for
  150. the digit ``0'' is 46 and a capital ``A'' is 65. See {\tx code!-char} for
  151. conversion in the other direction.
  152. \item[{\tx close~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{close}~\newline
  153. When an input file has been opened for reading or writing you should
  154. use {\tx close} it once finished with it. This is especially important
  155. for output files because it could be that some material will remain
  156. buffered and so will not be written until the file is closed. See {\tx open}.
  157. \item[{\tx code!-char~~~} \hspace{1cm} {\em function 1 arg}]\index{code"!-char}~\newline
  158. {\tx (code!-char 97)} would return a symbol whose name is the character
  159. with code 97 (in this case a lower case ``a''). Similarly for other codes
  160. typically in the range 0 to 255.
  161. \item[{\tx compress~~~~~} \hspace{1cm} {\em function 1 arg}]\index{compress}~\newline
  162. If you have a list of identifiers or strings then {\tx compress} treats each
  163. as standing for its first character and returns the Lisp expression you would
  164. get if ytou read from a document that contained those characters. This
  165. would normally be used when each item in the input list was just a single
  166. character. Because in \vsl{} the {\tx compress} function is implemented by
  167. just involing {\tx read} with input redirected from the list you can create
  168. symbols, numbers, strings and even lists this way. See {\tx explode}.
  169. \item[{\tx cond~~~~~~~~~} \hspace{1cm} {\em special form}]\index{cond}~\newline
  170. The primitive comditional operator in Lisp is {\tx cond}. It is a special
  171. form (i.e.\ it does not evaluate its arguments in the standard way. Its use is
  172. as in
  173. {\sverb
  174. (cond
  175. (p1 e1a e1b e1c ...)
  176. (p2 e2a e2b ...)
  177. ...
  178. \end{verbatim}}
  179. \noindent where {\tx p1}, {\tx p2} etc.\ are predicates, and the sequence of
  180. expressions (for instance {\tx e1a\ldots}) that follow the first one that yields
  181. a non-\nil{} value are computed. The result returned is the final thing that
  182. {\tx cond} evaluates. There are many examples of uses of {\tx cond} in the
  183. sample code here. Some people prefer to use {\tx if} or {\tx when} instead,
  184. but at least historically {\tx cond} came first.
  185. \item[{\tx cons~~~~~~~~~} \hspace{1cm} {\em function 2 args}]\index{cons}~\newline
  186. Lisp data is based on lists and trees, and {\tx cons} is the key function
  187. for creating them. The term {\tx cons}-cell is used for the object that
  188. the function creates. Such a cell has two componente, is {\tx car} and
  189. its {\tx cdr}. The apparently strange names for these related to the
  190. atchitecture of an early computer on which Lisp was first developed.
  191. If you have a list structure {\tx l} and an item {\tx a} then
  192. {\tx (cons a l)} is a list just one element longer than {\tx l} was formed
  193. by putting {\tx a} in front of the original. In Lisp it is much more
  194. expensive to attach a new item to the tail of a list. To do that
  195. would typically involve {\tx (append l (list a))} and especially if {\tx l}
  196. was long could be slow. So in Lisp it is normal to build up lists by
  197. succesively addint items to the head using {\tx cons}. See also {\tx car},
  198. {\tx cdr} and {\tx list}.
  199. \item[{\tx copy~~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{copy}~\newline
  200. It is normally only necessary (or indeed useful) to make a copy of a Lisp
  201. structure if you are then about to use destructive operations such as
  202. {\tx rplaca} on the original, but this function is provided in case you
  203. do ever need to.
  204. \item[{\tx cos~~~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{cos}~\newline
  205. It would be easy to extend the \vsl{} implementation to provide a full set
  206. of mathematical functions, but to keep things small the initial version only
  207. provides a few key cases: {\tx sin}, {\tx cos}, {\tx atan},
  208. {\tx exp}, {\tx log} and {\tx sqrt}. Each of these can be given
  209. either an integer or floating point argument but they always return a floating
  210. point result. The trigonometric functions work in radians rather than
  211. degrees.
  212. \item[{\tx de~~~~~~~~~~~} \hspace{1cm} {\em special form}]\index{de}~\newline
  213. To define a new function evaluate {\tx (de name arglist body)}, the special
  214. form that is provided for this purpose. After you have defined something
  215. you could retrieve the definition you had set up using {\tx (getd 'name)}.
  216. \item[{\tx deflist~~~~~~} \hspace{1cm} {\em function 2 args}]\index{deflist}~\newline
  217. Sometimes when setting up data you need to perform a succession of
  218. {\tx put} operations all using the same property name. {\tx deflist} provides
  219. a short-cut so you can write something like
  220. {\sverb
  221. (deflist
  222. '((a A)
  223. (b B)
  224. (c C))
  225. 'propname)
  226. \end{verbatim}}
  227. \noindent and have the same effect as
  228. {\sverb
  229. (put 'a 'propname 'A)
  230. (put 'b 'propname 'B)
  231. (put 'c 'propname 'C)
  232. \end{verbatim}}
  233. \item[{\tx df~~~~~~~~~~~} \hspace{1cm} {\em special form}]\index{df}~\newline
  234. {\tx df} is rather like {\tx de} except that it allows you to defined a new
  235. special form. A special form must be defined as if it has just one
  236. argument, and this will receive the whole of the ``argument'' information from
  237. any call without any evaluation having happened. Often the body of a special
  238. form will thus wish to use {\tx eval} to make evaluation happen. In most
  239. Lisp programs it will be unusual to introduce new special forms. See also
  240. {\tx dm} for an alternative way (also sometimes controversial)
  241. for extending the syntax of Lisp.
  242. \item[{\tx difference~~~} \hspace{1cm} {\em function 2 args}]\index{difference}~\newline
  243. Subtract one number from another. If either value is floating point the
  244. result will be floating point.
  245. \item[{\tx divide~~~~~~~} \hspace{1cm} {\em function 2 args}]\index{divide}~\newline
  246. Divide one integer from another and return the {\tx cons} of the quotient and
  247. remainder. The idea behind this function was that when integers are divided
  248. it is common to require both quotient and remainder, so having a one function
  249. to return both might be helpful. In Lisp systems that support very high
  250. precision arithmetic this can indeed save time. In \vsl{} you will probably
  251. do as well calling {\tx quotient} and then {\tx remainder}.
  252. \item[{\tx dm~~~~~~~~~~~} \hspace{1cm} {\em special form}]\index{dm}~\newline
  253. A Lisp Macro is something that when evaluated produces futher executable
  254. Lisp to be its replacement.
  255. The special
  256. form introduced by {\tx dm} can defined a new one. In general it will be
  257. sensible to define macros before you define any functions that use them.
  258. Some people believe that extensive use of macros can make your code harder
  259. to read and debug, and so would rather you did not use them at all.
  260. \item[{\tx do~~~~~~~~~~~} \hspace{1cm} {\em macro}]\index{do}~\newline
  261. A perhaps over-general form of loop can be specified by the {\tx do} macro
  262. or its close cousin {\tx do!*}. The structure of aan invocation of it is
  263. {\sverb
  264. (do ((var1 init1 step1)
  265. (var2 init2 step2)
  266. ..)
  267. (endtest result ...)
  268. body
  269. ...)
  270. \end{verbatim}}
  271. \noindent and a concrete exammple is
  272. {\sverb
  273. (do ((x 10 (add1 x)))
  274. ((greaterp x 20) 'done)
  275. (print (list x (times x x))))
  276. \end{verbatim}}
  277. The difference between {\tx do} and {\tx do!*} is that the former processes
  278. all its initialisation and update of variables in parallel, while the latter
  279. acts sequentially. This is similar to the relationship between {\tx let} and
  280. {\tx let!*}.
  281. \item[{\tx do!*~~~~~~~~~} \hspace{1cm} {\em macro}]\index{do"!*}~\newline
  282. See {\tx do}.
  283. \item[{\tx dolist~~~~~~~} \hspace{1cm} {\em macro}]\index{dolist}~\newline
  284. Simple iteration over a lisp can be performed using the {\tx dolist} macro,
  285. where a typical tiny example might be
  286. {\sverb
  287. (dolist (x '(1 2 3) 'result) (print x))
  288. \end{verbatim}}
  289. \noindent which prints the numbers 1, 2 and 3 and then returns the
  290. value {\tx result}. In many cases you will merely omit the result part of the
  291. expression and then {\tx dolist} will return \nil.
  292. \item[{\tx dollar~~~~~~~} \hspace{1cm} {\em predefined variable}]\index{dollar}~\newline
  293. A predefined variable whose value is the symbol whose name is a dollar
  294. character. See {\tx blank} for another similarly predefined name.
  295. \item[{\tx dotimes~~~~~~} \hspace{1cm} {\em macro}]\index{dotimes}~\newline
  296. Counting is easy with {\tx dotimes}. It starts from zero, so
  297. {\sverb
  298. (dotimes (x 5 'result) (print x))
  299. \end{verbatim}}
  300. \noindent will print values 0, 1, 2, 3 and 4 before returning {\tx result}.
  301. \item[{\tx eq~~~~~~~~~~~} \hspace{1cm} {\em function 2 args}]\index{eq}~\newline
  302. If you wish to test two Lisp items for absolute identity then {\tx eq} is the
  303. function to use. If you enter the same spelling for a symbol twice Lisp arranges
  304. that you get the same symbol, but it is possible -- even probable -- that strings
  305. or large numbers can fail to be {\tx eq} even if they look the same. Two list
  306. structures are {\tx eq} only if their top-level {\tx cons} cells are identical
  307. in the sense that even if you received them via different paths they are the
  308. output from the same call to {\tx cons}. See {\tx equal} for a more
  309. expensive but perhaps more generous equality test.
  310. \item[{\tx eqcar~~~~~~~~} \hspace{1cm} {\em function 2 args}]\index{eqcar}~\newline
  311. {\tx (excar a b)} is like {\tx (and (not (atom a)) (eq (car a) b))}.
  312. \item[{\tx equal~~~~~~~~} \hspace{1cm} {\em function 2 args}]\index{equal}~\newline
  313. Wile {\tx eq} compares objects for absolute identity, {\tx equal} compares
  314. them to see if they have the same structure. {\tx equal} understands how to
  315. compare big and floating point numbers, strings and vectors as well as
  316. lists. To illustrate the difference between the two functions consider
  317. {\begin{verbatim}
  318. (setq a (cons 1 1000000000))
  319. (setq b (cons 1 1000000000))
  320. (eq a b)
  321. (equal a b)
  322. (eq (cdr a) (cdr b))
  323. (equal (cdr a) (cdr b))
  324. \end{verbatim}}
  325. In each case {\tx eq} returns \nil{} wiile {\tx equal} will return {\tx t}.
  326. Although you should not in general rely on {\tx eq} when comparing numbers,
  327. in \vsl{} all small numbers are represented in a way that will allow {\tx eq}
  328. to handle them reliably. If \vsl{} is runing on a 32-bit system the
  329. range is -268435456 to 268435455. If the system had been built for a 64-bit
  330. machine it is much larger.
  331. \item[{\tx error~~~~~~~~} \hspace{1cm} {\em function 2 args}]\index{error}~\newline
  332. If a user wants to report that something has gone wrong it can call the
  333. {\tx error} function. This is given two arguments, and they will be displayed
  334. in any message that is printed. See {\tx errorset} for information about how
  335. to control the amount of information displayed when an error occurs.
  336. \item[{\tx errorset~~~~~} \hspace{1cm} {\em function 3 args}]\index{errorset}~\newline
  337. The default situation is that when \vsl{} encounters and error it unwinds
  338. from whatever it was doing and awaits the next item of input from the user.
  339. The function {\tx errorset} can be used to trap errors so that a program can
  340. respond or continue in its own way. It can also control how much diagnostic
  341. output is generated. A call {\tx (errorset form msg trace)} will evaluate
  342. the Lisp expression {\tx form} rather in the way that {\tx eval} would have.
  343. If there is no error it returns a list of length one whose element is the
  344. value that was computed. If the evaluation of {\tx form} failed then
  345. {\tx errorset} returns an atom rather than a list, so its caller can be
  346. aware of the situation. The argument {\tx msg} can be non-\nil{} to indicate
  347. that a short (typically one line) report is displayed on any error. If
  348. {\tx trace} is non-nil then a report showing the nesting of function calls
  349. will also be shown. If both arguments are \nil{} then the error and recovery
  350. from it should be silent. See {\tx eval} for a sample use.
  351. \item[{\tx eval~~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{eval}~\newline
  352. An approximation to how Lisp interacts with the user is
  353. {\sverb
  354. (while t
  355. (errorset '(print (eval (read))) t t))
  356. \end{verbatim}}
  357. \noindent where {\tx eval} takes whatever form was read and evaluates it. The
  358. {\tx eval} function (and its relative {\tx apply}) can be used anywhere in Lisp
  359. code where a data structure needs to be interpreted as a bit of Lisp code and
  360. obeyed.
  361. \item[{\tx exp~~~~~~~~~~} \hspace{1cm} {\em special form}]\index{exp}~\newline
  362. The exponential function. See {\tx log}.
  363. \item[{\tx expand~~~~~~~} \hspace{1cm} {\em function 2 args}]\index{expand}~\newline
  364. In some Lisp implementations it would be useful (for instance for efficiency)
  365. to transform some uses of functions taking an indefinite number of arguments
  366. (for instance {\tx plus}) into sequences of calls to versions taking just
  367. two arguments. The {\tx expand} function is intended to help with this. Its
  368. first argument is a list of expressions, the second a (two argument) function
  369. to be used to combine them. For instance {\tx (expand '(a b c) 'plus2)} will
  370. yield {\tx (plus2 a (plus2 b c))}. This could be useful if {\tx plus} were
  371. to have been implemented as a macro expanding to multiple uses of {\tx plus2}
  372. rather than as a special form, and if \vsl{} provided the two-argument
  373. function concerned (which at present it does not!).
  374. \item[{\tx explode~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{explode}~\newline
  375. Any Lisp item can be processes as by {\tx prin} but with the resulting sequence
  376. of characters being collected as a list rather than being printed directly.
  377. {\tx explode} does this, while {\tx explodec} behaves like {\tx princ}. So
  378. {\tx (explode '("a" . 3))} will be {\tx (!( !" a !" ! !. ! !3 !))}.
  379. {\tx explode} can be useful to find the sequence of letters making up the name
  380. of a symbol (or just to make it possible to see how many there are).
  381. \item[{\tx explodec~~~~~} \hspace{1cm} {\em function 1 arg}]\index{explodec}~\newline
  382. See {\tx explode}
  383. \item[{\tx expr~~~~~~~~~} \hspace{1cm} {\em symbol}]\index{expr}~\newline
  384. The function {\tx getd} can retrieve the function definition (if any) associated
  385. with a symbol. The value returned is {\tx (type . value)} where the {\tx type}
  386. is one of the symbols {\tx expr}, {\tx subr}, {\tx fexpr}, {\tx fsubr} or
  387. {\tx macrp}. The case {\tx expr} indicates that the function is a normal-style
  388. function that has been defined in Lisp. The value information following it
  389. in the result of {\tx getd} is the Lisp structure representing it. {\tx fexpr}
  390. is for special forms defined in Lisp (using {\tx df}. {\tx subr} and {\tx fsubr}
  391. and ordinary and special functions that have been defined at a lower level than
  392. Lisp (in other words things that form part ofthe \vsl{} kernel). {\tx macro}
  393. marks a macro as defined using {\tx dm}. With the default
  394. \vsl{} image {\tx (getd 'caar)} returns {\tx (expr lambda (x) (car (car x)))}.
  395. \item[{\tx f~~~~~~~~~~~~} \hspace{1cm} {\em predefined variable}]\index{f}~\newline
  396. {\tx f} is a variable pre-set to have the value \nil. This exists because at
  397. one stage people tended to want to use {\tx t} for {\em true} and {\tx f}
  398. for {\em false}. In most cases it will be safer to use \nil{} directly if that
  399. is what you mean, and attempts to use {\tx f} as a definitive denotation
  400. of {\em false} cause trouble when you try using the name as an ordinary variable,
  401. as in {\tx (de fff (a b c d e f g) \ldots)}.
  402. \item[{\tx fexpr~~~~~~~~} \hspace{1cm} {\em symbol}]\index{fexpr}~\newline
  403. See {\tx expr}.
  404. \item[{\tx fix~~~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{fix}~\newline
  405. If you have a floating point number and want convert it to an integer you can
  406. use the function {\tx fix}. It truncates the value towards zero while
  407. doing the conversion.
  408. \item[{\tx fixp~~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{fixp}~\newline
  409. The predicate {\tx fixp} tests if its argument is an integer, and if it is
  410. it returns {\tx t}. See also {\tx numberp} and {\tx floatp}. You are
  411. permitted to test any Lisp object using {\tx fixp} and note that
  412. {\tx (fixp 2.0)} will be \nil{} because 2.0 is a floating point number even
  413. if its value is an integer.
  414. \item[{\tx float~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{float}~\newline
  415. Converts from an integer to a floating point number.
  416. \item[{\tx floatp~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{floatp}~\newline
  417. Test if an object is a floating point number. See {\tx fixp}.
  418. \item[{\tx fsubr~~~~~~~~} \hspace{1cm} {\em symbol}]\index{fsubr}~\newline
  419. See {\tx expr}.
  420. \item[{\tx gensym~~~~~~~} \hspace{1cm} {\em function 0 args}]\index{gensym}~\newline
  421. Sometime in a Lisp program you need a new sybol. One that is certain not to
  422. clash with any others you may have used already. {\tx (gensym)} will create
  423. a fresh symbol for you. Such symbols should be though of as being anonymous.
  424. In \vsl{} they do not even have a name unless and until you print them. At
  425. that stage a name will be allocated, and it will be of one from the
  426. sequence {\tx g001}, {\tx g002},\ldots. However if you type in the characters
  427. {\tx g001} that will not refer to the generated symbol that was displayed
  428. that way -- you will get an ordinary symbol that you may confuse with the
  429. gensym but that Lisp will not.
  430. \item[{\tx geq~~~~~~~~~~} \hspace{1cm} {\em function 2 args}]\index{geq}~\newline
  431. This is a predicate that returns {\tx t} if its first argument is
  432. greater than or equal to its second. Both arguments must be numbers. See
  433. {\tx leq}, {\tx greaterp} and {\tx lessp}.
  434. \item[{\tx get~~~~~~~~~~} \hspace{1cm} {\em function 2 args}]\index{get}~\newline
  435. Every symbol has a property-list, which can be retrieved directly using
  436. {\tx plist}. The main functions for saving and retrieving information
  437. on property lists are {\tx put} and {\tx get}. After you have gone
  438. {\tx (put 'name 'tag 'value)} a call {\tx (get 'name 'tag)} will return {\tx
  439. value}. See also {\tx remprop}. An extended version of the library could define
  440. functions {\tx flag}, {\tx flagp} and {\tx remflag} to store flags rather
  441. then more general properties, but \vsl{} only supplies the basics.
  442. \item[{\tx getd~~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{getd}~\newline
  443. See {\tx expr}.
  444. \item[{\tx gethash~~~~~~} \hspace{1cm} {\em function 2 args}]\index{gethash}~\newline
  445. If {\tx h} is a hash table then {\tx (gethash 'key h)} retrieves the value
  446. stored in it under the indicated {\tx key} by some previous call to
  447. {\tx (puthash 'key h 'value)}. See {\tx mkhash}, {\tx puthash} and {\tx remhash}.
  448. \item[{\tx getv~~~~~~~~~} \hspace{1cm} {\em function 2 args}]\index{getv}~\newline
  449. If {tx v} is a vector then {\tx (getv v n)} returns the {\tx n}th element
  450. ot if. See {\tx mkvect}, {\tx putv} and {\tx upbv}.
  451. \item[{\tx go~~~~~~~~~~~} \hspace{1cm} {\em special form}]\index{go}~\newline
  452. See {\tx prog}.
  453. \item[{\tx greaterp~~~~~} \hspace{1cm} {\em function 2 args}]\index{greaterp}~\newline
  454. {\tx (greaterp x y)} is true if {\tx x} and {\tx y} are numbers with
  455. {\tx x} larger then {\tx y}. See {\tx geq}, {\tx lessp} and {\tx leq}.
  456. \item[{\tx if~~~~~~~~~~~} \hspace{1cm} {\em macro}]\index{if}~\newline
  457. The fundamental conditional form in Lisp is {\tx cons}, but for convenience
  458. the macros {\tx if} amd {\tx when} are supplied. {\tx if} takes two
  459. or three arguments. The first is a predicate -- the condition that
  460. is to be tested. The next is the value to return, while the last is the
  461. result required if the condition is {\em false} and defaults to \nil.
  462. {\tx when} also takes a predicate, but all its further arguments are things
  463. to be obeyed in sequence if the condition holds. Thus
  464. {\tx (when p a b c)} behaves like {\tx (if p (progn a b c) nil)}.
  465. \item[{\tx input~~~~~~~~} \hspace{1cm} {\em symbol}]\index{input}~\newline
  466. See {\tx open}.
  467. \item[{\tx lambda~~~~~~~} \hspace{1cm} {\em symbol}]\index{lambda}~\newline
  468. Some people will believe that {\tx lambda} is the key symbol standing for the
  469. essence of Lisp. Others view it as a slight curiosity mostly of interest
  470. to obsessive specialists. It introduces a notation for a function that does
  471. not require that the function be given a name. This is inspired by
  472. Alonzo Chruch's $\lambda$-calculus. The denotation of a function is a list
  473. with {\tx lambda} as its first element, then a list of its formal parameters,
  474. and finally a sequence of values that are to be evaluated when the function
  475. is invoked. So {\tx (lambda (x) (plus x 1))} is a function that adds one to
  476. its argument. If you try writing lambda expressions with bodies that refer to
  477. variables other than their formal arguments then you will need to read
  478. and understand the secion of this book that discusses deep and shallow
  479. binding strategies in an implementation of Lisp. This issue in fact arises
  480. with named functions defined using {\tx de} as well.
  481. \item[{\tx last~~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{last}~\newline
  482. If you have a list then {\tx last} can return the final element in it. Recall
  483. that the first item in a list can be extracted using {\tx car}, and note that
  484. {\tx last} is goig to be slower, so where possible arrange what you do so
  485. that you access the start of your lists more often than their ends.
  486. \item[{\tx lastcar~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{lastcar}~\newline
  487. This function is just like {\tx last} except that if {\tx last} is called on
  488. an empty list if reports an error, while {\tx lastcar} merely returns nil.
  489. \item[{\tx leftshift~~~~} \hspace{1cm} {\em function 2 args}]\index{leftshift}~\newline
  490. Take an integer value, treat it as a bit-pattern and shift that leftwards
  491. by the specified amount. Return the result as an integer. Generally
  492. {\tx (leftshift x $n$)} has the same effect as multiplying {\tx x} by
  493. $2^{n}$. See {\tx rightshift}.
  494. \item[{\tx length~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{length}~\newline
  495. This function returns the length of a list. If its argument is \nil{} it returns
  496. 0.
  497. \item[{\tx leq~~~~~~~~~~} \hspace{1cm} {\em function 2 args}]\index{leq}~\newline
  498. A test for ``less than or equal''. See {\tx geq}, {\tx greaterp} and {\tx lessp}.
  499. \item[{\tx lessp~~~~~~~~} \hspace{1cm} {\em function 2 args}]\index{lessp}~\newline
  500. A test for ``less then''. See {\tx geq}, {\tx greaterp} and {\tx leq}.
  501. \item[{\tx let~~~~~~~~~~} \hspace{1cm} {\em macro}]\index{let}~\newline
  502. Sometimes it is convenient to introduce a new name for some result you
  503. have just computed and are about to use. The {\tx let} macro provides
  504. a way to do this. So as an example where four temporary values are
  505. being introduced, consider
  506. {\sverb
  507. (let ((u (plus x y))
  508. (v (difference x y))
  509. (xx (times x x))
  510. (yy (times y y)))
  511. (list (difference xx yy)
  512. (times u v)))
  513. \end{verbatim}}
  514. In really old fashioned Lisp this would have been achieved using {\tx prog}
  515. as in
  516. {\sverb
  517. (prog (u v xx yy)
  518. (setq u (plus x y))
  519. (setq v (difference x y))
  520. ...
  521. (return (list (difference xx yy) ...)))
  522. \end{verbatim}}
  523. \noindent and yet another scheme would use an explicit lambda-expression
  524. {\sverb
  525. ((lambda (u v xx yy)
  526. (list (difference xx yy) (times u v)))
  527. (plus x y)
  528. (difference x y)
  529. (times x x)
  530. (times y y))
  531. \end{verbatim}}
  532. Of all these the version using {\tx let} is liable to be the clearest and
  533. neatest. Actually the versions using {\tx prog} and {\tx lambda} can
  534. have different behaviours sometimes. {\tx let}
  535. and {\tx lambda} introduce all their new variable simultaneously, and so the
  536. definition given for a later one can not depend on an earlier one. {\tx let!*}
  537. is like {\tx let} but introduces one variable at a time so that subsequent
  538. ones can depend on it, and that is closer to how the naive use of {\tx prog}
  539. would work. Thus
  540. {\sverb
  541. (let!* ((x2 (times x x))
  542. (x4 (times x2 x2))
  543. (x8 (times x4 x4)))
  544. (times x x4 x8))
  545. \end{verbatim}}
  546. \noindent returns the thirteenth power of {\tx x}, while if {\tx let} had
  547. been used rather than {\tx let!*} you would have received an error message
  548. about {\tx x2} being undefined that arose when it was used to define {\tx x4}.
  549. \item[{\tx let!*~~~~~~~~} \hspace{1cm} {\em macro}]\index{let"!*}~\newline
  550. ASee {\tx let}.
  551. \item[{\tx lispsystem!*~} \hspace{1cm} {\em predefined variable}]\index{lispsystem"!*}~\newline
  552. It is sometimes useful to allow Lisp code to adapt based on knowing
  553. something about the particular Lisp implementation it is running on. In
  554. Standard Lisp (and hence \vsl) environment information is provided in
  555. a predefined variables called {\tx lispsystem!*}. In \vsl{} the only information
  556. put there is a symbol \vsl{} to identify the Lisp system in use. But it would
  557. be easy to extent the code in {\tx vsl.c} to put in whatever extra information
  558. about the host computer anybody felt might be relevant.
  559. \item[{\tx list~~~~~~~~~} \hspace{1cm} {\em special form}]\index{list}~\newline
  560. The fundamental function for building Lisp data-structures is {\tx cons},
  561. but by convention a list is a chain of {\tx cons} cells ending with \nil.
  562. Created in the fundamental manner a list of length 4 might be
  563. built using {\tx (cons 'a (cons 'b (cons c (cons 'd nil))))}. That is correct
  564. but clumsy!. The special form {\tx list} accepts an arbitrary number of
  565. arguments and forms a list out of them: {\tx (list 'a 'b 'c 'd)}. It will
  566. therefore be common to use one call to {\tx list} in place of
  567. multiple uses of {\tx cons} whenever possible.
  568. \item[{\tx list!*~~~~~~~} \hspace{1cm} {\em special form}]\index{list"!*}~\newline
  569. The structures created using {\tx list} are always automatically provided
  570. with a \nil{} termination. Sometimes a list-like structure is
  571. wanted with some other end. This may arise for instance when putting
  572. multiple items onto the front of an existing list. The function {\tx list!*}
  573. can achieve this, and taking an example that puts 4 items ahead of the
  574. termination, the long-winded form
  575. {\tx (cons 'a (cons 'b (cons c (cons 'd 'e))))} could be replaced by the
  576. much more concise {\tx (list!* 'a 'b 'c 'd 'e)}. As a special case
  577. {\tx list!*} with just two arguments degenerates to being exactly the same
  578. as {\tx cons}.
  579. \item[{\tx log~~~~~~~~~~} \hspace{1cm} {\em special form}]\index{log}~\newline
  580. The (natural) logarithm of a value. See {\tx exp}.
  581. \item[{\tx logand~~~~~~~} \hspace{1cm} {\em special form}]\index{logand}~\newline
  582. If integers in Lisp are represented in binary form (and for those who want the
  583. full story, negative values in two's complement) then a number can be thought
  584. of as a string of bits. {\tx logand} takes an arbitrary number of integers
  585. and performs an logical ``and'' operation on each bit position, so that a ``1''
  586. is present in the output only all of the inputs have a ``1'' in that position.
  587. The result is returned as an integer. See also {\tx logor}, {\tx lognot}
  588. and {\tx logxor} for operations, and {\tx leftshift} and {\tx rightshift}
  589. for re-aligning bits.
  590. \item[{\tx lognot~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{lognot}~\newline
  591. See {\tx logand}. This function negates each bit.
  592. \item[{\tx logor~~~~~~~~} \hspace{1cm} {\em special form}]\index{logor}~\newline
  593. See {\tx logand}. This function yields a ``1'' when any input has
  594. a ``1'' in that place.
  595. \item[{\tx logxor~~~~~~~} \hspace{1cm} {\em special form}]\index{logxor}~\newline
  596. See {\tx logand}. This yields a ``1'' if an odd number of inputs have a ``1''
  597. in the cooresponding place, and is ``exclusive or''.
  598. \item[{\tx lpar~~~~~~~~~} \hspace{1cm} {\em predefined variable}]\index{lpar}~\newline
  599. A predefined symbol whose value is the symbole whose name is a left
  600. parenthesis. See also {\tx rpar}.
  601. \item[{\tx macro~~~~~~~~} \hspace{1cm} {\em symbol}]\index{macro}~\newline
  602. See {\tx expr}.
  603. \item[{\tx map~~~~~~~~~~} \hspace{1cm} {\em function 2 args}]\index{map}~\newline
  604. There are a number of functions whose names begin with {\tx map}. These
  605. take two arguments, on a list and the second a function. Each of them
  606. traverses the list calling the given function for each position on it.
  607. {\tx map}, {\tx maplist} and {\tx mapcon} each pass first the original list
  608. and then each succesive tail of it. {\tx mapc}, {\tx mapcar} and {\tx mapcan}
  609. pass the successive items in the list.
  610. In each case the three variants do different things with the results returned
  611. by the function. {\tx map} and {\tx mapc} ignore it and in the end just return
  612. \nil. This is only useful if the function that is provided has side-effects. For
  613. instance it might print something. {\tx maplist} and {\tx mapcar} build a new
  614. list out of the results, and so theior overall result is a list the same
  615. length as the input one. Finally {\tx mapcon} and {\tx mapcan} expect the
  616. function to return \nil{} or some list, and they use {\tx nconc} to
  617. concatenate all those lists.
  618. Many people find {\tx mapc} is the most useful, but then that the
  619. {\tx dotimes} macro (which achieves a similar effect) is easier to use:
  620. compare
  621. {\sverb
  622. (setq a '(1 2 3 4))
  623. (mapc a '(lambda (x) (print (times x x))))
  624. (dolist (x a) (print (times x x)))
  625. \end{verbatim}}
  626. \noindent which achieve similar effects.
  627. \item[{\tx mapc~~~~~~~~~} \hspace{1cm} {\em function 2 args}]\index{mapc}~\newline
  628. See {\tx map}.
  629. \item[{\tx mapcan~~~~~~~} \hspace{1cm} {\em function 2 args}]\index{mapcan}~\newline
  630. See {\tx map}.
  631. \item[{\tx mapcar~~~~~~~} \hspace{1cm} {\em function 2 args}]\index{mapcar}~\newline
  632. See {\tx map}.
  633. \item[{\tx mapcon~~~~~~~} \hspace{1cm} {\em function 2 args}]\index{mapcon}~\newline
  634. See {\tx map}.
  635. \item[{\tx maplist~~~~~~} \hspace{1cm} {\em function 2 args}]\index{maplist}~\newline
  636. See {\tx map}.
  637. \item[{\tx minus~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{minus}~\newline
  638. Negates a number.
  639. \item[{\tx minusp~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{minusp}~\newline
  640. Tests if a value is a negative number. Note that in \vsl{} it is legal
  641. to call {\tx minus} with an argument that is not even a number, in which
  642. case it will return \nil{} to indicate that it is not negative, but in many
  643. other Lisp dialects you should only give {\tx minusp} numeric input.
  644. \item[{\tx mkhash~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{mkhash}~\newline
  645. The hash-table capability built into \vsl{} uses {\tx (mkhash n)} to create
  646. a table, {\tx puthash} to insert data and {\tx gethash} to retrieve
  647. it. {\tx remhash} can remove data. The argument to {\tx mkhash} is used to
  648. control the size of the table,
  649. and might reasonable by chosen to be a fifth or a tenth of the number
  650. of keys you expect to store. Searches within hash tables are based on
  651. {\tx eq}-style identity and are expected to be faster than various
  652. alternative (if simpler) schemes that could be considered.
  653. \item[{\tx mkvect~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{mkvect}~\newline
  654. In \vsl{} a call {\tx (mkvect $n$)} creates a vector where subsequent uses
  655. of {\tx putv} and {\tx getv} can use index values in the range from $0$
  656. to $n$. This results in the vector having $n+1$ elements. A whole vector
  657. counts as an atom in Lisp, not as a list. If {\tx v} is a vector then
  658. {\tx (upbv v)} returns its upper bound -- the largest subscript legal for
  659. use with it.
  660. \item[{\tx nconc~~~~~~~~} \hspace{1cm} {\em function 2 args}]\index{nconc}~\newline
  661. Given two lists, {\tx nconc} concatenates them using a {\tx rplacd} on the
  662. final cell of the first list. This avoids some extra storage allocation that
  663. {\tx append} would have had to make, but overwrites part of the
  664. first list, and unless used with sensitivity that can cause trouble.
  665. \item[{\tx neq~~~~~~~~~~} \hspace{1cm} {\em function 2 args}]\index{neq}~\newline
  666. {\tx (neq a b)} yields exactly the same result as {\tx (not (equal a b))}.
  667. \item[{\tx nil~~~~~~~~~~} \hspace{1cm} {\em predefined variable}]\index{nil}~\newline
  668. The symbol {\tx nil} is used in Lisp to denote an empty list, or to mark
  669. the end of a non-empty one. It is used to mean {\em false}, with anything
  670. non-nil being treated as {\em true}. The value of {\tx nil} is {\tx nil}. In
  671. some Lisp systems (but not this one or its close relatives) it is arranged
  672. that {\tx car} and {\tx cdr} may accept {\tx nil} as an argument and yield
  673. {\tx nil}. Here you are not allowed to do that so {\tx (cdr nil)} will
  674. report an error just as {\tx (cdr 'any\_other\_atom)} would.
  675. \item[{\tx not~~~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{not}~\newline
  676. When a value is being thought of as a truth-value the function {\tx not}
  677. can be used to invert it. Because {\em false} is represented by \nil{} it
  678. turns out that {\tx not} behaves identically to {\tx null}.
  679. \item[{\tx null~~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{null}~\newline
  680. Tests if its argument is \nil. Often used to detect when a list is empty.
  681. \item[{\tx numberp~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{numberp}~\newline
  682. Returns {\tx t} if its argument is a number. See also {\tx fixp} and
  683. {\tx floatp} that check for specific sub-categories of numbers.
  684. \item[{\tx oblist~~~~~~~} \hspace{1cm} {\em function 0 args}]\index{oblist}~\newline
  685. The term ``object list'' is historically used in Lisp to refer to the
  686. symbol table that keeps track of all the identifiers that are in use. Its
  687. purpose is to arrange that every time you enter the same sequence of characters
  688. you get the same symbol back. The function {\tx (oblist)} returns a list of
  689. all symbols in this table. This table of symbols important to Lisp was
  690. started by taking the output from {\tx oblist} and sorting and
  691. formatting it. The number of symbols in the object list gives some idea
  692. of the size of the Lisp implementation. With \vsl{} there are a couple of hundred
  693. symbols known before you start adding more. With the C and the Java coded
  694. implementations of Standard Lisp used with the Reduce algebra system there are
  695. around four times as many.
  696. \item[{\tx onep~~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{onep}~\newline
  697. Test it its argument is 1 or 1.0. See {\tx zerop}.
  698. \item[{\tx open~~~~~~~~~} \hspace{1cm} {\em function 2 args}]\index{open}~\newline
  699. To access data in a file you first {\tx open} the file. A file can be
  700. opened either for reading or writing, as in {\tx (open "input.dat" 'input)}
  701. or {\tx (open "newfile.out", 'output)}. In each case {\tx open} returns
  702. an object that can be passed to {\tx rds} or {\tx wrs} to select that stream
  703. for use. When finished with any file that has bene open should be
  704. tidied up by handing its descriptor to the {\tx close} function.
  705. As well as providing access to files, {\tx open} can be used to launch
  706. another program, with Lisp output to the associated stream made available to
  707. that program as its standard input. This is done using the
  708. construction {\tx (open "programname" 'pipe)}.
  709. \item[{\tx or~~~~~~~~~~~} \hspace{1cm} {\em special form}]\index{or}~\newline
  710. See {\tx and}.
  711. \item[{\tx output~~~~~~~} \hspace{1cm} {\em symbol}]\index{output}~\newline
  712. See {\tx open}.
  713. \item[{\tx pipe~~~~~~~~~} \hspace{1cm} {\em symbol}]\index{pipe}~\newline
  714. See {\tx open}.
  715. \item[{\tx plist~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{plist}~\newline
  716. Every symbol has a property-list and the {\tx plist} function returns it. Normally
  717. this will only be used as a matter of interest, since {\tx put} and {\tx get}
  718. are the proper functions for storing and retrieving information from property
  719. lists.
  720. \item[{\tx plus~~~~~~~~~} \hspace{1cm} {\em special form}]\index{plus}~\newline
  721. Adds an arbitrary number of values. If any one of them is floating
  722. point the result will be floating point.
  723. \item[{\tx preserve~~~~~} \hspace{1cm} {\em function 0 or 1 arg}]\index{preserve}~\newline
  724. If you call {\tx preserve} a copy of the current status of everything in your
  725. Lisp world is written to a file called {\tx vsl.img}. When \vsl{} next starts
  726. it reloads this file (unless the {\tx -z} command line option is used). This
  727. capability can be used to build an image file containing all the definitions
  728. and settings that make up a program so that when {\tx vsl} is started
  729. they are all immediately available.
  730. \item[{\tx prettyprint~~} \hspace{1cm} {\em function 1 arg}]\index{prettyprint}~\newline
  731. The ordinary print functions in \vsl{} fit as much on a line as they can. In
  732. contrast {\tx prettyprint} attempts to make its output more human-readable
  733. by indenting everything in a systematic manner. Su of you want to print out
  734. some Lisp code in a format where it is easier to read it may be useful.
  735. \item[{\tx prin~~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{prin}~\newline
  736. The family of print functions supplied with \vsl{} consists of
  737. {\tx prin}, {\tx princ}, {\tx print} and {\tx printc}. The basic behaviour
  738. of each is that they print their argument to the current output stream. The versions
  739. with a ``{\tx c}'' omit any escape marks, and when printing strings do not
  740. print quote marks, and so the output is perhaps nice for a human reader
  741. but could not be presented back to Lisp. The ones without a ``{\tx c}''
  742. insert escapes (exclamation marks) in names that include characters other
  743. than letters and digits, and do put quote marks around strings. The versions
  744. with a ``{\tx t}'' terminate the output line after displaying their
  745. argument, so that a sequence of calls to {\tx prin} display all the
  746. values on one line, while {\tx print} puts each Lisp form on a separate line.
  747. See {\tx terpri} and {\tx wrs}.
  748. \item[{\tx princ~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{princ}~\newline
  749. See {\tx prin}.
  750. \item[{\tx print~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{print}~\newline
  751. See {\tx prin}.
  752. \item[{\tx printc~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{printc}~\newline
  753. See {\tx prin}.
  754. \item[{\tx prog~~~~~~~~~} \hspace{1cm} {\em special form}]\index{prog}~\newline
  755. {\tx prog} feels like an archaic feature inherited from the early days of Lisp,
  756. amd provides a range of capabilities. Firstly it itroduces some local
  757. variables, then it allows for the sequential execution of a sequence of
  758. Lisp forms, with a labels and a {\tx go} statement to provide control. Finally
  759. a {\tx prog} block only returns a non-nil value if the {\tx return} function
  760. is called within it to provide one. Here is an illustration of the
  761. use of these to compute and print some Fibonacci numbers and then return the
  762. symbol {\tx finished}
  763. {\sverb
  764. (prog (a b n c)
  765. (setq a 0 b 1 n 0)
  766. top(when (greaterp n 10) (return 'finished))
  767. (setq c b b (print (plus a b)) a c n (add1 n))
  768. (go top))
  769. \end{verbatim}}
  770. \item[{\tx progn~~~~~~~~} \hspace{1cm} {\em special form}]\index{progn}~\newline
  771. There are a number of contexts in Lisp where you can write a sequence of
  772. expressions and these are evaluated in turn with the result of the
  773. final one as the overall result. {\tx progn} can provide this capability
  774. in any other situation where it is useful.
  775. \item[{\tx psetq~~~~~~~~} \hspace{1cm} {\em macro}]\index{psetq}~\newline
  776. See {tx setq}, but {\tx psetq} arranges to evaluate all the new values before
  777. updating any of the variables. A typical use of it would be to exchange the
  778. values in two variables, as in {\tx (psetq a b b a)}.
  779. \item[{\tx put~~~~~~~~~~} \hspace{1cm} {\em function 3 args}]\index{put}~\newline
  780. See {\tx get} and {\tx deflist}.
  781. \item[{\tx puthash~~~~~~} \hspace{1cm} {\em function 3 args}]\index{puthash}~\newline
  782. See {\tx mkhash}, {\tx gethash} and {\tx remhash}.
  783. \item[{\tx putv~~~~~~~~~} \hspace{1cm} {\em function 3 args}]\index{putv}~\newline
  784. See {\tx mkvect} and {\tx getvec}.
  785. \item[{\tx quote~~~~~~~~} \hspace{1cm} {\em special form}]\index{quote}~\newline
  786. Normally each sub-part of a Lisp program will be evaluated -- that is to say
  787. treated as program not data. The special form {\tx quote} protects its
  788. argument from evaluation and so is used when you wish to specify data.
  789. This is so common and so important that Lisp provides special syntax for it.
  790. A Lisp expression preceeded by a single quote mark {\tx '} is expanded into
  791. an application of the {\tx quote} function. Thus {\tx '(a b c)} means
  792. exactly the sane as {\tx (quote (a b c))}.
  793. \item[{\tx quotient~~~~~} \hspace{1cm} {\em function 2 args}]\index{quotient}~\newline
  794. Form the quotient of two numeric arguments.
  795. \item[{\tx rassoc~~~~~~~} \hspace{1cm} {\em function 2 args}]\index{rassoc}~\newline
  796. {\tx rassoc} is just like {\tx assoc} except that it looks for a match
  797. against the second component of one of the pairs in a list rather than
  798. the first. So it is a sort of reversed-{\tx assoc}. Thus
  799. {\tx (rassoc 2 '((a . 1) (b . 2) (c . 3)))} returns {\tx (b . 2)}.
  800. \item[{\tx rdf~~~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{rdf}~\newline
  801. {\tx rdf} reads and interprets all the Lisp code in the file whose name
  802. it is given as an argument.
  803. \item[{\tx rds~~~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{rds}~\newline
  804. To read data from a file you first open the file (using {\tx open}) then select
  805. it as the current input stream using {\tx rds}. A call to {\tx rds} returns the
  806. previously selected input stream, and very often you will want to save that
  807. so you can restore it later. A reasonably complete (and slightly cautious)
  808. example would be
  809. {\sverb
  810. (let* ((instream (open "filename" 'input))
  811. (oldstream (rds instream)))
  812. (errorset '(process (read)) t t)
  813. (rds oldstream)
  814. (close instream))
  815. \end{verbatim}}
  816. This shows saving the existing input stream and restoring it at the
  817. end. It
  818. uses {\tx errorset} to ensure that this happens even if processing the
  819. input from the file fails.
  820. \item[{\tx read~~~~~~~~~} \hspace{1cm} {\em function 0 args}]\index{read}~\newline
  821. This reads a full Lisp object from the current input stream (which is by
  822. default from the keyboard, but can be changed using {\tx rds}). The item can
  823. be a symbol, a number, a string or a list. It can also start with a quote
  824. mark or backquote. The function {\tx read} is the one that is normally
  825. used when Lisp wants to grab input from the user, so the standard
  826. Lisp top level behaviour is as if it were obeying
  827. {\tx (while t (print (eval (read))))}.
  828. If {\tx read} finds the end of an input file it returns {\tx !$eof!$}.
  829. \item[{\tx readch~~~~~~~} \hspace{1cm} {\em function 0 args}]\index{readch}~\newline
  830. This reads a single character, returning a Lisp symbol that has that character
  831. as its name. If {\tx readch} finds the end of an input file it returns {\tx !$eof!$}.
  832. \item[{\tx readline~~~~~} \hspace{1cm} {\em function 0 args}]\index{readline}~\newline
  833. This reads a whole line and returns a symbol made up from the characters
  834. found. If {\tx readlione} finds the end of an input file it returns
  835. {\tx !$eof!$}.
  836. \item[{\tx remainder~~~~} \hspace{1cm} {\em function 2 args}]\index{remainder}~\newline
  837. This divides a pair of integers and returns the remainder.
  838. \item[{\tx remhash~~~~~~} \hspace{1cm} {\em function 2 args}]\index{remhash}~\newline
  839. {\tx (remhash 'key table)} removes a hash table entry previously
  840. inserted by {\tx puthash}.
  841. \item[{\tx remprop~~~~~~} \hspace{1cm} {\em function 2 args}]\index{remprop}~\newline
  842. {\tx (remprop 'symbol 'indicator)} removes a property previously
  843. set up using {\tx put}.
  844. \item[{\tx return~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{return}~\newline
  845. This is used with {\tx prog}.
  846. \item[{\tx reverse~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{reverse}~\newline
  847. The ordinary function for reversing a list.
  848. \item[{\tx reversip~~~~~} \hspace{1cm} {\em function 1 arg}]\index{reversip}~\newline
  849. A function that reverses a list in a way that re-uses the existing {\tx cons}-cells
  850. so as to avoid any need to allocate fresh ones. This necessarily destroys
  851. the input list by overwriting parts of it (using {\tx rplacd})
  852. so should only be used when you are certain that nobody else needs that list.
  853. \item[{\tx rightshift~~~} \hspace{1cm} {\em function 2 args}]\index{rightshift}~\newline
  854. See {\tx logand} and friends. This shifts the bits in a number right, and
  855. at least for positive values {\tx (rightshift a $n$)} has the same
  856. effect as dividing {\tx a} by $2^{n}$.
  857. \item[{\tx rpar~~~~~~~~~} \hspace{1cm} {\em predefined variable}]\index{rpar}~\newline
  858. A predefined symbol whose value is the symbole whose name is a right
  859. parenthesis. See also {\tx lpar}.
  860. \item[{\tx rplaca~~~~~~~} \hspace{1cm} {\em function 2 args}]\index{rplaca}~\newline
  861. If you have a {\tx cons}-cell you can use {\tx rplaca} to replace the
  862. {\tx car} field, {\tx rplacd} to replace the {\tx cdr} field or
  863. {\tx rplacw} to replace both. In each case the result of the function is the
  864. {\tx cons} cell that has been updated. Use of these functions can corrupt
  865. existing structures and create cyclic ones that lead to all sorts of trouble,
  866. and so they should only be used when there is a compelling reason to need
  867. a side-effect.
  868. \item[{\tx rplacd~~~~~~~} \hspace{1cm} {\em function 2 args}]\index{rplacd}~\newline
  869. See {\tx rplaca}.
  870. \item[{\tx rplacw~~~~~~~} \hspace{1cm} {\em function 2 args}]\index{replacw}~\newline
  871. See {\tx rplaca}.
  872. \item[{\tx sassoc~~~~~~~} \hspace{1cm} {\em function 3 args}]\index{sassoc}~\newline
  873. Here we have another variant on {\tx assoc}. In fact {\tx sassoc} is like
  874. {\tx assoc} except that it has an extra argument, and if the key it is looking
  875. for is not found in the association list rather then returning a simple value
  876. \nil{} it returns the result from calling that final argument as a function
  877. with no arguments. While this has a long history of being part of Lisp
  878. I suspect that very few people use it these days.
  879. \item[{\tx set~~~~~~~~~~} \hspace{1cm} {\em function 2 args}]\index{set}~\newline
  880. This behaves like {\tx setq} except that rather than being a special form it
  881. takes exactly two arguments, and treats the first as the name of a variable
  882. and the second as a value to store into that variable. It is not very common
  883. to need to make the name of a variable that you are assigning to a computed
  884. value in this manner.
  885. \item[{\tx setq~~~~~~~~~} \hspace{1cm} {\em special form}]\index{setq}~\newline
  886. When you have a Lisp variable you can change its value using {\tx setq}. In
  887. fact {\tx setq} allows you to make several updates, one after another, in one
  888. call. Its arguments alternate between being variable names and expressions
  889. to compute values to set them to. So for instance {\tx (setq a 1 b 2)} sets
  890. {\tx a} to {\tx 1} and {\tx b} to {\tx 2}. See {\tx psetq} for a variant that
  891. does all the assignments in parallel.
  892. \item[{\tx sin~~~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{sin}~\newline
  893. This is the usual trigonometic function, accepting its argument in
  894. radianc. See {\tx cos} and {\tx sqrt}.
  895. %\item[{\tx sort~~~~~~~~~} \hspace{1cm} {\em function 2 args}]\index{sort}~\newline
  896. %~
  897. \item[{\tx spaces~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{spaces}~\newline
  898. {\tx (spaces $n$)} prints $n$ blanks.
  899. \item[{\tx sqrt~~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{sqrt}~\newline
  900. Computes the square root of a number, returning the result as a floating
  901. point value whether the input was floating or an integer.
  902. \item[{\tx stop~~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{stop}~\newline
  903. To quit Lisp you can call {\tx stop} giving it an argument that is used as
  904. a return code from the system. This quits Lisp instantly and unconditionally
  905. and so should be used with some consideration.
  906. \item[{\tx stringp~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{stringp}~\newline
  907. Tests if its argument is a string. See {\tx atom}, {\tx numberp} and
  908. {\tx symbolp}.
  909. \item[{\tx sub1~~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{sub1}~\newline
  910. Subtracts one from its argument.
  911. \item[{\tx subr~~~~~~~~~} \hspace{1cm} {\em symbol}]\index{subr}~\newline
  912. See {\tx expr}.
  913. \item[{\tx subst~~~~~~~~} \hspace{1cm} {\em function 3 args}]\index{subst}~\newline
  914. If you have a list or set of nested lists then {\tx (subst a b c)} replaces every
  915. item in {\tx c} that is equal to {\tx b} with an {\tx a}. In other
  916. words ``substitute a for b in c''. This only scans its input down to the
  917. level of atoms, so for instance vectors and hash tables do not have their
  918. components or contents looked at.
  919. \item[{\tx symbolp~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{symbolp}~\newline
  920. Test if an onject is a symbol.
  921. \item[{\tx t~~~~~~~~~~~~} \hspace{1cm} {\em predefined variable}]\index{t}~\newline
  922. In Lisp the symbol \nil{} is used for {\em false}. If there is no better
  923. non-\nil{} value to be used for {\em true} then {\tx t} is used, and the
  924. symbol {\tx t} starts off as a variable that has itself as its value.
  925. \item[{\tx tab~~~~~~~~~~} \hspace{1cm} {\em predefined variable}]\index{tab}~\newline
  926. A symbol whose initial value is a tab character. See {\tx blank}.
  927. \item[{\tx terpri~~~~~~~} \hspace{1cm} {\em function 0 args}]\index{terpri}~\newline
  928. This TERminates the PRInt Line. It is equivalent to {\tx (princ !$eol!$)}.
  929. \item[{\tx time~~~~~~~~~} \hspace{1cm} {\em function 0 args}]\index{time}~\newline
  930. If you wish to measure the amount of CPU time that some calculation takes then
  931. you can use {\tx (time)} to read a timer both before and after. The difference
  932. between the two values will be the processor time used, measured in
  933. milliseconds.
  934. \item[{\tx times~~~~~~~~} \hspace{1cm} {\em special form}]\index{times}~\newline
  935. Multiplies all of its arguments together.
  936. \item[{\tx trace~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{trace}~\newline
  937. If you go {\tx (trace '(f1 f2 \ldots))} then each of the functions {\tx f1},\ldots
  938. is marked for tracing. When this has happened \vsl{} prints messages each time
  939. the function concerned is called and each time it returns a result. This
  940. can be a great help when your code is misbehaving: you {\tx trace} a suitable
  941. set of key functions and try some test examples. The extra output may be
  942. bulky but with luck will allow you to understand exactly what is happening.
  943. When fimished you can call {\tx (untrace '(f1 f2 \ldots))} to restore
  944. things to their normal state.
  945. \item[{\tx upbv~~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{upbv}~\newline
  946. Given a vector, {\tx upbv} returns the highest legal subscript that can be
  947. used with it. See {\tx mkvect}, {\tx putv} and {\tx getv}.
  948. \item[{\tx untrace~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{untrace}~\newline
  949. See {\tx trace}.
  950. \item[{\tx vectorp~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{vectorp}~\newline
  951. Tests if an object is a vector. See {\tx mkvect}.
  952. \item[{\tx vsl~~~~~~~~~~} \hspace{1cm} {\em symbol in lispsystem!*}]\index{vsl}~\newline
  953. A predefined variable {\tx lispsystem!*} has items in it that
  954. can give information about the Lisp system that is in use. Here the only
  955. information provided is the symbol \vsl{} which (obviously) identifies the
  956. Lisp version.
  957. \item[{\tx while~~~~~~~~} \hspace{1cm} {\em macro}]\index{while}~\newline
  958. {\tx while} is a macro that is provided with a predicate and then a sequence
  959. of expressions to be evaluated repeatedly for so long as the predicate yields
  960. something non-\nil.
  961. {\sverb
  962. (let ((n 1))
  963. (while (lessp n 1000000)
  964. (printc (list n "is too small"))
  965. (setq n (times 3 n)))
  966. n)
  967. \end{verbatim}}
  968. \noindent would return the first power of three that is at least a million,
  969. prionting reports on its progress.
  970. \item[{\tx wrs~~~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{wrs}~\newline
  971. If you need to direct output to somewhere other than the terminal (for instance
  972. to a file or pipe) then you can use {\tx wrs} to select the relevant stream as
  973. the one to print to. {\tx wrs} returns the previously selected stream, and
  974. often you will wish to save that so you can restore it later. See {\tx open},
  975. {\tx rds} and {\tx close}.
  976. \item[{\tx zerop~~~~~~~~} \hspace{1cm} {\em function 1 arg}]\index{zerop}~\newline
  977. Tests to see if its argument is 0 or 0.0. See {\tx onep}.
  978. \end{description}