Commit | Line | Data |
---|---|---|
133480cf JF |
1 | .Lc Special\ Functions 4 |
2 | .\".ch 4 | |
3 | .Lf and "[g_arg1 ...]" | |
4 | .Re | |
5 | the value of the last argument if all arguments evaluate | |
6 | to a non nil value, otherwise | |
7 | .i and | |
8 | returns nil. | |
9 | It returns t if there are no arguments. | |
10 | .No | |
11 | the arguments are evaluated left to right and evaluation will cease | |
12 | with the first nil encountered | |
13 | .Lf apply "'u_func 'l_args" | |
14 | .Re | |
15 | the result of applying function u_func to the arguments in the list l_args. | |
16 | .Lf arg "['x_numb]" | |
17 | .Re | |
18 | if x_numb is specified then the x_numb'\fIth\fP argument to | |
19 | the enclosing lexpr | |
20 | If x_numb is not specified then this returns the number of arguments | |
21 | to the enclosing lexpr. | |
22 | .No | |
23 | it is an error to the interpreter if x_numb is given and out of range. | |
24 | .Lf break "[g_val]" | |
25 | .Re | |
26 | the value of the next return typed in at top level. | |
27 | .Se | |
28 | the lisp system stops and prints out g_val if given, and then | |
29 | goes into a break loop. | |
30 | This allows one to interactively debug a program. | |
31 | You may leave the break with | |
32 | .i return | |
33 | or | |
34 | .i retbrk . | |
35 | .Lf catch "g_exp [s_tag]" | |
36 | .Re | |
37 | the result of evaluating g_exp or the value thrown during the evaluation | |
38 | of g_exp. | |
39 | .Se | |
40 | this first sets up a `catch frame' on the lisp runtime stack. | |
41 | Then it begins to evaluate g_exp. | |
42 | If g_exp evaluates normally, its value is returned. | |
43 | If, however a | |
44 | .i throw | |
45 | is done we will catch the value thrown iff | |
46 | the tag thrown to is s_tag or if there is no s_tag argument to the catch. | |
47 | .No | |
48 | Errors are implemented as a special kind of throw. | |
49 | A catch with no tag will not catch an error but a catch whose tag is | |
50 | the error type will catch that type of error. | |
51 | See \(scX.Y for more information. | |
52 | .\".pg | |
53 | .Lf cond "[l_clause1 ...]" | |
54 | .Re | |
55 | the last value evaluated in the first clause satisfied. | |
56 | If no clauses are satisfied then nil is returned. | |
57 | .No | |
58 | This is the basic conditional `statement' in lisp. | |
59 | The clauses are processed from left to right. | |
60 | The first element of a clause is evaluated. | |
61 | If it evaluated to a non nil value then that clause is satisfied and | |
62 | all following elements of that clause are evaluated. | |
63 | The last value computed is returned as the value of the cond. | |
64 | If there is just one element in the clause then its value is returned. | |
65 | If the first element of a clause evaluates to nil, then the other | |
66 | elements of that clause are not evaluated and the system moves to | |
67 | the next clause. | |
68 | .Lf declare "[g_arg ...]" | |
69 | .Re | |
70 | nil | |
71 | .No | |
72 | this is a no-op to the evaluator. | |
73 | It has special meaning to the compiler. | |
74 | .Lf def "s_name (s_type l_argl g_exp1 ...)" | |
75 | .Wh | |
76 | s_type is one of lambda, nlambda, macro or lexpr. | |
77 | .Re | |
78 | s_name | |
79 | .Se | |
80 | This defines the function s_name to the lisp system. | |
81 | If s_type is nlambda or macro then the argument list l_argl must contain | |
82 | exactly one non-nil symbol. | |
83 | .Lf defun "s_name [s_mtype] ls_argl g_exp1 ... " | |
84 | .Wh | |
85 | s_mtype is one of fexpr, expr, args or macro. | |
86 | .Re | |
87 | s_name | |
88 | .Se | |
89 | This defines the function s_name. | |
90 | .No | |
91 | this exists for Maclisp compatibility, it is just a macro which | |
92 | changes the defun form to the def form. | |
93 | An s_mtype of fexpr is converted to nlambda, of args to lexpr | |
94 | , and of expr to lambda. Macro is the same. | |
95 | If ls_arg1 is a symbol, then the type is assumed to be lexpr and | |
96 | ls_arg1 is the symbol which is bound to the number of args when the | |
97 | function is entered. | |
98 | .Lf do "l_vrbs l_test g_exp1 ..." | |
99 | .Re | |
100 | the last form in the cdr of l_test evaluated, or a value explicitly given by | |
101 | a return evaluated within the do body. | |
102 | .No | |
103 | This is the basic iteration form for | |
104 | .Fr . | |
105 | l_vrbs is a list of zero or more var-init-repeat forms. | |
106 | A var-init-repeat form looks like: | |
107 | .br | |
108 | .tl ''(s_name [g_init [g_repeat]])'' | |
109 | There are three cases depending on what is present in the form. | |
110 | If just s_name is present, this means that when the do is entered, | |
111 | s_name is lambda-bound to nil and is never modified by the system | |
112 | (though the program is certainly free to modify its value). | |
113 | If the form is (s_name\ 'g_init) then the only difference is that | |
114 | s_name is lambda-bound to the value of g_init instead of nil. | |
115 | If g_repeat is also present then s_name is lambda-bound to g_init | |
116 | when the loop is entered and after each pass through the do body | |
117 | s_name is bound to the value of g_repeat. | |
118 | .br | |
119 | l_test is either nil or has the form of a cond clause. | |
120 | If it is nil then the do body will be evaluated only once and the | |
121 | do will return nil. | |
122 | Otherwise, before the do body is evaluated the car of l_test is | |
123 | evaluated and if the result is non nil this signals an end to | |
124 | the looping. | |
125 | Then the rest of the forms in l_test are evaluated | |
126 | and the value of the last one is returned as the value of the do. | |
127 | If the cdr of l_test is nil, then nil is returned -- thus this is not | |
128 | exactly like a cond clause. | |
129 | .br | |
130 | g_exp1 and those forms which follow constitute the do body. | |
131 | A do body is like a prog body and thus may have labels and one may | |
132 | use the functions go and return. | |
133 | .br | |
134 | The sequence of evaluations is this: | |
135 | .np | |
136 | the init forms are evaluated left to right and stored in temporary | |
137 | locations. | |
138 | .np | |
139 | Simultaneously all do variables are lambda bound to the value of | |
140 | their init forms or nil. | |
141 | .np | |
142 | If l_test is non nil then the car is evaluated and if it is non nil | |
143 | the rest of the forms in l_test are evaluated and the last value is | |
144 | returned as the value | |
145 | of the do. | |
146 | .np | |
147 | The forms in the do body are evaluated left to right. | |
148 | .np | |
149 | If l_test is nil the do function returns with the value nil. | |
150 | .np | |
151 | The repeat forms are evaluated and saved in temporary locations. | |
152 | .np | |
153 | The variables with repeat forms are simultaneoulsy | |
154 | bound to the values of those forms. | |
155 | .np | |
156 | Go to step 3. | |
157 | .No | |
158 | there is an alternate form of do which can be used when there is | |
159 | only one do variable. | |
160 | It is described next. | |
161 | .\".pg | |
162 | .Lf do "s_name g_init g_repeat g_test g_exp1 ..." | |
163 | .nr $p 0 | |
164 | .No | |
165 | this is another, less general, form of do. | |
166 | It is evaluated by: | |
167 | .np | |
168 | evaluating g_init | |
169 | .np | |
170 | lambda binding s_name to value of g_init | |
171 | .np | |
172 | g_test is evaluated and if it is not nil the do function returns with nil. | |
173 | .np | |
174 | the do body is evaluated beginning at g_exp1. | |
175 | .np | |
176 | the repeat form is evaluted and stored in s_name. | |
177 | .np | |
178 | go to step 3. | |
179 | .\".pg | |
180 | .Lf err ??? | |
181 | .Lf errset ??? | |
182 | .Lf eval "'g_val" | |
183 | .Re | |
184 | the result of evaluating g_val. | |
185 | .No | |
186 | The evaluator evaluates g_val in this way: | |
187 | .br | |
188 | If g_val is a symbol, then the evaluator returns its value. | |
189 | If g_val had never been assigned a value, then this causes | |
190 | an 'Unbound Variable' error. | |
191 | If g_val is of type value, then its value is returned. | |
192 | If g_val is a list object then g_val is either a function call or | |
193 | array reference. | |
194 | Let g_car be the first element of g_val. | |
195 | We continually evaluate g_car until we end up with a symbol with | |
196 | a non nil function binding | |
197 | or a non-symbol. | |
198 | Call what we end up with: g_func. | |
199 | g_func must be one of three types: list, binary or array. | |
200 | If it is a list then the first element of the list, which | |
201 | we shall call g_functype, must be either | |
202 | lambda, nlambda, macro or lexpr. | |
203 | If g_func is a binary, then its discipline, which we shall call | |
204 | g_functype, is either lambda, nlambda or macro. | |
205 | If g_func is an array then this form is evaluated specially, see | |
206 | \(sc X.arrays. | |
207 | If g_func is a list or binary, then g_functype will determine how | |
208 | the arguments to this function, the cdr of g_val, are processed. | |
209 | If g_functype is lambda or lexpr, the arguments are evaluated | |
210 | (by calling | |
211 | .i eval | |
212 | recursively) and stacked. | |
213 | If g_functype is nlambda then the argument list is stacked. | |
214 | If g_functype is macro then the entire form, g_val is stacked. | |
215 | Next the formal valiables are lambda bound. | |
216 | The formal variables are the cadr of g_func - if g_functype is | |
217 | nlambda, lexpr or macro, there should only be one formal variable. | |
218 | The values on the stack are lambda bound to the formal variables | |
219 | except in the case of a lexpr, where the number of actual arguments | |
220 | is bound to the formal variable. | |
221 | After the binding is done, the function is invoked, either by | |
222 | jumping to the entry point in the case of a binary or | |
223 | by evaluating the list of forms beginning at cddr g_func. | |
224 | The result of this function invocation is returned as the value | |
225 | of the call to eval. | |
226 | .Lf eval-when "l_times g_exp1 ... g_expn" | |
227 | .Wh | |
228 | l_times is a list containing any combination of compile, eval and load. | |
229 | .Re | |
230 | nil | |
231 | if the symbol eval is not member of l_times, | |
232 | else returns the value of g_expn. | |
233 | .Se | |
234 | If eval is a member of l_times, then the forms g_exp\fIi\fP are | |
235 | evaluated. | |
236 | .No | |
237 | this is used mainly to control when the compiler evaluates forms. | |
238 | .\".pg | |
239 | .Lf exec | |
240 | .Lf funcall "'u_func ['g_arg1 ...]" | |
241 | .Re | |
242 | the value of applying function u_func to the arguments g_arg\fIi\fP. | |
243 | .Lf function "u_func" | |
244 | .Re | |
245 | the function binding of u_func if it is an symbol with a function binding | |
246 | otherwise u_func is returned. | |
247 | .Lf getdisc "'t_func" | |
248 | .Re | |
249 | the discipline of the machine coded function (either lambda, nlambda | |
250 | or macro). | |
251 | .Lf go "g_labexp" | |
252 | .Wh | |
253 | g_labexp is either a symbol or an expression. | |
254 | .Se | |
255 | If g_labexp is an expression, that expression is evaluated and this | |
256 | should | |
257 | result in a symbol. | |
258 | the locus of control moves to just following the label s_lable in the | |
259 | current prog body. | |
260 | .No | |
261 | this is only valid in the context of a prog body. | |
262 | The interpreter will allow non-local go's and expressions which | |
263 | evaluate to a symbol, but the compiler will not so | |
264 | be forewarned. | |
265 | .Lf map "'u_func 'l_arg1 ..." | |
266 | .Re | |
267 | l_arg1 | |
268 | .No | |
269 | The function u_func is applied to successive sublists of the l_arg\fIi\fP. | |
270 | All sublists should have the same length. | |
271 | .\".pg | |
272 | .Lf mapc "'u_func 'l_arg1 ..." | |
273 | .Re | |
274 | l_arg1. | |
275 | .No | |
276 | The function u_func is applied to successive elements of the argument | |
277 | lists. | |
278 | All of the lists should have the same length. | |
279 | .Lf mapcan "'u_func 'l_arg1 ..." | |
280 | .Re | |
281 | nconc applied to the results of the functional evaluations. | |
282 | .No | |
283 | The function u_func is applied to successive elements of the | |
284 | argument lists. | |
285 | All sublists should have the same length. | |
286 | .Lf mapcar "'u_func 'l_arg1 ..." | |
287 | .Re | |
288 | a list of the values returned from the functional application. | |
289 | .No | |
290 | the function u_func is applied to successive elements of the | |
291 | argument lists. | |
292 | All sublists should have the same length. | |
293 | .Lf mapcon "'u_func 'l_arg1 ..." | |
294 | .Re | |
295 | nconc applied to the results of the functional evaluation. | |
296 | .No | |
297 | the function u_func is applied to successive sublists of the | |
298 | argument lists. | |
299 | All sublists should have the same length. | |
300 | .Lf maplist "'u_func 'l_arg1 ..." | |
301 | .Re | |
302 | a list of the results of the functional evaluations. | |
303 | .No | |
304 | the function u_func is applied to successive sublists of the arguments | |
305 | lists. | |
306 | All sublists should have the same length. | |
307 | .Lf mfunction "entry 's_disc" | |
308 | .Re | |
309 | a lisp object of type binary composed of entry and s_disc. | |
310 | .No | |
311 | entry is a pointer to the machine code for a function, and s_disc is the | |
312 | discipline (e.g. lambda). | |
313 | .\".pg | |
314 | .Lf oblist | |
315 | .Re | |
316 | a list of all symbols on the oblist. | |
317 | .Lf or "[g_arg1 ... ]" | |
318 | .Re | |
319 | the value of the first non nil argument or nil if all arguments | |
320 | evaluate to nil. | |
321 | .No | |
322 | Evaluation proceeds left to right and stops as soon as one of the arguments | |
323 | evaluates to a non nil value. | |
324 | .Lf prog "l_vrbls g_exp1 ..." | |
325 | .Re | |
326 | the value explicitly given in a return form | |
327 | or else nil if no return is done by the time the last g_exp\fIi\fP is | |
328 | evaluated. | |
329 | .No | |
330 | the local variables are lambda bound to nil then the g_exp\fI\fP | |
331 | are evaluated from left to right. | |
332 | This is a prog body (obviously) and this means than | |
333 | any symbols seen are not evaluated, | |
334 | instead they are treated as labels. | |
335 | This also means that returns and go's are allowed. | |
336 | .Lf prog2 "g_exp1 g_exp2 [g_exp3 ...]" | |
337 | .Re | |
338 | the value of g_exp2. | |
339 | .No | |
340 | the forms are evaluated from left to right and the value of g_exp2 is | |
341 | returned. | |
342 | .Lf progn "g_exp1 [g_exp2 ...]" | |
343 | .Re | |
344 | the value of the last g_exp\fIi\fP. | |
345 | .No | |
346 | the forms are evaluated from left to right and the value of the last one | |
347 | is returned. | |
348 | .Im | |
349 | what if there are no forms. | |
350 | .Lf progv "'l_locv 'l_initv g_exp1 ..." | |
351 | .Wh | |
352 | l_locv is a list of symbols and the length of l_initv is the same as | |
353 | the length of l_locv. | |
354 | .Re | |
355 | the value of the last g_exp\fIi\fP evaluated. | |
356 | .No | |
357 | first the symbols in l_locv are lambda-bound to the values in l_initv. | |
358 | Then the g_exp\fIi\fP are evaluated left to right. | |
359 | The body of a progv is like the body of a progn, it is | |
360 | .i not | |
361 | a prog body. | |
362 | .\".pg | |
363 | .Lf putd "'s_name 'u_func" | |
364 | .Re | |
365 | this sets the function binding of symbol s_name to u_func. | |
366 | .Lf return "['g_val]" | |
367 | .Re | |
368 | g_val (or nil if g_val is not present) from the enclosing prog body. | |
369 | .No | |
370 | this form is only valid in the context of a prog body. | |
371 | .Lf throw "'g_val [s_tag]" | |
372 | .Re | |
373 | g_val from the enclosing catch with the tag s_tag or no tag at all, whichever | |
374 | is closest. | |
375 | .No | |
376 | this is used in conjunction with | |
377 | .i catch | |
378 | to cause a clean jump to an enclosing context. |