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