BSD 4_4 release
[unix-history] / usr / src / old / lisp / PSD.doc / ch2.n
CommitLineData
3edcb7c8
KB
1.\" Copyright (c) 1980 The Regents of the University of California.
2.\" All rights reserved.
6c8cfa35 3.\"
ad787160
C
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\" notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\" notice, this list of conditions and the following disclaimer in the
11.\" documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\" must display the following acknowledgement:
14.\" This product includes software developed by the University of
15.\" California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\" may be used to endorse or promote products derived from this software
18.\" without specific prior written permission.
3edcb7c8 19.\"
ad787160
C
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\" @(#)ch2.n 6.3 (Berkeley) 4/17/91
6c8cfa35 33.\"
5843f2f8
NC
34.\" $Header: ch2.n,v 1.7 83/07/30 14:42:38 layer Exp $
35.Lc Data\ Structure\ Access 2
36.pp
37The following functions allow one to create and manipulate the various types
38of lisp data structures.
39Refer to \(sc1.2 for details of the data structures known to
40.Fr .
41.sh 2 Lists \n(ch 1
42.pp
43The following functions exist for the creation and manipulating of lists.
44Lists are composed of a linked list of objects called
45either 'list cells', 'cons cells' or 'dtpr cells'.
46Lists are normally terminated with the special symbol
47.b nil .
48.b nil
49is both a symbol and a representation for the empty list ().
50.sh 3 list\ creation
51.Lf cons "'g_arg1 'g_arg2"
52.Re
53a new list cell whose car is g_arg1 and whose cdr is g_arg2.
54.Lf xcons "'g_arg1 'g_arg2"
55.Eq
56\fI(cons 'g_arg2 'g_arg1)\fP
57.Lf ncons "'g_arg"
58.Eq
59\fI(cons 'g_arg nil)\fP
60.Lf list "['g_arg1 ... ]"
61.Re
62a list whose elements are the g_arg\fIi\fP.
63.Lf append "'l_arg1 'l_arg2"
64.Re
65a list containing the elements of l_arg1 followed by l_arg2.
66.No
67To generate the result, the top level list cells of l_arg1 are duplicated
68and the cdr of the last list cell is set to point to l_arg2.
69Thus this is an expensive operation if l_arg1 is large.
70See the descriptions of
71.i nconc
72and
73.i tconc
74for cheaper ways of doing the
75.i append
76if the list l_arg1 can be altered.
77.Lf append1 "'l_arg1 'g_arg2"
78.Re
79a list like l_arg1 with g_arg2 as the last element.
80.No
81this is equivalent to (append 'l_arg1 (list 'g_arg2)).
82.Eb
83; A common mistake is using append to add one element to the end of a list
84\-> \fI(append '(a b c d) 'e)\fP
85(a b c d . e)
86; The user intended to say:
87\-> \fI(append '(a b c d) '(e))
88(a b c d e)
89; better is append1
90\-> \fI(append1 '(a b c d) 'e)\fP
91(a b c d e)
92.Ee
93.Lf quote! "[g_qform\fIi\fP] ...[! 'g_eform\fIi\fP] ... [!! 'l_form\fIi\fP] ..."
94.Re
95The list resulting from the splicing and insertion process
96described below.
97.No
98.i quote!
99is the complement of the
100.i list
101function.
102.i list
103forms a list by evaluating each for in the argument list; evaluation is
104suppressed if the form is \fIquote\fPed. In
105.i quote!,
106each form is implicitly \fIquote\fPed. To be evaluated, a form
107must be preceded by one of the evaluate operations ! and !!. ! g_eform
108evaluates g_form and the value is inserted in the place of the call;
109!! l_form evaluates l_form and the value is spliced into the place of
110the call.
111.br
112.sp
113`Splicing in' means that the parentheses surrounding the list are removed
114as the example below shows.
115Use of the evaluate operators can occur at any level in a
116form argument.
117.br
118.sp
119Another way to get the effect of the \fIquote!\fP function is to use
120the backquote character macro (see \(sc 8.3.3).
121.Eb
122\fI(quote! cons ! (cons 1 2) 3) = (cons (1 . 2) 3)\fP
123\fI(quote! 1 !! (list 2 3 4) 5) = (1 2 3 4 5)\fP
124\fI(setq quoted 'evaled)(quote! ! ((I am ! quoted))) = ((I am evaled))\fP
125\fI(quote! try ! '(this ! one)) = (try (this ! one))\fP
126.Ee
127
128.Lf bignum-to-list "'b_arg"
129.Re
130A list of the fixnums which are used to represent the bignum.
131.No
132the inverse of this function is
133.i list-to-bignum.
134.Lf list-to-bignum "'l_ints"
135.Wh
136l_ints is a list of fixnums.
137.Re
138a bignum constructed of the given fixnums.
139.No
140the inverse of this function is
141.i bignum-to-list.
142
143.sh 3 list\ predicates
144.Lf dtpr "'g_arg"
145.Re
146t iff g_arg is a list cell.
147.No
148that (dtpr '()) is nil. The name \fBdtpr\fP is
149a contraction for ``dotted pair''.
150.Lf listp "'g_arg"
151.Re
152t iff g_arg is a list object or nil.
153.Lf tailp "'l_x 'l_y"
154.Re
155l_x, if a list cell
156.i eq
157to l_x is found by
158.i cdr ing
159down l_y zero or more times, nil otherwise.
160.Eb
161\-> \fI(setq x '(a b c d) y (cddr x))\fP
162(c d)
163\-> \fI(and (dtpr x) (listp x))\fP ; x and y are dtprs and lists
164t
165\-> \fI(dtpr '())\fP ; () is the same as nil and is not a dtpr
166nil
167\-> \fI(listp '())\fP ; however it is a list
168t
169\-> \fI(tailp y x)\fP
170(c d)
171.Ee
172.Lf length "'l_arg"
173.Re
174the number of elements in the top level of list l_arg.
175.sh 3 list\ accessing
176.Lf car "'l_arg"
177.Lx cdr "'l_arg"
178.Re the appropriate part of
179.i cons
180cell.
181(\fIcar\fP (\fIcons\fP x y)) is always x,
182(\fIcdr\fP (\fIcons\fP x y)) is always y.
183In
184.Fr ,
185the cdr portion is located first in memory.
186This is hardly noticeable, and we mention it
187primarily as a curiosity.
188.Lf c\.\.r "'lh_arg"
189.Wh
190the .. represents any positive number of \fBa\fP's and \fBd\fP's.
191.Re
192the result of accessing the list structure in the way determined by
193the function name.
194The \fBa\fP's and \fBd\fP's are read from right to left, a
195.b d
196directing the access down the cdr part of the list cell and an
197.b a
198down the car part.
199.No
200lh_arg may also be nil, and it is guaranteed that the car and cdr of nil
201is nil.
202If lh_arg is a hunk, then \fI(car\ 'lh_arg)\fP is the same as
203\fI(cxr\ 1\ 'lh_arg)\fP and \fI(cdr\ 'lh_arg)\fP is the same
204as \fI(cxr\ 0\ 'lh_arg)\fP.
205.br
206It is generally hard to read and understand the context
207of functions with large strings of
208.b a 's
209and
210.b d 's,
211but these functions are supported by rapid accessing and open-compiling
212(see Chapter 12).
213.Lf nth "'x_index 'l_list"
214.Re
215the nth element of l_list, assuming zero-based index.
216Thus (nth 0 l_list) is the same as (car l_list).
217.i nth
218is both a function, and a compiler macro, so that
219more efficient code might be generated than for
220.i nthelem
221(described below).
222.No
223If x_arg1 is non-positive or greater than the length
224of the list, nil is returned.
225.Lf nthcdr "'x_index 'l_list"
226.Re
227the result of \fIcdr\fPing down the list l_list x_index times.
228.No
229If x_index is less than 0, then \fI(cons\ nil\ 'l_list)\fP is returned.
230.Lf nthelem "'x_arg1 'l_arg2"
231.Re
232The x_arg1'\fIst\fP element of the list l_arg2.
233.No
234This function comes from the PDP-11 Lisp system.
235.Lf last "'l_arg"
236.Re
237the last list cell in the list l_arg.
238.Ex
239\fIlast\fP does NOT return the last element of a list!
240.br
241\fI(last '(a b))\fP = (b)
242.Lf ldiff "'l_x 'l_y"
243.Re
244a list of all
245elements in l_x but not in l_y
246, i.e., the list difference of
247l_x and l_y.
248.No
249l_y must be a tail of l_x, i.e.,
250.i eq
251to the result of applying some number of \fIcdr\fP's
252to l_x.
253Note that the value of \fIldiff\fP is always new list
254structure unless l_y is nil, in which case \fI(ldiff l_x nil)\fP is l_x
255itself.
256If l_y is not a tail of l_x, \fIldiff\fP generates an error.
257.Ex
258\fI(ldiff 'l_x (member 'g_foo 'l_x))\fP gives all elements
259in l_x up to the first g_foo.
260.sh 3 list\ manipulation
261.Lf rplaca "'lh_arg1 'g_arg2"
262.Re
263the modified lh_arg1.
264.Se
265the car of lh_arg1 is set to g_arg2.
266If lh_arg1 is a hunk then the second element of the hunk is set to g_arg2.
267.Lf rplacd "'lh_arg1 'g_arg2"
268.Re
269the modified lh_arg1.
270.Se
271the cdr of lh_arg2 is set to g_arg2.
272If lh_arg1 is a hunk then the first element of the hunk is set to g_arg2.
273
274.Lf attach "'g_x 'l_l"
275.Re
276l_l whose
277.i car
278is now g_x, whose
279.i cadr
280is the original \fI(car\ l_l)\fP,
281and whose
282.i cddr
283is the original \fI(cdr\ l_l)\fP.
284.No
285what happens is that g_x is added to the
286beginning of list l_l yet maintaining the same list cell at the
287beginning of the list.
288.Lf delete "'g_val 'l_list ['x_count]"
289.Re
290the result of splicing g_val from the top level of
291l_list no more than x_count times.
292.No
293x_count defaults to a very large number, thus if x_count is not given, all
294occurrences of g_val are removed from the top level of l_list.
295g_val is compared with successive
296.i car 's
297of l_list using the function
298.i equal .
299.Se
300l_list is modified using rplacd, no new list cells are used.
301.Lf delq "'g_val 'l_list ['x_count]"
302.Lx dremove "'g_val 'l_list ['x_count]"
303.Re
304the result of splicing g_val from the top level of l_list no more than
305x_count times.
306.No
307.i delq
308(and
309.i dremove )
310are the same as
311.i delete
312except that
313.i eq
314is used for comparison instead of
315.i equal .
316.Eb
317; note that you should use the value returned by \fIdelete\fP or \fIdelq\fP
318; and not assume that g_val will always show the deletions.
319; For example
320
321\-> \fI(setq test '(a b c a d e))\fP
322(a b c a d e)
323\-> \fI(delete 'a test)\fP
324(b c d e) ; the value returned is what we would expect
325\-> \fItest\fP
326(a b c d e) ; but test still has the first a in the list!
327.Ee
328.Lf remq "'g_x 'l_l ['x_count]"
329.Lx remove "'g_x 'l_l"
330.Re
331a
332.i copy
333of l_l with all top level elements
334.i equal
335to g_x removed.
336.i remq
337uses
338.i eq
339instead of
340.i equal
341for comparisons.
342.No
343remove does not modify its arguments like
344.i delete ,
345and
346.i delq
347do.
348.Lf insert "'g_object 'l_list 'u_comparefn 'g_nodups"
349.Re
350a list consisting of l_list with g_object destructively inserted
351in a place determined by the ordering function u_comparefn.
352.No
353\fI(comparefn 'g_x 'g_y)\fP
354should return something non-nil if g_x can precede g_y in sorted order,
355nil if g_y must precede g_x.
356If u_comparefn is nil, alphabetical order
357will be used.
358If g_nodups is non-nil, an element will not be inserted if an
359equal element is already in the list.
360.i insert
361does binary search to determine where to insert the new element.
362.Lf merge "'l_data1 'l_data2 'u_comparefn"
363.Re
364the merged list of the two input sorted lists l_data1 and l_data1
365using binary comparison function u_comparefn.
366.No
367\fI(comparefn 'g_x 'g_y)\fP
368should return something non-nil if g_x can precede g_y in sorted order,
369nil if g_y must precede g_x. If u_comparefn is nil,
370alphabetical order
371will be used. u_comparefn should be thought of as "less than or equal".
372.i merge
373changes both of its data arguments.
374.Lf subst "'g_x 'g_y 'l_s"
375.Lx dsubst "'g_x 'g_y 'l_s"
376.Re
377the result of substituting g_x for all
378.i equal
379occurrences of g_y at all levels in l_s.
380.No
381If g_y is a symbol,
382.i eq
383will be used for comparisons.
384The function
385.i subst
386does not modify l_s
387but the function
388.i dsubst
389(destructive substitution)
390does.
391.Lf lsubst "'l_x 'g_y 'l_s"
392.Re
393a copy of l_s with l_x spliced in for every occurrence of of g_y
394at all levels.
395Splicing in means that the parentheses surrounding the list l_x are removed
396as the example below shows.
397.Eb
398\-> \fI(subst '(a b c) 'x '(x y z (x y z) (x y z)))\fP
399((a b c) y z ((a b c) y z) ((a b c) y z))
400\-> \fI(lsubst '(a b c) 'x '(x y z (x y z) (x y z)))\fP
401(a b c y z (a b c y z) (a b c y z))
402.Ee
403.Lf subpair "'l_old 'l_new 'l_expr"
404.Wh
405there are the same number of elements in l_old as l_new.
406.Re
407the list l_expr with all occurrences of a object in l_old replaced by
408the corresponding one in l_new.
409When a substitution is made, a copy of the value to substitute in
410is not made.
411.Ex
412\fI(subpair '(a c)' (x y) '(a b c d)) = (x b y d)\fP
413
414.Lf nconc "'l_arg1 'l_arg2 ['l_arg3 ...]"
415.Re
416A list consisting of the elements of l_arg1 followed by the elements of
417l_arg2 followed by l_arg3 and so on.
418.No
419The
420.i cdr
421of the last list cell of l_arg\fIi\fP is changed to point to
422l_arg\fIi+1\fP.
423.Eb
424; \fInconc\fP is faster than \fIappend\fP because it doesn't allocate new list cells.
425\-> \fI(setq lis1 '(a b c))\fP
426(a b c)
427\-> \fI(setq lis2 '(d e f))\fP
428(d e f)
429\-> \fI(append lis1 lis2)\fP
430(a b c d e f)
431\-> \fIlis1\fP
432(a b c) ; note that lis1 has not been changed by \fIappend\fP
433\-> \fI(nconc lis1 lis2)\fP
434(a b c d e f) ; \fInconc\fP returns the same value as \fIappend\fP
435\-> \fIlis1\fP
436(a b c d e f) ; but in doing so alters lis1
437.Ee
438
439.Lf reverse "'l_arg"
440.Lx nreverse "'l_arg"
441.Re
442the list l_arg with the elements at the top
443level in reverse order.
444.No
445The function
446.i nreverse
447does the reversal in place,
448that is the list structure is modified.
449.Lf nreconc "'l_arg 'g_arg"
450.Eq
451\fI(nconc (nreverse 'l_arg) 'g_arg)\fP
452
453.sh 2 Predicates
454.pp
455The following functions test for properties of data objects.
456When the result of the test is either 'false' or 'true', then
457\fBnil\fP will be returned for 'false' and something other than
458\fBnil\fP (often \fBt\fP) will be returned for 'true'.
459.Lf arrayp "'g_arg"
460.Re
461t iff g_arg is of type array.
462.Lf atom "'g_arg"
463.Re
464t iff g_arg is not a list or hunk object.
465.No
466\fI(atom '())\fP returns t.
467.Lf bcdp "'g_arg"
468.Re
469t iff g_arg is a data object of type binary.
470.No
471This function is a throwback to the PDP-11 Lisp system.
472The name stands for binary code predicate.
473.Lf bigp "'g_arg"
474.Re
475t iff g_arg is a bignum.
476.Lf dtpr "'g_arg"
477.Re
478t iff g_arg is a list cell.
479.No
480that (dtpr '()) is nil.
481.Lf hunkp "'g_arg"
482.Re
483t iff g_arg is a hunk.
484.Lf listp "'g_arg"
485.Re
486t iff g_arg is a list object or nil.
487.Lf stringp "'g_arg"
488.Re
489t iff g_arg is a string.
490.Lf symbolp "'g_arg"
491.Re
492t iff g_arg is a symbol.
493.Lf valuep "'g_arg"
494.Re
495t iff g_arg is a value cell
496.Lf vectorp 'v_vector
497.Re
498\fBt\fP iff the argument is a vector.
499.Lf vectorip 'v_vector
500.Re
501\fBt\fP iff the argument is an immediate-vector.
502.Lf type "'g_arg"
503.Lx typep "'g_arg"
504.Re
505a symbol whose pname describes the type of g_arg.
506.Lf signp "s_test 'g_val"
507.Re
508t iff g_val is a number and the given test s_test on g_val returns true.
509.No
510The fact that
511.i signp
512simply returns nil if g_val is not a number is probably the most
513important reason that
514.i signp
515is used.
516The permitted values for s_test and what they mean are given in this table.
5f60f95f 517.(b
5843f2f8
NC
518.TS
519center box;
520l l .
521s_test tested
522
523=
524l g_val < 0
525le g_val \(<= 0
526e g_val = 0
527n g_val \(!= 0
528ge g_val \(>= 0
529g g_val > 0
530.TE
5f60f95f 531.)b
5843f2f8
NC
532.Lf eq "'g_arg1 'g_arg2"
533.Re
534t if g_arg1 and g_arg2 are the exact same lisp object.
535.No
536.i Eq
537simply tests if g_arg1 and g_arg2 are located in the exact same
538place in memory.
539Lisp objects which print the same are not necessarily
540.i eq .
541The only objects guaranteed to be
542.i eq
543are interned symbols with the same print name.
544[Unless a symbol is created in a special way (such as with
545.i uconcat
546or
547.i maknam )
548it will be interned.]
549.Lf neq "'g_x 'g_y"
550.Re
551t if g_x is not
552.i eq
553to g_y, otherwise nil.
554.Lf equal "'g_arg1 'g_arg2"
555.Lx eqstr "'g_arg1 'g_arg2"
556.Re
557t iff g_arg1 and g_arg2 have the same structure as described below.
558.No
559g_arg and g_arg2 are
560.i equal
561if
562.np
563they are \fIeq\fP.
564.np
565they are both fixnums with the same value
566.np
567they are both flonums with the same value
568.np
569they are both bignums with the same value
570.np
571they are both strings and are identical.
572.np
573they are both lists and their cars and cdrs are
574.i equal .
575.Eb
576; \fIeq\fP is much faster than \fIequal\fP, especially in compiled code,
577; however you cannot use \fIeq\fP to test for equality of numbers outside
578; of the range -1024 to 1023. \fIequal\fP will always work.
579\-> \fI(eq 1023 1023)\fP
580t
581\-> \fI(eq 1024 1024)\fP
582nil
583\-> \fI(equal 1024 1024)\fP
584t
585.Ee
586
587.Lf not "'g_arg"
588.Lx null "'g_arg"
589.Re
590t iff g_arg is nil.
591
592.Lf member "'g_arg1 'l_arg2"
593.Lx memq "'g_arg1 'l_arg2"
594.Re
595that part of the l_arg2 beginning with the first occurrence
596of g_arg1.
597If g_arg1 is not in the top level of l_arg2, nil is returned.
598.No
599.i member
600tests for equality with
601.i equal ,
602.i memq
603tests for equality with
604.i eq .
605
606.sh 2 Symbols\ and\ Strings
607.pp
608In many of the following functions the distinction between symbols and
609strings is somewhat blurred.
610To remind ourselves of the difference,
611a string is a null terminated sequence of characters, stored as
612compactly as possible.
613Strings are used as constants in
614.Fr .
615They
616.i eval
617to themselves.
618A symbol has additional structure:
619a value, property list, function binding,
620as well as its external representation (or print-name).
621If a symbol is given to one of the string manipulation functions below, its
622print name will be used as the string.
623.pp
624Another popular way to represent strings in Lisp is as a list of fixnums
625which represent characters.
626The suffix 'n' to a string manipulation function indicates that it
627returns a string in this form.
628.sh 3 symbol\ and\ string\ creation
629.Lf concat "['stn_arg1 ... ]"
630.Lx uconcat "['stn_arg1 ... ]"
631.Re
632a symbol whose print name
633is the result of concatenating the print names,
634string characters or numerical representations
635of the sn_arg\fIi\fP.
636.No
637If no arguments are given, a symbol with a null pname is returned.
638\fIconcat\fP places the symbol created on the oblist, the function
639.i uconcat
640does the same thing but does not place the new symbol on the oblist.
641.Ex
642\fI(concat 'abc (add 3 4) "def")\fP = abc7def
643.Lf concatl "'l_arg"
644.Eq
645\fI(apply 'concat 'l_arg)\fP
646
647.Lf implode "'l_arg"
648.Lx maknam "'l_arg"
649.Wh
650l_arg is a list of symbols, strings and small fixnums.
651.Re
652The symbol whose print name is the result of concatenating the
653first characters of the print names of the symbols and strings
654in the list.
655Any fixnums are converted to the equivalent ascii character.
656In order to concatenate entire strings or print names, use the
657function
658.i concat .
659.No
660.i implode
661interns the symbol it creates,
662.i maknam
663does not.
664.Lf gensym "['s_leader]"
665.Re
666a new uninterned atom beginning with the first character of s_leader's
667pname, or beginning with g if s_leader is not given.
668.No
669The symbol looks like x0nnnnn where x is s_leader's first character and
670nnnnn is the number of times you have called gensym.
671.Lf copysymbol "'s_arg 'g_pred"
672.Re
673an uninterned symbol with the same print name as s_arg.
674If g_pred is non nil, then the value, function binding
675and property list of the new symbol are made
676.i eq
677to those of s_arg.
678
679.Lf ascii "'x_charnum"
680.Wh
681x_charnum is between 0 and 255.
682.Re
683a symbol whose print name is the single character whose fixnum
684representation is x_charnum.
685
686.Lf intern "'s_arg"
687.Re
688s_arg
689.Se
690s_arg is put on the oblist if it is not already there.
691.Lf remob "'s_symbol"
692.Re
693s_symbol
694.Se
695s_symbol is removed from the oblist.
696.Lf rematom "'s_arg"
697.Re
698t if s_arg is indeed an atom.
699.Se
700s_arg is put on the free atoms list, effectively reclaiming an
701atom cell.
702.No
703This function does
704.i not
705check to see if s_arg is on the oblist or is referenced anywhere.
706Thus calling
707.i rematom
708on an atom in the oblist may result in disaster when that atom cell
709is reused!
710.sh 3 string\ and\ symbol\ predicates
711.Lf boundp "'s_name"
712.Re
713nil if s_name is unbound: that is, it has never been given a value.
714If x_name has the value g_val, then (nil\ .\ g_val) is returned.
715See also
716.i makunbound .
717.Lf alphalessp "'st_arg1 'st_arg2"
718.Re
719t iff the `name' of st_arg1 is alphabetically less than the
720name of st_arg2.
721If st_arg is a symbol then its `name' is its print name.
722If st_arg is a string, then its `name' is the string itself.
723.sh 3 symbol\ and\ string\ accessing
724.Lf symeval "'s_arg"
725.Re
726the value of symbol s_arg.
727.No
728It is illegal to ask for the value of an unbound symbol.
729This function has the same effect as
730.i eval ,
731but compiles into much more efficient code.
732.Lf get_pname "'s_arg"
733.Re
734the string which is the print name of s_arg.
735.Lf plist "'s_arg"
736.Re
737the property list of s_arg.
738.Lf getd "'s_arg"
739.Re
740the function definition of s_arg or nil if there is no function definition.
741.No
742the function definition may turn out to be an array header.
743.Lf getchar "'s_arg 'x_index"
744.Lx nthchar "'s_arg 'x_index"
745.Lx getcharn "'s_arg 'x_index"
746.Re
747the x_index\fIth\fP character of the print name of s_arg or nil if x_index
748is less than 1 or greater than the length of s_arg's print name.
749.No
750.i getchar
751and
752.i nthchar
753return a symbol with a single character print name,
754.i getcharn
755returns the fixnum representation of the character.
756.Lf substring "'st_string 'x_index ['x_length]"
757.Lx substringn "'st_string 'x_index ['x_length]"
758.Re
759a string of length at most
760x_length starting at x_index\fIth\fP character
761in the string.
762.No
763If x_length is not given, all of the characters for x_index
764to the end of the string are returned.
765If x_index is negative the string begins at the
766x_index\fIth\fP character from the end.
767If x_index is out of bounds, nil is returned.
768.No
769.i substring
770returns a list of symbols,
771.i substringn
772returns a list of fixnums.
773If
774.i substringn
775is given a 0 x_length argument then a single fixnum
776which is the x_index\fIth\fP character is returned.
777.sh 3 symbol\ and\ string\ manipulation
778.Lf set "'s_arg1 'g_arg2"
779.Re
780g_arg2.
781.Se
782the value of s_arg1 is set to g_arg2.
783.Lf setq "s_atm1 'g_val1 [ s_atm2 'g_val2 ... ... ]"
784.Wh
785the arguments are pairs of atom names and expressions.
786.Re
787the last g_val\fIi\fP.
788.Se
789each s_atm\fIi\fP is set to have the value g_val\fIi\fP.
790.No
791.i set
792evaluates all of its arguments,
793.i setq
794does not evaluate the s_atm\fIi\fP.
795.Lf desetq "sl_pattern1 'g_exp1 [... ...]"
796.Re
797g_expn
798.Se
799This acts just like \fIsetq\fP if all the sl_pattern\fIi\fP are symbols.
800If sl_pattern\fIi\fP is a list then it is a template which should
801have the same structure as g_exp\fIi\fP
802The symbols in sl_pattern are assigned to the corresponding
803parts of g_exp.
804(See also
805.i setf
806)
807.Ex
808\fI(desetq (a b (c . d)) '(1 2 (3 4 5)))\fP
809.br
810sets a to 1, b to 2, c to 3, and d to (4 5).
811
812.Lf setplist "'s_atm 'l_plist"
813.Re
814l_plist.
815.Se
816the property list of s_atm is set to l_plist.
817.Lf makunbound "'s_arg"
818.Re
819s_arg
820.Se
821the value of s_arg is made `unbound'.
822If the interpreter attempts to evaluate s_arg before it is again
823given a value, an unbound variable error will occur.
824.Lf aexplode "'s_arg"
825.Lx explode "'g_arg"
826.Lx aexplodec "'s_arg"
827.Lx explodec "'g_arg"
828.Lx aexploden "'s_arg"
829.Lx exploden "'g_arg"
830.Re
831a list of the characters used to print out s_arg or g_arg.
832.No
833The functions beginning with 'a' are internal functions which are limited
834to symbol arguments.
835The functions
836.i aexplode
837and
838.i explode
839return a list of characters which
840.i print
841would use to print the argument.
842These characters include all necessary escape characters.
843Functions
844.i aexplodec
845and
846.i explodec
847return a list of characters which
848.i patom
849would use to print the argument (i.e. no escape characters).
850Functions
851.i aexploden
852and
853.i exploden
854are similar to
855.i aexplodec
856and
857.i explodec
858except that a list of fixnum equivalents of characters are returned.
859.Eb
860\-> \fI(setq x '|quote this \e| ok?|)\fP
861|quote this \e| ok?|
862\-> \fI(explode x)\fP
863(q u o t e |\e\e| | | t h i s |\e\e| | | |\e\e| |\e|| |\e\e| | | o k ?)
864; note that |\e\e| just means the single character: backslash.
865; and |\e|| just means the single character: vertical bar
866; and | | means the single character: space
867
868\-> \fI(explodec x)\fP
869(q u o t e | | t h i s | | |\e|| | | o k ?)
870\-> \fI(exploden x)\fP
871(113 117 111 116 101 32 116 104 105 115 32 124 32 111 107 63)
872.Ee
873.sh 2 Vectors
874.pp
875See Chapter 9 for a discussion of vectors.
876They are less efficient that hunks but more efficient than arrays.
877.sh 3 vector\ creation
878.Lf new-vector "'x_size ['g_fill ['g_prop]]"
879.Re
880A \fBvector\fP of length x_size.
881Each data entry is initialized to g_fill, or to nil, if the argument g_fill
882is not present.
883The vector's property is set to g_prop, or to nil, by default.
884.Lf new-vectori-byte "'x_size ['g_fill ['g_prop]]"
885.Lx new-vectori-word "'x_size ['g_fill ['g_prop]]"
886.Lx new-vectori-long "'x_size ['g_fill ['g_prop]]"
887.Re
888A \fBvectori\fP with x_size elements in it.
889The actual memory requirement is two long words + x_size*(n bytes),
890where n is 1 for new-vector-byte, 2 for new-vector-word, or 4 for
891new-vectori-long.
892Each data entry is initialized to g_fill, or to zero, if the argument g_fill
893is not present.
894The vector's property is set to g_prop, or nil, by default.
895.sp 2v
896.lp
897Vectors may be created by specifying multiple initial values:
898.Lf vector "['g_val0 'g_val1 ...]"
899.Re
900a \fBvector\fP, with as many data elements as there are arguments.
901It is quite possible to have a vector with no data elements.
902The vector's property will be a null list.
903.Lf vectori-byte "['x_val0 'x_val2 ...]"
904.Lx vectori-word "['x_val0 'x_val2 ...]"
905.Lx vectori-long "['x_val0 'x_val2 ...]"
906.Re
907a \fBvectori\fP, with as many data elements as there are arguments.
908The arguments are required to be fixnums.
909Only the low order byte or word is used in the case of vectori-byte
910and vectori-word.
911The vector's property will be null.
912.sh 3 vector\ reference
913.Lf vref "'v_vect 'x_index"
914.Lx vrefi-byte "'V_vect 'x_bindex"
915.Lx vrefi-word "'V_vect 'x_windex"
916.Lx vrefi-long "'V_vect 'x_lindex"
917.Re
918the desired data element from a vector.
919The indices must be fixnums.
920Indexing is zero-based.
921The vrefi functions sign extend the data.
922.Lf vprop 'Vv_vect
923.Re
924The Lisp property associated with a vector.
925.Lf vget "'Vv_vect 'g_ind"
926.Re
927The value stored under g_ind if the Lisp property associated
928with 'Vv_vect is a disembodied property list.
929.Lf vsize 'Vv_vect
930.Lx vsize-byte 'V_vect
931.Lx vsize-word 'V_vect
932.Re
933the number of data elements in the vector. For immediate-vectors,
934the functions vsize-byte and vsize-word return the number of data elements,
935if one thinks of the binary data as being comprised of bytes or words.
936.sh 3 vector\ modfication
937.Lf vset "'v_vect 'x_index 'g_val"
938.Lx vseti-byte "'V_vect 'x_bindex 'x_val"
939.Lx vseti-word "'V_vect 'x_windex 'x_val"
940.Lx vseti-long "'V_vect 'x_lindex 'x_val"
941.Re
942the datum.
943.Se
944The indexed element of the vector is set to the value.
945As noted above, for vseti-word and vseti-byte, the index
946is construed as the number of the data element within
947the vector. It is not a byte address.
948Also, for those two functions,
949the low order byte or word of x_val is what is stored.
950.Lf vsetprop "'Vv_vect 'g_value"
951.Re
952g_value. This should be either a symbol
953or a disembodied property list whose
954.i car
955is a symbol identifying the type of
956the vector.
957.Se
958the property list of Vv_vect is set to g_value.
959.Lf vputprop "'Vv_vect 'g_value 'g_ind"
960.Re
961g_value.
962.Se
963If the vector property of Vv_vect is a disembodied property list,
964then vputprop adds the value g_value under the indicator g_ind.
965Otherwise, the old vector property is made the first
966element of the list.
967.sh 2 Arrays
968.pp
969See Chapter 9 for a complete description of arrays.
970Some of these functions are part of a Maclisp array
971compatibility package representing only one simple way of using the
972array structure of
973.Fr .
974.sh 3 array\ creation
975.Lf marray "'g_data 's_access 'g_aux 'x_length 'x_delta"
976.Re
977an array type with the fields set up from the above arguments
978in the obvious way (see \(sc 1.2.10).
979.Lf *array "'s_name 's_type 'x_dim1 ... 'x_dim\fIn\fP"
980.Lx array "s_name s_type x_dim1 ... x_dim\fIn\fP"
981.Wh
982s_type may be one of t, nil, fixnum, flonum, fixnum-block and
983flonum-block.
984.Re
985an array of type s_type with n dimensions of extents given by the
986x_dim\fIi\fP.
987.Se
988If s_name is non nil, the function definition of s_name is
989set to the array structure returned.
990.No
991These
992functions create a Maclisp compatible array.
993In
994.Fr
995arrays of type t, nil, fixnum and flonum are equivalent and the elements
996of these arrays can be any type of lisp object.
997Fixnum-block and flonum-block arrays are restricted to fixnums and flonums
998respectively and are used mainly to communicate with
999foreign functions (see \(sc8.5).
1000.No
1001.i *array
1002evaluates its arguments,
1003.i array
1004does not.
1005.sh 3 array\ predicate
1006.Lf arrayp "'g_arg"
1007.Re
1008t iff g_arg is of type array.
1009.sh 3 array\ accessors
1010
1011.Lf getaccess "'a_array"
1012.Lx getaux "'a_array"
1013.Lx getdelta "'a_array"
1014.Lx getdata "'a_array"
1015.Lx getlength "'a_array"
1016.Re
1017the field of the array object a_array given by the function name.
1018.Lf arrayref "'a_name 'x_ind"
1019.Re
1020the x_ind\fIth\fP element of the array object a_name.
1021x_ind of zero accesses the first element.
1022.No
1023.i arrayref
1024uses the data, length and delta fields of a_name to determine which
1025object to return.
1026.Lf arraycall "s_type 'as_array 'x_ind1 ... "
1027.Re
1028the element selected by the indices from the array a_array
1029of type s_type.
1030.No
1031If as_array is a symbol then the function binding of this symbol should
1032contain an array object.
1033.br
1034s_type is ignored by
1035.i arraycall
1036but is included for compatibility with Maclisp.
1037.Lf arraydims "'s_name"
1038.Re
1039a list of the type and bounds of the array s_name.
1040.Lf listarray "'sa_array ['x_elements]"
1041.Re
1042a list of all of the elements in array sa_array.
1043If x_elements
1044is given, then only the first x_elements are returned.
1045
1046.Eb
1047; We will create a 3 by 4 array of general lisp objects
1048\-> \fI(array ernie t 3 4)\fP
1049array[12]
1050
1051; the array header is stored in the function definition slot of the
1052; symbol ernie
1053\-> \fI(arrayp (getd 'ernie))\fP
1054t
1055\-> \fI(arraydims (getd 'ernie))\fP
1056(t 3 4)
1057
1058; store in ernie[2][2] the list (test list)
1059\-> \fI(store (ernie 2 2) '(test list))\fP
1060(test list)
1061
1062; check to see if it is there
1063\-> \fI(ernie 2 2)\fP
1064(test list)
1065
1066; now use the low level function \fIarrayref\fP to find the same element
1067; arrays are 0 based and row-major (the last subscript varies the fastest)
1068; thus element [2][2] is the 10th element , (starting at 0).
1069\-> \fI(arrayref (getd 'ernie) 10)\fP
1070(ptr to)(test list) ; the result is a value cell (thus the (ptr to))
1071.Ee
1072.sh 3 array\ manipulation
1073.Lf putaccess "'a_array 'su_func"
1074.Lx putaux "'a_array 'g_aux"
1075.Lx putdata "'a_array 'g_arg"
1076.Lx putdelta "'a_array 'x_delta"
1077.Lx putlength "'a_array 'x_length"
1078.Re
1079the second argument to the function.
1080.Se
1081The field of the array object given by the function name is replaced
1082by the second argument to the function.
1083.Lf store "'l_arexp 'g_val"
1084.Wh
1085l_arexp is an expression
1086which references an array element.
1087.Re
1088g_val
1089.Se
1090the array location which contains the element which l_arexp references is
1091changed to contain g_val.
1092.Lf fillarray "'s_array 'l_itms"
1093.Re
1094s_array
1095.Se
1096the array s_array is filled with elements from l_itms.
1097If there are not enough elements in l_itms to fill the entire array,
1098then the last element of l_itms is used to fill the remaining parts
1099of the array.
1100.sh 2 Hunks
1101.pp
1102Hunks are vector-like objects whose size can range from 1 to 128 elements.
1103Internally, hunks are allocated in sizes which are powers of 2.
1104In order to create hunks of a given size,
1105a hunk with at least that many elements is allocated
1106and a distinguished symbol \s-2EMPTY\s0 is placed in those
1107elements not requested.
1108Most hunk functions respect those distinguished symbols, but there are
1109two
1110.i (*makhunk
1111and
1112.i *rplacx )
1113which will overwrite the distinguished symbol.
1114.sh 3 hunk\ creation
1115.Lf hunk "'g_val1 ['g_val2 ... 'g_val\fIn\fP]"
1116.Re
1117a hunk of length n whose elements are initialized to the g_val\fIi\fP.
1118.No
1119the maximum size of a hunk is 128.
1120.Ex
1121\fI(hunk 4 'sharp 'keys)\fP = {4 sharp keys}
1122.Lf makhunk "'xl_arg"
1123.Re
1124a hunk of length xl_arg initialized to all nils if xl_arg is a fixnum.
1125If xl_arg is a list, then we return a hunk of size \fI(length\ 'xl_arg)\fP
1126initialized to the elements in xl_arg.
1127.No
1128\fI(makhunk\ '(a\ b\ c))\fP is equivalent to \fI(hunk\ 'a\ 'b\ 'c)\fP.
1129.Ex
1130\fI(makhunk 4)\fP = \fI{nil nil nil nil}\fP
1131.Lf *makhunk "'x_arg"
1132.Re
1133a hunk of size 2\*[x_arg\*] initialized to \s-2EMPTY\s0.
1134.No
1135This is only to be used by such functions as \fIhunk\fP and \fImakhunk\fP
1136which create and initialize hunks for users.
1137.sh 3 hunk\ accessor
1138.Lf cxr "'x_ind 'h_hunk"
1139.Re
1140element x_ind (starting at 0) of hunk h_hunk.
1141.Lf hunk-to-list 'h_hunk
1142.Re
1143a list consisting of the elements of h_hunk.
1144.sh 3 hunk\ manipulators
1145.Lf rplacx "'x_ind 'h_hunk 'g_val"
1146.Lx *rplacx "'x_ind 'h_hunk 'g_val"
1147.Re
1148h_hunk
1149.Se
1150Element x_ind (starting at 0) of h_hunk is set to g_val.
1151.No
1152.i rplacx
1153will not modify one of the distinguished (EMPTY) elements
1154whereas
1155.i *rplacx
1156will.
1157.Lf hunksize "'h_arg"
1158.Re
1159the size of the hunk h_arg.
1160.Ex
1161\fI(hunksize (hunk 1 2 3))\fP = 3
1162.sh 2 Bcds
1163.pp
1164A bcd object contains a pointer to compiled code and to the type of
1165function object the compiled code represents.
1166.Lf getdisc "'y_bcd"
1167.Lx getentry "'y_bcd"
1168.Re
1169the field of the bcd object given by the function name.
1170.Lf putdisc "'y_func 's_discipline"
1171.Re
1172s_discipline
1173.Se
1174Sets the discipline field of y_func to s_discipline.
1175.sh 2 Structures
1176.pp
1177There are three common structures constructed out of list cells: the
1178assoc list, the property list and the tconc list.
1179The functions below manipulate these structures.
1180.sh 3 assoc\ list
1181.pp
1182An `assoc list' (or alist) is a common lisp data structure. It has the
1183form
1184.br
1185.ce 1
1186((key1 . value1) (key2 . value2) (key3 . value3) ... (keyn . valuen))
1187.Lf assoc "'g_arg1 'l_arg2"
1188.Lx assq "'g_arg1 'l_arg2"
1189.Re
1190the first top level element of l_arg2 whose
1191.i car
1192is
1193.i equal
1194(with
1195.i assoc )
1196or
1197.i eq
1198(with
1199.i assq )
1200to g_arg1.
1201.No
1202Usually l_arg2 has an
1203.i a-list
1204structure and g_arg1 acts as key.
1205.Lf sassoc "'g_arg1 'l_arg2 'sl_func"
1206.Re
1207the result of \fI(cond\ ((assoc\ 'g_arg\ 'l_arg2)\ (apply\ 'sl_func\ nil)))\fP
1208.No
1209sassoc is written as a macro.
1210.Lf sassq "'g_arg1 'l_arg2 'sl_func"
1211.Re
1212the result of \fI(cond\ ((assq\ 'g_arg\ 'l_arg2)\ (apply\ 'sl_func\ nil)))\fP
1213.No
1214sassq is written as a macro.
1215
1216.Eb
1217; \fIassoc\fP or \fIassq\fP is given a key and an assoc list and returns
1218; the key and value item if it exists, they differ only in how they test
1219; for equality of the keys.
1220
1221\-> \fI(setq alist '((alpha . a) ( (complex key) . b) (junk . x)))\fP
1222((alpha . a) ((complex key) . b) (junk . x))
1223
1224; we should use \fIassq\fP when the key is an atom
1225\-> \fI(assq 'alpha alist)\fP
1226(alpha . a)
1227
1228; but it may not work when the key is a list
1229\-> \fI(assq '(complex key) alist)\fP
1230nil
1231
1232; however \fIassoc\fP will always work
1233\-> \fI(assoc '(complex key) alist)\fP
1234((complex key) . b)
1235.Ee
1236.Lf sublis "'l_alst 'l_exp"
1237.Wh
1238l_alst is an
1239.i a-list .
1240.Re
1241the list l_exp with every occurrence of key\fIi\fP replaced by val\fIi\fP.
1242.No
1243new list structure is returned to prevent modification of l_exp.
1244When a substitution is made, a copy of the value to substitute in
1245is not made.
1246.sh 3 property\ list
1247.pp
1248A property list consists of an alternating sequence of keys and
1249values. Normally a property list is stored on a symbol. A list
1250is a 'disembodied' property list if it contains an odd number of
1251elements, the first of which is ignored.
1252.Lf plist "'s_name"
1253.Re
1254the property list of s_name.
1255.Lf setplist "'s_atm 'l_plist"
1256.Re
1257l_plist.
1258.Se
1259the property list of s_atm is set to l_plist.
1260
1261.Lf get "'ls_name 'g_ind"
1262.Re
1263the value under indicator g_ind in ls_name's property list if ls_name
1264is a symbol.
1265.No
1266If there is no indicator g_ind in ls_name's property list nil is returned.
1267If ls_name is a list of an odd number of elements then it is a disembodied
1268property list.
1269\fIget\fP searches a disembodied property list by starting at its
1270\fIcdr\fP, and comparing every other element with g_ind, using
1271\fIeq\fP.
1272.Lf getl "'ls_name 'l_indicators"
1273.Re
1274the property list ls_name beginning at the first indicator which is
1275a member of the list l_indicators, or nil if none of the indicators
1276in l_indicators are on ls_name's property list.
1277.No
1278If ls_name is a list, then it is assumed to be a disembodied property
1279list.
1280
1281.Lf putprop "'ls_name 'g_val 'g_ind"
1282.Lx defprop "ls_name g_val g_ind"
1283.Re
1284g_val.
1285.Se
1286Adds to the property list of ls_name the value g_val under the indicator
1287g_ind.
1288.No
1289.i putprop
1290evaluates it arguments,
1291.i defprop
1292does not.
1293ls_name may be a disembodied property list, see \fIget\fP.
1294.Lf remprop "'ls_name 'g_ind"
1295.Re
1296the portion of ls_name's property list beginning with the
1297property under the indicator g_ind.
1298If there is no g_ind indicator in ls_name's plist, nil is returned.
1299.Se
1300the value under indicator g_ind and g_ind itself is removed from
1301the property list of ls_name.
1302.No
1303ls_name may be a disembodied property list, see \fIget\fP.
1304
1305.Eb
1306\-> \fI(putprop 'xlate 'a 'alpha)\fP
1307a
1308\-> \fI(putprop 'xlate 'b 'beta)\fP
1309b
1310\-> \fI(plist 'xlate)\fP
1311(alpha a beta b)
1312\-> \fI(get 'xlate 'alpha)\fP
1313a
1314; use of a disembodied property list:
1315\-> \fI(get '(nil fateman rjf sklower kls foderaro jkf) 'sklower)\fP
1316kls
1317.Ee
1318.sh 3 tconc\ structure
1319.pp
1320A tconc structure is a special type of list designed to make it
1321easy to add objects to the end.
1322It consists of a list cell whose
1323.i car
1324points to a
1325list of the elements added with
1326.i tconc
1327or
1328.i lconc
1329and whose
1330.i cdr
1331points to the last list cell of the list pointed to by the
1332.i car.
1333.Lf tconc "'l_ptr 'g_x"
1334.Wh
1335l_ptr is a tconc structure.
1336.Re
1337l_ptr with g_x added to the end.
1338.Lf lconc "'l_ptr 'l_x"
1339.Wh
1340l_ptr is a tconc structure.
1341.Re
1342l_ptr with the list l_x spliced in at the end.
1343.Eb
1344; A \fItconc\fP structure can be initialized in two ways.
1345; nil can be given to \fItconc\fP in which case \fItconc\fP will generate
1346; a \fItconc\fP structure.
1347
1348\->\fI(setq foo (tconc nil 1))\fP
1349((1) 1)
1350
1351; Since \fItconc\fP destructively adds to
1352; the list, you can now add to foo without using \fIsetq\fP again.
1353
1354\->\fI(tconc foo 2)\fP
1355((1 2) 2)
1356\->\fIfoo\fP
1357((1 2) 2)
1358
1359; Another way to create a null \fItconc\fP structure
1360; is to use \fI(ncons\ nil)\fP.
1361
1362\->\fI(setq foo (ncons nil))\fP
1363(nil)
1364\->\fI(tconc foo 1)\fP
1365((1) 1)
1366
1367; now see what \fIlconc\fP can do
1368\-> \fI(lconc foo nil)\fP
1369((1) 1) ; no change
1370\-> \fI(lconc foo '(2 3 4))\fP
1371((1 2 3 4) 4)
1372.Ee
1373.sh 3 fclosures
1374.pp
1375An fclosure is a functional object which admits some data
1376manipulations. They are discussed in \(sc8.4.
1377Internally, they are constructed from vectors.
1378.Lf fclosure "'l_vars 'g_funobj"
1379.Wh
1380l_vars is a list of variables, g_funobj is any object
1381that can be funcalled (including, fclosures).
1382.Re
1383A vector which is the fclosure.
1384.Lf fclosure-alist "'v_fclosure"
1385.Re
1386An association list representing the variables in the fclosure.
1387This is a snapshot of the current state of the fclosure.
1388If the bindings in the fclosure are changed, any previously
1389calculated results of
1390.i fclosure-alist
1391will not change.
1392.Lf fclosure-function "'v_fclosure"
1393.Re
1394the functional object part of the fclosure.
1395.Lf fclosurep "'v_fclosure"
1396.Re
1397t iff the argument is an fclosure.
1398.Lf symeval-in-fclosure "'v_fclosure 's_symbol"
1399.Re
1400the current binding of a particular symbol in an fclosure.
1401.Lf set-in-fclosure "'v_fclosure 's_symbol 'g_newvalue"
1402.Re
1403g_newvalue.
1404.Se
1405The variable s_symbol is bound in the fclosure to g_newvalue.
1406.sh 2 Random\ functions
1407.pp
1408The following functions don't fall into any of the classifications above.
1409.Lf bcdad "'s_funcname"
1410.Re
1411a fixnum which is the address in memory where the function
1412s_funcname begins.
1413If s_funcname is not a machine coded function (binary) then
1414.i bcdad
1415returns nil.
1416.Lf copy "'g_arg"
1417.Re
1418A structure
1419.i equal
1420to g_arg but with new list cells.
1421.Lf copyint* "'x_arg"
1422.Re
1423a fixnum with the same value as x_arg but in a freshly allocated cell.
1424.Lf cpy1 "'xvt_arg"
1425.Re
1426a new cell of the same type as xvt_arg with the same value as xvt_arg.
1427.Lf getaddress "'s_entry1 's_binder1 'st_discipline1 [... ... ...]"
1428.Re
1429the binary object which s_binder1's function field is set to.
1430.No
1431This looks in the running lisp's symbol table for a symbol with the same
1432name as s_entry\fIi\fP.
1433It then creates a binary object
1434whose entry field points to s_entry\fIi\fP
1435and whose discipline is st_discipline\fIi\fP.
1436This binary object is stored in the function field of s_binder\fIi\fP.
1437If st_discipline\fIi\fP is nil, then "subroutine" is used by default.
1438This is especially useful for
1439.i cfasl
1440users.
1441.Lf macroexpand "'g_form"
1442.Re
1443g_form after all macros in it are
1444expanded.
1445.No
1446This function will only macroexpand
1447expressions which could be evaluated
1448and it does not know about the special nlambdas such as
1449.i cond
1450and
1451.i do ,
1452thus it misses many macro expansions.
1453.Lf ptr "'g_arg"
1454.Re
1455a value cell initialized to point to g_arg.
1456.Lf quote "g_arg"
1457.Re
1458g_arg.
1459.No
1460the reader allows you to abbreviate (quote foo) as 'foo.
1461.Lf kwote "'g_arg"
1462.Re
1463 \fI(list (quote quote) g_arg)\fP.
1464.Lf replace "'g_arg1 'g_arg2"
1465.Wh
1466g_arg1 and g_arg2 must be the same type of lispval and not symbols or hunks.
1467.Re
1468g_arg2.
1469.Se
1470The effect of
1471.i replace
1472is dependent on the type of the g_arg\fIi\fP although one will notice
1473a similarity in the effects.
1474To understand what
1475.i replace
1476does to fixnum and flonum arguments,
1477you must first understand that
1478such numbers are `boxed' in
1479.Fr .
1480What this means is that if the symbol x has a value 32412, then in
1481memory the value element of x's symbol structure contains the address of
1482another word of memory (called a box) with 32412 in it.
1483.br
1484.sp
1485Thus, there are two ways of changing the value of x:
1486the first is to change
1487the value element of x's symbol structure to point to a word of memory
1488with a different value.
1489The second way is to change the value in the box which x points to.
1490The former method is used almost all of the time, the latter is
1491used very rarely and has the potential to cause great confusion.
1492The function
1493.i replace
1494allows you to do the latter, i.e., to actually change the value in
1495the box.
1496.br
1497.sp
1498You should watch out for these situations.
1499If you do \fI(setq\ y\ x)\fP,
1500then both x and y will point to the same box.
1501If you now \fI(replace\ x\ 12345)\fP,
1502then y will also have the value 12345.
1503And, in fact, there may be many other pointers to that box.
1504.br
1505.sp
1506Another problem with replacing fixnums
1507is that some boxes are read-only.
1508The fixnums between -1024 and 1023 are stored in a read-only area
1509and attempts to replace them will result in an "Illegal memory reference"
1510error (see the description of
1511.i copyint*
1512for a way around this problem).
1513.br
1514.sp
1515For the other valid types, the effect of
1516.i replace
1517is easy to understand.
1518The fields of g_val1's structure are made eq to the corresponding fields of
1519g_val2's structure.
1520For example, if x and y have lists as values then the effect of
1521\fI(replace\ x\ y)\fP is the same as
1522\fI(rplaca\ x\ (car\ y))\fP and \fI(rplacd\ x\ (cdr\ y))\fP.
1523.Lf scons "'x_arg 'bs_rest"
1524.Wh
1525bs_rest is a bignum or nil.
1526.Re
1527a bignum whose first bigit is x_arg
1528and whose higher order bigits are bs_rest.
1529.Lf setf "g_refexpr 'g_value"
1530.No
1531.i setf
1532is a generalization of setq. Information may be stored by
1533binding variables, replacing entries of arrays, and vectors,
1534or being put on property lists, among others.
1535Setf will allow the user to store data into some location,
1536by mentioning the operation used to refer to the location.
1537Thus, the first argument may be partially evaluated, but only
1538to the extent needed to calculate a reference.
1539.i setf
1540returns g_value.
1541(Compare to
1542.i desetq
1543)
1544.Eb
1545 (setf x 3) = (setq x 3)
1546 (setf (car x) 3) = (rplaca x 3)
1547 (setf (get foo 'bar) 3) = (putprop foo 3 'bar)
1548 (setf (vref vector index) value) = (vset vector index value)
1549.Ee
1550.Lf sort "'l_data 'u_comparefn"
1551.Re
1552a list of the elements of l_data ordered by the comparison
1553function u_comparefn.
1554.Se
1555the list l_data is modified rather than allocated in new storage.
1556.No
1557\fI(comparefn 'g_x 'g_y)\fP should return something
1558non-nil if g_x can precede g_y in sorted order; nil if g_y must precede
1559g_x.
1560If u_comparefn is nil,
1561alphabetical order will be used.
1562.Lf sortcar "'l_list 'u_comparefn"
1563.Re
1564a list of the elements of l_list with the
1565.i car 's
1566ordered by the sort function u_comparefn.
1567.Se
1568the list l_list is modified rather than copied.
1569.No
1570Like \fIsort\fP,
1571if u_comparefn is nil,
1572alphabetical order will be used.