document distributed with 4.1BSD
[unix-history] / usr / src / old / lisp / PSD.doc / ch4.n
CommitLineData
a9516a90
NC
1.\" Copyright (c) 1980 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
a87625b5 5.\" @(#)ch4.n 6.1 (Berkeley) %G%
a9516a90 6.\"
a87625b5
NC
7." $Header: ch4.n,v 1.4 83/07/27 15:11:44 layer Exp $
8.pp
9.Lc Special\ Functions 4
10.Lf and "[g_arg1 ...]"
11.Re
12the value of the last argument if all arguments evaluate
13to a non-nil value, otherwise
14.i and
15returns nil.
16It returns t if there are no arguments.
17.No
18the arguments are evaluated left to right and evaluation will cease
19with the first nil encountered.
20.Lf apply "'u_func 'l_args"
21.Re
22the result of applying function u_func to the arguments in the list l_args.
23.No
24If u_func is a lambda, then the \fI(length\ l_args)\fP should equal the
25number of formal parameters for the u_func.
26If u_func is a nlambda or macro, then l_args is bound to the single
27formal parameter.
28.Eb
29; \fIadd1\fP is a lambda of 1 argument
30\-> \fI(apply 'add1 '(3))\fP
314
32
33; we will define \fIplus1\fP as a macro which will be equivalent to \fIadd1\fP
34\-> \fI(def plus1 (macro (arg) (list 'add1 (cadr arg))))\fP
35plus1
36\-> \fI(plus1 3)\fP
374
38
39; now if we \fIapply\fP a macro we obtain the form it changes to.
40\-> \fI(apply 'plus1 '(plus1 3))\fP
41(add1 3)
42
43; if we \fIfuncall\fP a macro however, the result of the macro is \fIeval\fPed
44; before it is returned.
45\-> \fI(funcall 'plus1 '(plus1 3))\fP
464
47
48; for this particular macro, the \fIcar\fP of the \fIarg\fP is not checked
49; so that this too will work
50\-> \fI(apply 'plus1 '(foo 3))\fP
51(add1 3)
52
53.Ee
54.Lf arg "['x_numb]"
55.Re
56if x_numb is specified then the x_numb'\fIth\fP argument to
57the enclosing lexpr
58If x_numb is not specified then this returns the number of arguments
59to the enclosing lexpr.
60.No
61it is an error to the interpreter if x_numb is given and out of range.
62.Lf break "[g_message ['g_pred]]"
63.Wh
64if g_message is not given it is assumed to be the null string, and
65if g_pred is not given it is assumed to be t.
66.Re
67the value of \fI(*break 'g_pred 'g_message)\fP
68.Lf *break "'g_pred 'g_message"
69.Re
70nil immediately if g_pred is nil, else
71the value of the next (return 'value) expression typed in at top level.
72.Se
73If the predicate, g_pred, evaluates to non-null,
74the lisp system stops and prints out `Break '
75followed by g_message.
76It then enters a break loop
77which allows one to interactively debug a program.
78To continue execution from a break you can use the
79.i return
80function.
81to return to top level or another break level, you can use
82.i retbrk
83or
84.i reset .
85.Lf caseq "'g_key-form l_clause1 ..."
86.Wh
87l_clause\fIi\fP is a list of the form
88(g_comparator ['g_form\fIi\fP ...]).
89The comparators may be symbols, small fixnums, a list of small fixnums or
90symbols.
91.No
92The way caseq works is that it evaluates g_key-form,
93yielding a value we will call the selector.
94Each clause is examined until the selector is found
95consistent with the comparator.
96For a symbol, or a fixnum, this means the two must be \fIeq\fP.
97For a list, this means that the selector must be \fIeq\fP to
98some element of the list.
99.br
100.sp
101The comparator consisting of the symbol \fBt\fP has special semantics:
102it matches anything, and consequently, should be the last comparator.
103.br
104.sp
105In any case, having chosen a clause, \fIcaseq\fP evaluates each form
106within that clause and
107.Re
108the value of the last form. If no comparators are matched,
109\fIcaseq\fP returns nil.
110.Eb
111Here are two ways of defining the same function:
112\->\fI(defun fate (personna)
113 (caseq personna
114 (cow '(jumped over the moon))
115 (cat '(played nero))
116 ((dish spoon) '(ran away with each other))
117 (t '(lived happily ever after))))\fP
118fate
119\->\fI(defun fate (personna)
120 (cond
121 ((eq personna 'cow) '(jumped over the moon))
122 ((eq personna 'cat) '(played nero))
123 ((memq personna '(dish spoon)) '(ran away with each other))
124 (t '(lived happily ever after))))\fP
125fate
126.Ee
127.Lf catch "g_exp [ls_tag]"
128.Wh
129if ls_tag is not given, it is assumed to be nil.
130.Re
131the result of \fI(*catch 'ls_tag g_exp)\fP
132.No
133catch is defined as a macro.
134.Lf *catch "'ls_tag g_exp"
135.Wh
136ls_tag is either a symbol or a list of symbols.
137.Re
138the result of evaluating g_exp or the value thrown during the evaluation
139of g_exp.
140.Se
141this first sets up a `catch frame' on the lisp runtime stack.
142Then it begins to evaluate g_exp.
143If g_exp evaluates normally, its value is returned.
144If, however, a value is thrown during the evaluation of g_exp then
145this *catch will return with that value if one of these cases
146is true:
147.nr $p 0
148.np
149the tag thrown to is ls_tag
150.np
151ls_tag is a list and the tag thrown to is a member of this list
152.np
153ls_tag is nil.
154.No
155Errors are implemented as a special kind of throw.
156A catch with no tag will not catch an error but a catch whose tag is
157the error type will catch that type of error.
158See Chapter 10 for more information.
159.Lf comment "[g_arg ...]"
160.Re
161the symbol comment.
162.No
163This does absolutely nothing.
164.Lf cond "[l_clause1 ...]"
165.Re
166the last value evaluated in the first clause satisfied.
167If no clauses are satisfied then nil is returned.
168.No
169This is the basic conditional `statement' in lisp.
170The clauses are processed from left to right.
171The first element of a clause is evaluated.
172If it evaluated to a non-null value then that clause is satisfied and
173all following elements of that clause are evaluated.
174The last value computed is returned as the value of the cond.
175If there is just one element in the clause then its value is returned.
176If the first element of a clause evaluates to nil, then the other
177elements of that clause are not evaluated and the system moves to
178the next clause.
179.Lf cvttointlisp
180.Se
181The reader is modified to conform with the Interlisp syntax.
182The character % is made the escape character and special meanings for
183comma, backquote and backslash are removed.
184Also the reader is told to convert upper case to lower case.
185.Lf cvttofranzlisp
186.Se
187.Fr "'s"
188default syntax is reinstated.
189One would run this function after having run any
190of the other
191.i cvtto-
192functions.
193Backslash is made the escape character, super-brackets work again,
194and the reader distinguishes between upper and
195lower case.
196.Lf cvttomaclisp
197.Se
198The reader is modified to conform with Maclisp syntax.
199The character / is made the escape character and the special meanings
200for backslash, left and right bracket are removed.
201The reader is made case-insensitive.
202.Lf cvttoucilisp
203.Se
204The reader is modified to conform with UCI Lisp syntax.
205The character / is made the escape character, tilde is made the comment
206character, exclamation point takes on the unquote function normally
207held by comma, and backslash, comma, semicolon become normal
208characters.
209Here too, the reader is made case-insensitive.
210.Lf debug "s_msg"
211.Se
212Enter the Fixit package described in Chapter 15.
213This package allows you to examine the evaluation stack in detail.
214To leave the Fixit package type 'ok'.
215.Lf debugging "'g_arg"
216.Se
217If g_arg is non-null,
218Franz unlinks the transfer tables, does a \fI(*rset\ t)\fP to turn on
219evaluation monitoring and sets the all-error catcher (ER%all) to be
220\fIdebug-err-handler\fP.
221If g_arg is nil,
222all of the above changes are undone.
223.Lf declare "[g_arg ...]"
224.Re
225nil
226.No
227this is a no-op to the evaluator.
228It has special meaning to the compiler (see Chapter 12).
229.Lf def "s_name (s_type l_argl g_exp1 ...)"
230.Wh
231s_type is one of lambda, nlambda, macro or lexpr.
232.Re
233s_name
234.Se
235This defines the function s_name to the lisp system.
236If s_type is nlambda or macro then the argument list l_argl must contain
237exactly one non-nil symbol.
238.Lf defmacro "s_name l_arg g_exp1 ..."
239.Lx defcmacro "s_name l_arg g_exp1 ..."
240.Re
241s_name
242.Se
243This defines the macro s_name.
244\fIdefmacro\fP makes it easy to write macros since it makes
245the syntax just like \fIdefun\fP.
246Further information on \fIdefmacro\fP is in \(sc8.3.2.
247\fIdefcmacro\fP defines compiler-only macros, or cmacros.
248A cmacro is stored on the property list of a
249symbol under the indicator \fBcmacro\fP.
250Thus a function can
251have a normal definition and a cmacro definition.
252For an example of the use of cmacros, see the definitions
253of nthcdr and nth in /usr/lib/lisp/common2.l
254.Lf defun "s_name [s_mtype] ls_argl g_exp1 ... "
255.Wh
256s_mtype is one of fexpr, expr, args or macro.
257.Re
258s_name
259.Se
260This defines the function s_name.
261.No
262this exists for Maclisp compatibility, it is just a macro which
263changes the defun form to the def form.
264An s_mtype of fexpr is converted to nlambda
265and of expr to lambda. Macro remains the same.
266If ls_arg1 is a non-nil symbol, then the type is assumed to be lexpr and
267ls_arg1 is the symbol which is bound to the number of args when the
268function is entered.
269.br
270For compatibility with the Lisp Machine Lisp, there are three types of
271optional parameters that can occur in ls_argl: \fI&optional\fP declares that
272the following symbols are optional, and may or may not appear in the
273argument list to the function, \fI&rest symbol\fP
274declares that all forms in the
275function call that are not accounted for by previous lambda bindings
276are to be assigned to \fIsymbol\fP, and \fI&aux form1 ... formn\fP
277declares that the \fIformi\fP are either symbols, in which case they
278are lambda bound to \fBnil\fP, or lists, in which case the first element
279of the list is lambda bound to the second, evaluated element.
280.Eb
281; \fIdef\fP and \fIdefun\fP here are used to define identical functions
282; you can decide for yourself which is easier to use.
283\-> \fI(def append1 (lambda (lis extra) (append lis (list extra))))\fP
284append1
285
286\-> \fI(defun append1 (lis extra) (append lis (list extra)))\fP
287append1
288
289; Using the & forms...
290\-> \fI(defu\kCn test (a b &optional c &aux (retval 0) &rest z)
291 \h'|\nCu'\kB(if c them (msg \kA"Optional arg present" N
292 \h'|\nAu'"c is " c N))
293 \h'|\nBu'(msg \kA"rest is " z N
294 \h'|\nAu'"retval is " retval N))\fP
295test
296\-> \fI(test 1 2 3 4)\fP
297Optional arg present
298c is 3
299rest is (4)
300retval is 0
301.Ee
302.Lf defvar "s_variable ['g_init]"
303.Re
304s_variable.
305.No
306This form is put at the top level in files, like \fIdefun\fB.
307.Se
308This declares s_variable to be special. If g_init is present
309and s_variable is unbound when the file is read in, s_variable
310will be set to the value of g_init.
311An advantage of `(defvar foo)' over `(declare (special foo))' is that if
312a file containing defvars is loaded (or fasl'ed) in during compilation,
313the variables mentioned in the defvar's will be declared special. The only
314way to have that effect with `(declare (special foo))' is to \fIinclude\fP
315the file.
316.Lf do "l_vrbs l_test g_exp1 ..."
317.Re
318the last form in the cdr of l_test evaluated, or a value explicitly given by
319a return evaluated within the do body.
320.No
321This is the basic iteration form for
322.Fr .
323l_vrbs is a list of zero or more var-init-repeat forms.
324A var-init-repeat form looks like:
325.br
326.tl ''(s_name [g_init [g_repeat]])''
327There are three cases depending on what is present in the form.
328If just s_name is present, this means that when the do is entered,
329s_name is lambda-bound to nil and is never modified by the system
330(though the program is certainly free to modify its value).
331If the form is (s_name\ 'g_init) then the only difference is that
332s_name is lambda-bound to the value of g_init instead of nil.
333If g_repeat is also present then s_name is lambda-bound to g_init
334when the loop is entered and after each pass through the do body
335s_name is bound to the value of g_repeat.
336.br
337l_test is either nil or has the form of a cond clause.
338If it is nil then the do body will be evaluated only once and the
339do will return nil.
340Otherwise, before the do body is evaluated the car of l_test is
341evaluated and if the result is non-null, this signals an end to
342the looping.
343Then the rest of the forms in l_test are evaluated
344and the value of the last one is returned as the value of the do.
345If the cdr of l_test is nil, then nil is returned -- thus this is not
346exactly like a cond clause.
347.br
348g_exp1 and those forms which follow constitute the do body.
349A do body is like a prog body and thus may have labels and one may
350use the functions go and return.
351.br
352The sequence of evaluations is this:
353.nr $p 0
354.np
355the init forms are evaluated left to right and stored in temporary
356locations.
357.np
358Simultaneously all do variables are lambda bound to the value of
359their init forms or nil.
360.np
361If l_test is non-null, then the car is evaluated and if it is non-null,
362the rest of the forms in l_test are evaluated and the last value is
363returned as the value
364of the do.
365.np
366The forms in the do body are evaluated left to right.
367.np
368If l_test is nil the do function returns with the value nil.
369.np
370The repeat forms are evaluated and saved in temporary locations.
371.np
372The variables with repeat forms are simultaneously
373bound to the values of those forms.
374.np
375Go to step 3.
376.No
377there is an alternate form of do which can be used when there is
378only one do variable.
379It is described next.
380.Eb
381; this is a simple function which numbers the elements of a list.
382; It uses a \fIdo\fP function with two local variables.
383\-> \fI(defun printem (lis)
384 (do ((xx lis (cdr xx))
385 (i 1 (1+ i)))
386 ((null xx) (patom "all done") (terpr))
387 (print i)
388 (patom ": ")
389 (print (car xx))
390 (terpr)))\fP
391printem
392\-> \fI(printem '(a b c d))\fP
3931: a
3942: b
3953: c
3964: d
397all done
398nil
399\->
400.Ee
401.Lf do "s_name g_init g_repeat g_test g_exp1 ..."
402.nr $p 0
403.No
404this is another, less general, form of do.
405It is evaluated by:
406.np
407evaluating g_init
408.np
409lambda binding s_name to value of g_init
410.np
411g_test is evaluated and if it is not nil the do function returns with nil.
412.np
413the do body is evaluated beginning at g_exp1.
414.np
415the repeat form is evaluated and stored in s_name.
416.np
417go to step 3.
418.Re
419nil
420.Lf environment "[l_when1 l_what1 l_when2 l_what2 ...]"
421.Lx environment-maclisp "[l_when1 l_what1 l_when2 l_what2 ...]"
422.Lx environment-lmlisp "[l_when1 l_what1 l_when2 l_what2 ...]"
423.Wh
424the when's are a subset of (eval compile load), and the symbols have the
425same meaning as they do in 'eval-when'.
426.br
427.sp
428The what's may be
429.br
430 (files file1 file2 ... fileN),
431.br
432which insure that the named files are loaded.
433To see if file\fIi\fP is loaded,
434it looks for a 'version' property under
435file\fIi\fP's property list. Thus to prevent multiple loading,
436you should put
437.br
438 (putprop 'myfile t 'version),
439.br
440at the end of myfile.l.
441.br
442.sp
443Another acceptable form for a what is
444.br
445(syntax type)
446.br
447Where type is either maclisp, intlisp, ucilisp, franzlisp.
448.Se
449\fIenvironment-maclisp\fP sets the environment to that which
450`liszt -m' would generate.
451.br
452.sp
453\fIenvironment-lmlisp\fP sets up the lisp machine environment. This is like
454maclisp but it has additional macros.
455.br
456.sp
457For these specialized environments, only the \fBfiles\fP clauses are useful.
458.Eg
459 (environment-maclisp (compile eval) (files foo bar))
460.Re
461the last list of files requested.
462.Lf err "['s_value [nil]]"
463.Re
464nothing (it never returns).
465.Se
466This causes an error and if this error is caught by an
467.i errset
468then that
469.i errset
470will return s_value instead of nil.
471If the second arg is given, then it must be nil (\s-2MAC\s0lisp
472compatibility).
473.Lf error "['s_message1 ['s_message2]]"
474.Re
475nothing (it never returns).
476.Se
477s_message1 and s_message2 are \fIpatom\fPed if they are given and
478then \fIerr\fP is called (with no arguments), which causes an error.
479.Lf errset "g_expr [s_flag]"
480.Re
481a list of one element, which is the value resulting from evaluating g_expr.
482If an error occurs during the evaluation of g_expr, then the locus of control
483will return to the
484.i errset
485which will then return nil (unless the error was caused by a call to
486.i err,
487with a non-null argument).
488.Se
489S_flag is evaluated before g_expr is evaluated.
490If s_flag is not given, then it is assumed to be t.
491If an error occurs during the evaluation of g_expr, and s_flag evaluated to
492a non-null value, then the error message associated with the
493error is printed before control returns to the errset.
494.Lf eval "'g_val ['x_bind-pointer]"
495.Re
496the result of evaluating g_val.
497.No
498The evaluator evaluates g_val in this way:
499.br
500If g_val is a symbol, then the evaluator returns its value.
501If g_val had never been assigned a value, then this causes
502an `Unbound Variable' error.
503If x_bind-pointer is given, then the variable is evaluated with
504respect to that pointer (see \fIevalframe\fP for details on bind-pointers).
505.br
506.sp
507If g_val is of type value, then its value is returned.
508If g_val is of any other type than list, g_val is returned.
509.br
510.sp
511If g_val is a list object then g_val is either a function call or
512array reference.
513Let g_car be the first element of g_val.
514We continually evaluate g_car until we end up with a symbol with
515a non-null function binding
516or a non-symbol.
517Call what we end up with: g_func.
518.br
519.sp
520G_func must be one of three types: list, binary or array.
521If it is a list then the first element of the list, which
522we shall call g_functype, must be either
523lambda, nlambda, macro or lexpr.
524If g_func is a binary, then its discipline, which we shall call
525g_functype, is either lambda, nlambda, macro or a string.
526If g_func is an array then this form is evaluated specially, see
527Chapter 9 on arrays.
528If g_func is a list or binary, then g_functype will determine how
529the arguments to this function, the cdr of g_val, are processed.
530If g_functype is a string, then this is a foreign function call (see \(sc8.5
531for more details).
532.br
533.sp
534If g_functype is lambda or lexpr, the arguments are evaluated
535(by calling
536.i eval
537recursively) and stacked.
538If g_functype is nlambda then the argument list is stacked.
539If g_functype is macro then the entire form, g_val is stacked.
540.br
541.sp
542Next, the formal variables are lambda bound.
543The formal variables are the cadr of g_func. If g_functype is
544nlambda, lexpr or macro, there should only be one formal variable.
545The values on the stack are lambda bound to the formal variables
546except in the case of a lexpr, where the number of actual arguments
547is bound to the formal variable.
548.br
549.sp
550After the binding is done, the function is invoked, either by
551jumping to the entry point in the case of a binary or
552by evaluating the list of forms beginning at cddr g_func.
553The result of this function invocation is returned as the value
554of the call to eval.
555.Lf evalframe "'x_pdlpointer"
556.Re
557an evalframe descriptor for the evaluation frame just before x_pdlpointer.
558If x_pdlpointer is nil, it returns the evaluation frame of the frame just
559before the current call to \fIevalframe\fP.
560.No
561An evalframe descriptor describes a call to \fIeval\fP, \fIapply\fP
562or \fIfuncall\fP.
563The form of the descriptor is
564.br
565\fI(type pdl-pointer expression bind-pointer np-index lbot-index)\fP
566.br
567where type is `eval' if this describes a call to \fIeval\fP or `apply'
568if this is a call to \fIapply\fP or \fIfuncall\fP.
569pdl-pointer is a number which describes
570this context.
571It can be passed to
572.i evalframe
573to obtain the next descriptor and
574can be passed to
575.i freturn
576to cause a return from this context.
577bind-pointer is the size of variable binding stack when this
578evaluation began.
579The bind-pointer can be given as a second argument
580to \fIeval\fP to order to evaluate variables in the same context as
581this evaluation.
582If type is `eval' then expression
583will have the form \fI(function-name\ arg1\ ...)\fP.
584If type is `apply' then expression will have the form
585\fI(function-name\ (arg1\ ...))\fP.
586np-index and lbot-index are pointers into the
587argument stack (also known as the \fInamestack\fP array) at the time of call.
588lbot-index points to the first argument, np-index points one beyond
589the last argument.
590.br
591In order for there to be enough information
592for \fIevalframe\fP to return, you must call \fI(*rset\ t)\fP.
593.Ex
594\fI(progn (evalframe nil))\fP
595.br
596returns \fI(eval 2147478600 (progn (evalframe nil)) 1 8 7)\fP
597.Lf evalhook "'g_form 'su_evalfunc ['su_funcallfunc]"
598.Re
599the result of evaluating g_form after lambda binding `evalhook' to
600su_evalfunc and, if it is given, lambda binding `funcallhook' to
601su_funcallhook.
602.No
603As explained in \(sc14.4, the function
604.i eval
605may pass the job of evaluating a form to a user `hook' function when
606various switches are set.
607The hook function normally prints the form to be evaluated on the
608terminal and then evaluates it by calling
609.i evalhook .
610.i Evalhook
611does the lambda binding mentioned above and then calls
612.i eval
613to evaluate the form after setting an internal switch to tell
614.i eval
615not to call the user's hook function just this one time.
616This allows the evaluation process to advance one step and yet
617insure that further calls to
618.i eval
619will cause traps to the hook function (if su_evalfunc is non-null).
620.br
621In order for \fIevalhook\fP to work, \fI(*rset\ t)\fP and
622\fI(sstatus\ evalhook\ t)\fP must have been done previously.
623.Lf exec "s_arg1 ..."
624.Re
625the result of forking and executing the command named by concatenating
626the s_arg\fIi\fP together with spaces in between.
627.Lf exece "'s_fname ['l_args ['l_envir]]"
628.Re
629the error code from the system if it was unable to
630execute the command s_fname with arguments
631l_args and with the environment set up as specified in l_envir.
632If this function is successful, it will not return, instead the lisp
633system will be overlaid by the new command.
634.Lf freturn "'x_pdl-pointer 'g_retval"
635.Re
636g_retval from the context given by x_pdl-pointer.
637.No
638A pdl-pointer denotes a certain expression currently being evaluated.
639The pdl-pointer for a given expression can be obtained from
640.i evalframe .
641.Lf frexp "'f_arg"
642.Re
643a list cell \fI(exponent . mantissa)\fP which represents the
644given flonum
645.No
646The exponent will be a fixnum, the mantissa a 56 bit bignum.
647If you think of the the binary point occurring right after the
648high order bit of mantissa, then
649f_arg\ =\ 2\*[exponent\*]\ *\ mantissa.
650.Lf funcall "'u_func ['g_arg1 ...]"
651.Re
652the value of applying function u_func to the arguments g_arg\fIi\fP
653and then evaluating that result if u_func is a macro.
654.No
655If u_func is a macro or nlambda then there should be only one g_arg.
656\fIfuncall\fP is the function which the evaluator uses to evaluate
657lists.
658If \fIfoo\fP is a lambda or lexpr or array,
659then \fI(funcall\ 'foo\ 'a\ 'b\ 'c)\fP
660is equivalent to \fI(foo\ 'a\ 'b\ 'c)\fP.
661If \fIfoo\fP is a nlambda
662then \fI(funcall\ 'foo\ '(a\ b\ c))\fP is equivalent to
663\fI(foo a b c)\fP.
664Finally, if
665.i foo
666is a macro then
667.i (funcall\ 'foo\ '(foo\ a\ b\ c))
668is equivalent to
669.i (foo\ a\ b\ c) .
670.Lf funcallhook "'l_form 'su_funcallfunc ['su_evalfunc]"
671.Re
672the result of \fIfuncall\fPing
673the \fI(car\ l_form)\fP
674on the already evaluated
675arguments in the \fI(cdr\ l_form)\fP
676after lambda binding `funcallhook' to
677su_funcallfunc and, if it is given, lambda binding `evalhook' to
678su_evalhook.
679.No
680This function is designed to continue the evaluation process
681with as little work as possible after a funcallhook trap has occurred.
682It is for this reason that the form of l_form is unorthodox: its
683.i car
684is the name of the function to call and its
685.i cdr
686are a list of arguments to stack (without evaluating again)
687before calling the given function.
688After stacking the arguments
689but
690before calling
691.i funcall
692an internal switch is set to prevent \fIfuncall\fP
693from passing the job of funcalling to su_funcallfunc.
694If \fIfuncall\fP is called recursively in funcalling l_form and
695if su_funcallfunc is non-null, then
696the arguments to
697.i funcall
698will actually be given to su_funcallfunc (a lexpr)
699to be funcalled.
700.br
701In order for \fIevalhook\fP to work, \fI(*rset\ t)\fP and
702\fI(sstatus\ evalhook\ t)\fP must have been done previously.
703A more detailed description of
704.i evalhook
705and
706.i funcallhook
707is given in Chapter 14.
708.Lf function "u_func"
709.Re
710the function binding of u_func if it is an symbol with a function binding
711otherwise u_func is returned.
712.Lf getdisc "'y_func"
713.Re
714the discipline of the machine coded function (either lambda, nlambda
715or macro).
716.Lf go "g_labexp"
717.Wh
718g_labexp is either a symbol or an expression.
719.Se
720If g_labexp is an expression, that expression is evaluated and
721should
722result in a symbol.
723The locus of control moves to just following the symbol g_labexp in the
724current prog or do body.
725.No
726this is only valid in the context of a prog or do body.
727The interpreter and compiler will allow non-local
728.i go 's
729although the compiler won't allow a \fIgo\fP to leave a function body.
730The compiler will not allow g_labexp to be an expression.
731.Lf if "'g_a 'g_b"
732.Lx if "'g_a 'g_b 'g_c ..."
733.Lx if "'g_a \fBthen\fP 'g_b [...] [\fBelseif\fP 'g_c \fBthen\fP 'g_d ...] [\fBelse\fP 'g_e [...]"
734.Lx if "'g_a \fBthen\fP 'g_b [...] [\fBelseif\fP 'g_c \fBthenret\fP] [\fBelse\fP 'g_d [...]"
735.No
736The various forms of \fIif\fP are intended to be a more readable
737conditional statement, to be used in place of \fIcond\fP. There
738are two varieties of \fIif\fP, with keywords, and without. The
739keyword-less variety is inherited from common Maclisp usage.
740A keyword-less, two argument \fIif\fP is equivalent to a one-clause
741\fIcond\fP, i.e. (\fIcond\fP (a b)). Any other keyword-less \fIif\fP
742must have at least three arguments. The first two arguments are the
743first clause of the equivalent \fIcond\fP, and all remaining arguments
744are shoved into a second clause beginning with \fBt\fP. Thus, the
745second form of \fIif\fP is equivalent to
746.br
747 (\fIcond\fP (a b) (t c ...)).
748.br
749.sp
750The keyword variety has the following grouping of arguments:
751a predicate, a then-clause, and optional
752else-clause. The predicate is evaluated, and if the result is
753non-nil, the then-clause will be performed, in the sense
754described below. Otherwise, (i.e. the result of the predicate
755evaluation was precisely nil), the else-clause will be performed.
756.br
757.sp
758Then-clauses will either consist entirely
759of the single keyword \fBthenret\fP, or will start with the keyword
760\fBthen\fP, and be followed by at least one general expression.
761(These general expressions must not be one of the keywords.)
762To actuate a \fBthenret\fP means to cease further evaluation
763of the \fIif\fP, and to return the value of the predicate just calculated.
764The performance of the longer clause means to evaluate each general expression
765in turn, and then return the last value calculated.
766.br
767.sp
768The else-clause may begin with the keyword \fBelse\fP and be followed
769by at least one general expression.
770The rendition of this clause is just like that of a then-clause.
771An else-clause
772may begin alternatively with the keyword \fBelseif\fP, and be followed
773(recursively) by a predicate, then-clause, and optional else-clause.
774Evaluation of this clause, is just evaluation of an \fIif\fP-form, with
775the same predicate, then- and else-clauses.
776.Lf I-throw-err "'l_token"
777.Wh
778l_token is the \fIcdr\fP of the value returned from a \fI*catch\fP with
779the tag ER%unwind-protect.
780.Re
781nothing (never returns in the current context)
782.Se
783The error or throw denoted by l_token is continued.
784.No
785This function is used to implement \fIunwind-protect\fP which allows the
786processing of a transfer of control though a certain context to be
787interrupted, a user function to be executed and than the transfer of
788control to continue.
789The form of l_token is either
790.br
791\fI(t tag value)\fP for a throw or
792.br
793\fI(nil type message valret contuab uniqueid [arg ...])\fP for an error.
794.br
795This function is not to be used for implementing throws or
796errors and is only documented here for completeness.
797.Lf let "l_args g_exp1 ... g_exprn"
798.Re
799the result of evaluating g_exprn within the bindings given by l_args.
800.No
801l_args is either nil (in which case
802.i let
803is just like
804.i progn )
805or it is a list of binding objects.
806A binding object is a list \fI(symbol\ expression)\fP.
807When a
808.i let
809is entered,
810all of the expressions are evaluated and then simultaneously
811lambda-bound to the corresponding symbols.
812In effect, a
813.i let
814expression is just like a lambda expression except the symbols and
815their initial values are next to each other, making the expression
816easier to understand.
817There are some added features to the
818.i let
819expression:
820A binding object can just be a symbol, in which case the expression
821corresponding to that symbol is `nil'.
822If a binding object is a list and the first element of that list is
823another list, then that list is assumed to be a binding template
824and
825.i let
826will do a
827.i desetq
828on it.
829.Lf let* "l_args g_exp1 ... g_expn"
830.Re
831the result of evaluating g_exprn within the bindings given by l_args.
832.No
833This is identical to
834.i let
835except the expressions in the binding list l_args are evaluated
836and bound sequentially instead of in parallel.
837.Lf lexpr-funcall "'g_function ['g_arg1 ...] 'l_argn"
838.No
839This is a cross between funcall and apply.
840The last argument, must be a list (possibly empty).
841The element of list arg are stack and then the function is
842funcalled.
843.Ex
844(lexpr-funcall 'list 'a '(b c d)) is the same as
845 (funcall 'list 'a 'b 'c 'd)
846.Lf listify "'x_count"
847.Re
848a list of x_count of the arguments to the current function (which
849must be a lexpr).
850.No
851normally arguments 1 through x_count are returned.
852If x_count is negative then a list of last abs(x_count) arguments are
853returned.
854.Lf map "'u_func 'l_arg1 ..."
855.Re
856l_arg1
857.No
858The function u_func is applied to successive sublists of the l_arg\fIi\fP.
859All sublists should have the same length.
860.\".pg
861.Lf mapc "'u_func 'l_arg1 ..."
862.Re
863l_arg1.
864.No
865The function u_func is applied to successive elements of the argument
866lists.
867All of the lists should have the same length.
868.Lf mapcan "'u_func 'l_arg1 ..."
869.Re
870nconc applied to the results of the functional evaluations.
871.No
872The function u_func is applied to successive elements of the
873argument lists.
874All sublists should have the same length.
875.Lf mapcar "'u_func 'l_arg1 ..."
876.Re
877a list of the values returned from the functional application.
878.No
879the function u_func is applied to successive elements of the
880argument lists.
881All sublists should have the same length.
882.Lf mapcon "'u_func 'l_arg1 ..."
883.Re
884nconc applied to the results of the functional evaluation.
885.No
886the function u_func is applied to successive sublists of the
887argument lists.
888All sublists should have the same length.
889.Lf maplist "'u_func 'l_arg1 ..."
890.Re
891a list of the results of the functional evaluations.
892.No
893the function u_func is applied to successive sublists of the arguments
894lists.
895All sublists should have the same length.
896.lp
897Readers may find the following summary table useful in remembering
898the differences between the six mapping functions:
899
900.TS
901box;
902c | c s s.
903\ Value returned is
904
905.T&
906c | c c c.
907T{
908.na
909Argument to functional is
910.ad
911T} l_arg1 list of results \fInconc\fP of results
912_
913.T&
914c | c c c.
915
916elements of list mapc mapcar mapcan
917
918sublists map maplist mapcon
919.TE
920.sp 2v
921.Lf mfunction "t_entry 's_disc"
922.Re
923a lisp object of type binary composed of t_entry and s_disc.
924.No
925t_entry is a pointer to the machine code for a function, and s_disc is the
926discipline (e.g. lambda).
927.\".pg
928.Lf oblist
929.Re
930a list of all symbols on the oblist.
931.Lf or "[g_arg1 ... ]"
932.Re
933the value of the first non-null argument or nil if all arguments
934evaluate to nil.
935.No
936Evaluation proceeds left to right and stops as soon as one of the arguments
937evaluates to a non-null value.
938.Lf prog "l_vrbls g_exp1 ..."
939.Re
940the value explicitly given in a return form
941or else nil if no return is done by the time the last g_exp\fIi\fP is
942evaluated.
943.No
944the local variables are lambda-bound to nil,
945then the g_exp\fIi\fP
946are evaluated from left to right.
947This is a prog body (obviously) and this means than
948any symbols seen are not evaluated,
949but are treated as labels.
950This also means that return's and go's are allowed.
951.Lf prog1 "'g_exp1 ['g_exp2 ...]"
952.Re
953g_exp1
954.Lf prog2 "'g_exp1 'g_exp2 ['g_exp3 ...]"
955.Re
956g_exp2
957.No
958the forms are evaluated from left to right and the value of g_exp2 is
959returned.
960.Lf progn "'g_exp1 ['g_exp2 ...]"
961.Re
962the last g_exp\fIi\fP.
963.Lf progv "'l_locv 'l_initv g_exp1 ..."
964.Wh
965l_locv is a list of symbols and l_initv is a list of expressions.
966.Re
967the value of the last g_exp\fIi\fP evaluated.
968.No
969The expressions in l_initv are evaluated from left to right
970and then lambda-bound to the symbols in l_locv.
971If there are too few expressions in l_initv then the missing values
972are assumed to be nil.
973If there are too many expressions in l_initv then the extra ones are
974ignored (although they are evaluated).
975Then the g_exp\fIi\fP are evaluated left to right.
976The body of a progv is like the body of a progn, it is
977.i not
978a prog body.
979(C.f.
980.i let )
981.Lf purcopy "'g_exp"
982.Re
983a copy of g_exp with new pure cells allocated wherever possible.
984.No
985pure space is never swept up by the garbage collector, so this should
986only be done on expressions which are not likely to become garbage
987in the future.
988In certain cases, data objects in pure space become read-only after
989a
990.i dumplisp
991and then an attempt to modify the object will result in an illegal memory
992reference.
993.Lf purep "'g_exp"
994.Re
995t iff the object g_exp is in pure space.
996.Lf putd "'s_name 'u_func"
997.Re
998u_func
999.Se
1000this sets the function binding of symbol s_name to u_func.
1001.Lf return "['g_val]"
1002.Re
1003g_val (or nil if g_val is not present) from the enclosing prog or do body.
1004.No
1005this form is only valid in the context of a prog or do body.
1006.Lf selectq "'g_key-form [l_clause1 ...]"
1007.No
1008This function is just like \fIcaseq\fP (see above), except that
1009the symbol \fBotherwise\fP has the same semantics as the
1010symbol \fBt\fP, when used as a comparator.
1011.Lf setarg "'x_argnum 'g_val"
1012.Wh
1013x_argnum is greater than zero and less than or equal to the number of
1014arguments to the lexpr.
1015.Re
1016g_val
1017.Se
1018the lexpr's x_argnum'th argument is set to g-val.
1019.No
1020this can only be used within the body of a lexpr.
1021.Lf throw "'g_val [s_tag]"
1022.Wh
1023if s_tag is not given, it is assumed to be nil.
1024.Re
1025the value of \fI(*throw 's_tag 'g_val)\fP.
1026.Lf *throw "'s_tag 'g_val"
1027.Re
1028g_val from the first enclosing catch with
1029the tag s_tag or with no tag at all.
1030.No
1031this is used in conjunction with
1032.i *catch
1033to cause a clean jump to an enclosing context.
1034.Lf unwind-protect "g_protected [g_cleanup1 ...]"
1035.Re
1036the result of evaluating g_protected.
1037.No
1038Normally g_protected is evaluated and its value
1039remembered, then the g_cleanup\fIi\fP
1040are evaluated and finally the saved value of g_protected is returned.
1041If something should happen when evaluating g_protected which causes
1042control to pass through g_protected and thus through
1043the call to the unwind-protect,
1044then the g_cleanup\fIi\fP will still be evaluated.
1045This is useful if g_protected does something sensitive which
1046must be cleaned up whether or not g_protected completes.