document distributed with 4.1BSD
[unix-history] / usr / src / old / lisp / PSD.doc / 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.\"
5843f2f8 5.\" @(#)ch2.n 6.1 (Berkeley) %G%
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.
490.TS
491center box;
492l l .
493s_test tested
494
495=
496l g_val < 0
497le g_val \(<= 0
498e g_val = 0
499n g_val \(!= 0
500ge g_val \(>= 0
501g g_val > 0
502.TE
503.Lf eq "'g_arg1 'g_arg2"
504.Re
505t if g_arg1 and g_arg2 are the exact same lisp object.
506.No
507.i Eq
508simply tests if g_arg1 and g_arg2 are located in the exact same
509place in memory.
510Lisp objects which print the same are not necessarily
511.i eq .
512The only objects guaranteed to be
513.i eq
514are interned symbols with the same print name.
515[Unless a symbol is created in a special way (such as with
516.i uconcat
517or
518.i maknam )
519it will be interned.]
520.Lf neq "'g_x 'g_y"
521.Re
522t if g_x is not
523.i eq
524to g_y, otherwise nil.
525.Lf equal "'g_arg1 'g_arg2"
526.Lx eqstr "'g_arg1 'g_arg2"
527.Re
528t iff g_arg1 and g_arg2 have the same structure as described below.
529.No
530g_arg and g_arg2 are
531.i equal
532if
533.np
534they are \fIeq\fP.
535.np
536they are both fixnums with the same value
537.np
538they are both flonums with the same value
539.np
540they are both bignums with the same value
541.np
542they are both strings and are identical.
543.np
544they are both lists and their cars and cdrs are
545.i equal .
546.Eb
547; \fIeq\fP is much faster than \fIequal\fP, especially in compiled code,
548; however you cannot use \fIeq\fP to test for equality of numbers outside
549; of the range -1024 to 1023. \fIequal\fP will always work.
550\-> \fI(eq 1023 1023)\fP
551t
552\-> \fI(eq 1024 1024)\fP
553nil
554\-> \fI(equal 1024 1024)\fP
555t
556.Ee
557
558.Lf not "'g_arg"
559.Lx null "'g_arg"
560.Re
561t iff g_arg is nil.
562
563.Lf member "'g_arg1 'l_arg2"
564.Lx memq "'g_arg1 'l_arg2"
565.Re
566that part of the l_arg2 beginning with the first occurrence
567of g_arg1.
568If g_arg1 is not in the top level of l_arg2, nil is returned.
569.No
570.i member
571tests for equality with
572.i equal ,
573.i memq
574tests for equality with
575.i eq .
576
577.sh 2 Symbols\ and\ Strings
578.pp
579In many of the following functions the distinction between symbols and
580strings is somewhat blurred.
581To remind ourselves of the difference,
582a string is a null terminated sequence of characters, stored as
583compactly as possible.
584Strings are used as constants in
585.Fr .
586They
587.i eval
588to themselves.
589A symbol has additional structure:
590a value, property list, function binding,
591as well as its external representation (or print-name).
592If a symbol is given to one of the string manipulation functions below, its
593print name will be used as the string.
594.pp
595Another popular way to represent strings in Lisp is as a list of fixnums
596which represent characters.
597The suffix 'n' to a string manipulation function indicates that it
598returns a string in this form.
599.sh 3 symbol\ and\ string\ creation
600.Lf concat "['stn_arg1 ... ]"
601.Lx uconcat "['stn_arg1 ... ]"
602.Re
603a symbol whose print name
604is the result of concatenating the print names,
605string characters or numerical representations
606of the sn_arg\fIi\fP.
607.No
608If no arguments are given, a symbol with a null pname is returned.
609\fIconcat\fP places the symbol created on the oblist, the function
610.i uconcat
611does the same thing but does not place the new symbol on the oblist.
612.Ex
613\fI(concat 'abc (add 3 4) "def")\fP = abc7def
614.Lf concatl "'l_arg"
615.Eq
616\fI(apply 'concat 'l_arg)\fP
617
618.Lf implode "'l_arg"
619.Lx maknam "'l_arg"
620.Wh
621l_arg is a list of symbols, strings and small fixnums.
622.Re
623The symbol whose print name is the result of concatenating the
624first characters of the print names of the symbols and strings
625in the list.
626Any fixnums are converted to the equivalent ascii character.
627In order to concatenate entire strings or print names, use the
628function
629.i concat .
630.No
631.i implode
632interns the symbol it creates,
633.i maknam
634does not.
635.Lf gensym "['s_leader]"
636.Re
637a new uninterned atom beginning with the first character of s_leader's
638pname, or beginning with g if s_leader is not given.
639.No
640The symbol looks like x0nnnnn where x is s_leader's first character and
641nnnnn is the number of times you have called gensym.
642.Lf copysymbol "'s_arg 'g_pred"
643.Re
644an uninterned symbol with the same print name as s_arg.
645If g_pred is non nil, then the value, function binding
646and property list of the new symbol are made
647.i eq
648to those of s_arg.
649
650.Lf ascii "'x_charnum"
651.Wh
652x_charnum is between 0 and 255.
653.Re
654a symbol whose print name is the single character whose fixnum
655representation is x_charnum.
656
657.Lf intern "'s_arg"
658.Re
659s_arg
660.Se
661s_arg is put on the oblist if it is not already there.
662.Lf remob "'s_symbol"
663.Re
664s_symbol
665.Se
666s_symbol is removed from the oblist.
667.Lf rematom "'s_arg"
668.Re
669t if s_arg is indeed an atom.
670.Se
671s_arg is put on the free atoms list, effectively reclaiming an
672atom cell.
673.No
674This function does
675.i not
676check to see if s_arg is on the oblist or is referenced anywhere.
677Thus calling
678.i rematom
679on an atom in the oblist may result in disaster when that atom cell
680is reused!
681.sh 3 string\ and\ symbol\ predicates
682.Lf boundp "'s_name"
683.Re
684nil if s_name is unbound: that is, it has never been given a value.
685If x_name has the value g_val, then (nil\ .\ g_val) is returned.
686See also
687.i makunbound .
688.Lf alphalessp "'st_arg1 'st_arg2"
689.Re
690t iff the `name' of st_arg1 is alphabetically less than the
691name of st_arg2.
692If st_arg is a symbol then its `name' is its print name.
693If st_arg is a string, then its `name' is the string itself.
694.sh 3 symbol\ and\ string\ accessing
695.Lf symeval "'s_arg"
696.Re
697the value of symbol s_arg.
698.No
699It is illegal to ask for the value of an unbound symbol.
700This function has the same effect as
701.i eval ,
702but compiles into much more efficient code.
703.Lf get_pname "'s_arg"
704.Re
705the string which is the print name of s_arg.
706.Lf plist "'s_arg"
707.Re
708the property list of s_arg.
709.Lf getd "'s_arg"
710.Re
711the function definition of s_arg or nil if there is no function definition.
712.No
713the function definition may turn out to be an array header.
714.Lf getchar "'s_arg 'x_index"
715.Lx nthchar "'s_arg 'x_index"
716.Lx getcharn "'s_arg 'x_index"
717.Re
718the x_index\fIth\fP character of the print name of s_arg or nil if x_index
719is less than 1 or greater than the length of s_arg's print name.
720.No
721.i getchar
722and
723.i nthchar
724return a symbol with a single character print name,
725.i getcharn
726returns the fixnum representation of the character.
727.Lf substring "'st_string 'x_index ['x_length]"
728.Lx substringn "'st_string 'x_index ['x_length]"
729.Re
730a string of length at most
731x_length starting at x_index\fIth\fP character
732in the string.
733.No
734If x_length is not given, all of the characters for x_index
735to the end of the string are returned.
736If x_index is negative the string begins at the
737x_index\fIth\fP character from the end.
738If x_index is out of bounds, nil is returned.
739.No
740.i substring
741returns a list of symbols,
742.i substringn
743returns a list of fixnums.
744If
745.i substringn
746is given a 0 x_length argument then a single fixnum
747which is the x_index\fIth\fP character is returned.
748.sh 3 symbol\ and\ string\ manipulation
749.Lf set "'s_arg1 'g_arg2"
750.Re
751g_arg2.
752.Se
753the value of s_arg1 is set to g_arg2.
754.Lf setq "s_atm1 'g_val1 [ s_atm2 'g_val2 ... ... ]"
755.Wh
756the arguments are pairs of atom names and expressions.
757.Re
758the last g_val\fIi\fP.
759.Se
760each s_atm\fIi\fP is set to have the value g_val\fIi\fP.
761.No
762.i set
763evaluates all of its arguments,
764.i setq
765does not evaluate the s_atm\fIi\fP.
766.Lf desetq "sl_pattern1 'g_exp1 [... ...]"
767.Re
768g_expn
769.Se
770This acts just like \fIsetq\fP if all the sl_pattern\fIi\fP are symbols.
771If sl_pattern\fIi\fP is a list then it is a template which should
772have the same structure as g_exp\fIi\fP
773The symbols in sl_pattern are assigned to the corresponding
774parts of g_exp.
775(See also
776.i setf
777)
778.Ex
779\fI(desetq (a b (c . d)) '(1 2 (3 4 5)))\fP
780.br
781sets a to 1, b to 2, c to 3, and d to (4 5).
782
783.Lf setplist "'s_atm 'l_plist"
784.Re
785l_plist.
786.Se
787the property list of s_atm is set to l_plist.
788.Lf makunbound "'s_arg"
789.Re
790s_arg
791.Se
792the value of s_arg is made `unbound'.
793If the interpreter attempts to evaluate s_arg before it is again
794given a value, an unbound variable error will occur.
795.Lf aexplode "'s_arg"
796.Lx explode "'g_arg"
797.Lx aexplodec "'s_arg"
798.Lx explodec "'g_arg"
799.Lx aexploden "'s_arg"
800.Lx exploden "'g_arg"
801.Re
802a list of the characters used to print out s_arg or g_arg.
803.No
804The functions beginning with 'a' are internal functions which are limited
805to symbol arguments.
806The functions
807.i aexplode
808and
809.i explode
810return a list of characters which
811.i print
812would use to print the argument.
813These characters include all necessary escape characters.
814Functions
815.i aexplodec
816and
817.i explodec
818return a list of characters which
819.i patom
820would use to print the argument (i.e. no escape characters).
821Functions
822.i aexploden
823and
824.i exploden
825are similar to
826.i aexplodec
827and
828.i explodec
829except that a list of fixnum equivalents of characters are returned.
830.Eb
831\-> \fI(setq x '|quote this \e| ok?|)\fP
832|quote this \e| ok?|
833\-> \fI(explode x)\fP
834(q u o t e |\e\e| | | t h i s |\e\e| | | |\e\e| |\e|| |\e\e| | | o k ?)
835; note that |\e\e| just means the single character: backslash.
836; and |\e|| just means the single character: vertical bar
837; and | | means the single character: space
838
839\-> \fI(explodec x)\fP
840(q u o t e | | t h i s | | |\e|| | | o k ?)
841\-> \fI(exploden x)\fP
842(113 117 111 116 101 32 116 104 105 115 32 124 32 111 107 63)
843.Ee
844.sh 2 Vectors
845.pp
846See Chapter 9 for a discussion of vectors.
847They are less efficient that hunks but more efficient than arrays.
848.sh 3 vector\ creation
849.Lf new-vector "'x_size ['g_fill ['g_prop]]"
850.Re
851A \fBvector\fP of length x_size.
852Each data entry is initialized to g_fill, or to nil, if the argument g_fill
853is not present.
854The vector's property is set to g_prop, or to nil, by default.
855.Lf new-vectori-byte "'x_size ['g_fill ['g_prop]]"
856.Lx new-vectori-word "'x_size ['g_fill ['g_prop]]"
857.Lx new-vectori-long "'x_size ['g_fill ['g_prop]]"
858.Re
859A \fBvectori\fP with x_size elements in it.
860The actual memory requirement is two long words + x_size*(n bytes),
861where n is 1 for new-vector-byte, 2 for new-vector-word, or 4 for
862new-vectori-long.
863Each data entry is initialized to g_fill, or to zero, if the argument g_fill
864is not present.
865The vector's property is set to g_prop, or nil, by default.
866.sp 2v
867.lp
868Vectors may be created by specifying multiple initial values:
869.Lf vector "['g_val0 'g_val1 ...]"
870.Re
871a \fBvector\fP, with as many data elements as there are arguments.
872It is quite possible to have a vector with no data elements.
873The vector's property will be a null list.
874.Lf vectori-byte "['x_val0 'x_val2 ...]"
875.Lx vectori-word "['x_val0 'x_val2 ...]"
876.Lx vectori-long "['x_val0 'x_val2 ...]"
877.Re
878a \fBvectori\fP, with as many data elements as there are arguments.
879The arguments are required to be fixnums.
880Only the low order byte or word is used in the case of vectori-byte
881and vectori-word.
882The vector's property will be null.
883.sh 3 vector\ reference
884.Lf vref "'v_vect 'x_index"
885.Lx vrefi-byte "'V_vect 'x_bindex"
886.Lx vrefi-word "'V_vect 'x_windex"
887.Lx vrefi-long "'V_vect 'x_lindex"
888.Re
889the desired data element from a vector.
890The indices must be fixnums.
891Indexing is zero-based.
892The vrefi functions sign extend the data.
893.Lf vprop 'Vv_vect
894.Re
895The Lisp property associated with a vector.
896.Lf vget "'Vv_vect 'g_ind"
897.Re
898The value stored under g_ind if the Lisp property associated
899with 'Vv_vect is a disembodied property list.
900.Lf vsize 'Vv_vect
901.Lx vsize-byte 'V_vect
902.Lx vsize-word 'V_vect
903.Re
904the number of data elements in the vector. For immediate-vectors,
905the functions vsize-byte and vsize-word return the number of data elements,
906if one thinks of the binary data as being comprised of bytes or words.
907.sh 3 vector\ modfication
908.Lf vset "'v_vect 'x_index 'g_val"
909.Lx vseti-byte "'V_vect 'x_bindex 'x_val"
910.Lx vseti-word "'V_vect 'x_windex 'x_val"
911.Lx vseti-long "'V_vect 'x_lindex 'x_val"
912.Re
913the datum.
914.Se
915The indexed element of the vector is set to the value.
916As noted above, for vseti-word and vseti-byte, the index
917is construed as the number of the data element within
918the vector. It is not a byte address.
919Also, for those two functions,
920the low order byte or word of x_val is what is stored.
921.Lf vsetprop "'Vv_vect 'g_value"
922.Re
923g_value. This should be either a symbol
924or a disembodied property list whose
925.i car
926is a symbol identifying the type of
927the vector.
928.Se
929the property list of Vv_vect is set to g_value.
930.Lf vputprop "'Vv_vect 'g_value 'g_ind"
931.Re
932g_value.
933.Se
934If the vector property of Vv_vect is a disembodied property list,
935then vputprop adds the value g_value under the indicator g_ind.
936Otherwise, the old vector property is made the first
937element of the list.
938.sh 2 Arrays
939.pp
940See Chapter 9 for a complete description of arrays.
941Some of these functions are part of a Maclisp array
942compatibility package representing only one simple way of using the
943array structure of
944.Fr .
945.sh 3 array\ creation
946.Lf marray "'g_data 's_access 'g_aux 'x_length 'x_delta"
947.Re
948an array type with the fields set up from the above arguments
949in the obvious way (see \(sc 1.2.10).
950.Lf *array "'s_name 's_type 'x_dim1 ... 'x_dim\fIn\fP"
951.Lx array "s_name s_type x_dim1 ... x_dim\fIn\fP"
952.Wh
953s_type may be one of t, nil, fixnum, flonum, fixnum-block and
954flonum-block.
955.Re
956an array of type s_type with n dimensions of extents given by the
957x_dim\fIi\fP.
958.Se
959If s_name is non nil, the function definition of s_name is
960set to the array structure returned.
961.No
962These
963functions create a Maclisp compatible array.
964In
965.Fr
966arrays of type t, nil, fixnum and flonum are equivalent and the elements
967of these arrays can be any type of lisp object.
968Fixnum-block and flonum-block arrays are restricted to fixnums and flonums
969respectively and are used mainly to communicate with
970foreign functions (see \(sc8.5).
971.No
972.i *array
973evaluates its arguments,
974.i array
975does not.
976.sh 3 array\ predicate
977.Lf arrayp "'g_arg"
978.Re
979t iff g_arg is of type array.
980.sh 3 array\ accessors
981
982.Lf getaccess "'a_array"
983.Lx getaux "'a_array"
984.Lx getdelta "'a_array"
985.Lx getdata "'a_array"
986.Lx getlength "'a_array"
987.Re
988the field of the array object a_array given by the function name.
989.Lf arrayref "'a_name 'x_ind"
990.Re
991the x_ind\fIth\fP element of the array object a_name.
992x_ind of zero accesses the first element.
993.No
994.i arrayref
995uses the data, length and delta fields of a_name to determine which
996object to return.
997.Lf arraycall "s_type 'as_array 'x_ind1 ... "
998.Re
999the element selected by the indices from the array a_array
1000of type s_type.
1001.No
1002If as_array is a symbol then the function binding of this symbol should
1003contain an array object.
1004.br
1005s_type is ignored by
1006.i arraycall
1007but is included for compatibility with Maclisp.
1008.Lf arraydims "'s_name"
1009.Re
1010a list of the type and bounds of the array s_name.
1011.Lf listarray "'sa_array ['x_elements]"
1012.Re
1013a list of all of the elements in array sa_array.
1014If x_elements
1015is given, then only the first x_elements are returned.
1016
1017.Eb
1018; We will create a 3 by 4 array of general lisp objects
1019\-> \fI(array ernie t 3 4)\fP
1020array[12]
1021
1022; the array header is stored in the function definition slot of the
1023; symbol ernie
1024\-> \fI(arrayp (getd 'ernie))\fP
1025t
1026\-> \fI(arraydims (getd 'ernie))\fP
1027(t 3 4)
1028
1029; store in ernie[2][2] the list (test list)
1030\-> \fI(store (ernie 2 2) '(test list))\fP
1031(test list)
1032
1033; check to see if it is there
1034\-> \fI(ernie 2 2)\fP
1035(test list)
1036
1037; now use the low level function \fIarrayref\fP to find the same element
1038; arrays are 0 based and row-major (the last subscript varies the fastest)
1039; thus element [2][2] is the 10th element , (starting at 0).
1040\-> \fI(arrayref (getd 'ernie) 10)\fP
1041(ptr to)(test list) ; the result is a value cell (thus the (ptr to))
1042.Ee
1043.sh 3 array\ manipulation
1044.Lf putaccess "'a_array 'su_func"
1045.Lx putaux "'a_array 'g_aux"
1046.Lx putdata "'a_array 'g_arg"
1047.Lx putdelta "'a_array 'x_delta"
1048.Lx putlength "'a_array 'x_length"
1049.Re
1050the second argument to the function.
1051.Se
1052The field of the array object given by the function name is replaced
1053by the second argument to the function.
1054.Lf store "'l_arexp 'g_val"
1055.Wh
1056l_arexp is an expression
1057which references an array element.
1058.Re
1059g_val
1060.Se
1061the array location which contains the element which l_arexp references is
1062changed to contain g_val.
1063.Lf fillarray "'s_array 'l_itms"
1064.Re
1065s_array
1066.Se
1067the array s_array is filled with elements from l_itms.
1068If there are not enough elements in l_itms to fill the entire array,
1069then the last element of l_itms is used to fill the remaining parts
1070of the array.
1071.sh 2 Hunks
1072.pp
1073Hunks are vector-like objects whose size can range from 1 to 128 elements.
1074Internally, hunks are allocated in sizes which are powers of 2.
1075In order to create hunks of a given size,
1076a hunk with at least that many elements is allocated
1077and a distinguished symbol \s-2EMPTY\s0 is placed in those
1078elements not requested.
1079Most hunk functions respect those distinguished symbols, but there are
1080two
1081.i (*makhunk
1082and
1083.i *rplacx )
1084which will overwrite the distinguished symbol.
1085.sh 3 hunk\ creation
1086.Lf hunk "'g_val1 ['g_val2 ... 'g_val\fIn\fP]"
1087.Re
1088a hunk of length n whose elements are initialized to the g_val\fIi\fP.
1089.No
1090the maximum size of a hunk is 128.
1091.Ex
1092\fI(hunk 4 'sharp 'keys)\fP = {4 sharp keys}
1093.Lf makhunk "'xl_arg"
1094.Re
1095a hunk of length xl_arg initialized to all nils if xl_arg is a fixnum.
1096If xl_arg is a list, then we return a hunk of size \fI(length\ 'xl_arg)\fP
1097initialized to the elements in xl_arg.
1098.No
1099\fI(makhunk\ '(a\ b\ c))\fP is equivalent to \fI(hunk\ 'a\ 'b\ 'c)\fP.
1100.Ex
1101\fI(makhunk 4)\fP = \fI{nil nil nil nil}\fP
1102.Lf *makhunk "'x_arg"
1103.Re
1104a hunk of size 2\*[x_arg\*] initialized to \s-2EMPTY\s0.
1105.No
1106This is only to be used by such functions as \fIhunk\fP and \fImakhunk\fP
1107which create and initialize hunks for users.
1108.sh 3 hunk\ accessor
1109.Lf cxr "'x_ind 'h_hunk"
1110.Re
1111element x_ind (starting at 0) of hunk h_hunk.
1112.Lf hunk-to-list 'h_hunk
1113.Re
1114a list consisting of the elements of h_hunk.
1115.sh 3 hunk\ manipulators
1116.Lf rplacx "'x_ind 'h_hunk 'g_val"
1117.Lx *rplacx "'x_ind 'h_hunk 'g_val"
1118.Re
1119h_hunk
1120.Se
1121Element x_ind (starting at 0) of h_hunk is set to g_val.
1122.No
1123.i rplacx
1124will not modify one of the distinguished (EMPTY) elements
1125whereas
1126.i *rplacx
1127will.
1128.Lf hunksize "'h_arg"
1129.Re
1130the size of the hunk h_arg.
1131.Ex
1132\fI(hunksize (hunk 1 2 3))\fP = 3
1133.sh 2 Bcds
1134.pp
1135A bcd object contains a pointer to compiled code and to the type of
1136function object the compiled code represents.
1137.Lf getdisc "'y_bcd"
1138.Lx getentry "'y_bcd"
1139.Re
1140the field of the bcd object given by the function name.
1141.Lf putdisc "'y_func 's_discipline"
1142.Re
1143s_discipline
1144.Se
1145Sets the discipline field of y_func to s_discipline.
1146.sh 2 Structures
1147.pp
1148There are three common structures constructed out of list cells: the
1149assoc list, the property list and the tconc list.
1150The functions below manipulate these structures.
1151.sh 3 assoc\ list
1152.pp
1153An `assoc list' (or alist) is a common lisp data structure. It has the
1154form
1155.br
1156.ce 1
1157((key1 . value1) (key2 . value2) (key3 . value3) ... (keyn . valuen))
1158.Lf assoc "'g_arg1 'l_arg2"
1159.Lx assq "'g_arg1 'l_arg2"
1160.Re
1161the first top level element of l_arg2 whose
1162.i car
1163is
1164.i equal
1165(with
1166.i assoc )
1167or
1168.i eq
1169(with
1170.i assq )
1171to g_arg1.
1172.No
1173Usually l_arg2 has an
1174.i a-list
1175structure and g_arg1 acts as key.
1176.Lf sassoc "'g_arg1 'l_arg2 'sl_func"
1177.Re
1178the result of \fI(cond\ ((assoc\ 'g_arg\ 'l_arg2)\ (apply\ 'sl_func\ nil)))\fP
1179.No
1180sassoc is written as a macro.
1181.Lf sassq "'g_arg1 'l_arg2 'sl_func"
1182.Re
1183the result of \fI(cond\ ((assq\ 'g_arg\ 'l_arg2)\ (apply\ 'sl_func\ nil)))\fP
1184.No
1185sassq is written as a macro.
1186
1187.Eb
1188; \fIassoc\fP or \fIassq\fP is given a key and an assoc list and returns
1189; the key and value item if it exists, they differ only in how they test
1190; for equality of the keys.
1191
1192\-> \fI(setq alist '((alpha . a) ( (complex key) . b) (junk . x)))\fP
1193((alpha . a) ((complex key) . b) (junk . x))
1194
1195; we should use \fIassq\fP when the key is an atom
1196\-> \fI(assq 'alpha alist)\fP
1197(alpha . a)
1198
1199; but it may not work when the key is a list
1200\-> \fI(assq '(complex key) alist)\fP
1201nil
1202
1203; however \fIassoc\fP will always work
1204\-> \fI(assoc '(complex key) alist)\fP
1205((complex key) . b)
1206.Ee
1207.Lf sublis "'l_alst 'l_exp"
1208.Wh
1209l_alst is an
1210.i a-list .
1211.Re
1212the list l_exp with every occurrence of key\fIi\fP replaced by val\fIi\fP.
1213.No
1214new list structure is returned to prevent modification of l_exp.
1215When a substitution is made, a copy of the value to substitute in
1216is not made.
1217.sh 3 property\ list
1218.pp
1219A property list consists of an alternating sequence of keys and
1220values. Normally a property list is stored on a symbol. A list
1221is a 'disembodied' property list if it contains an odd number of
1222elements, the first of which is ignored.
1223.Lf plist "'s_name"
1224.Re
1225the property list of s_name.
1226.Lf setplist "'s_atm 'l_plist"
1227.Re
1228l_plist.
1229.Se
1230the property list of s_atm is set to l_plist.
1231
1232.Lf get "'ls_name 'g_ind"
1233.Re
1234the value under indicator g_ind in ls_name's property list if ls_name
1235is a symbol.
1236.No
1237If there is no indicator g_ind in ls_name's property list nil is returned.
1238If ls_name is a list of an odd number of elements then it is a disembodied
1239property list.
1240\fIget\fP searches a disembodied property list by starting at its
1241\fIcdr\fP, and comparing every other element with g_ind, using
1242\fIeq\fP.
1243.Lf getl "'ls_name 'l_indicators"
1244.Re
1245the property list ls_name beginning at the first indicator which is
1246a member of the list l_indicators, or nil if none of the indicators
1247in l_indicators are on ls_name's property list.
1248.No
1249If ls_name is a list, then it is assumed to be a disembodied property
1250list.
1251
1252.Lf putprop "'ls_name 'g_val 'g_ind"
1253.Lx defprop "ls_name g_val g_ind"
1254.Re
1255g_val.
1256.Se
1257Adds to the property list of ls_name the value g_val under the indicator
1258g_ind.
1259.No
1260.i putprop
1261evaluates it arguments,
1262.i defprop
1263does not.
1264ls_name may be a disembodied property list, see \fIget\fP.
1265.Lf remprop "'ls_name 'g_ind"
1266.Re
1267the portion of ls_name's property list beginning with the
1268property under the indicator g_ind.
1269If there is no g_ind indicator in ls_name's plist, nil is returned.
1270.Se
1271the value under indicator g_ind and g_ind itself is removed from
1272the property list of ls_name.
1273.No
1274ls_name may be a disembodied property list, see \fIget\fP.
1275
1276.Eb
1277\-> \fI(putprop 'xlate 'a 'alpha)\fP
1278a
1279\-> \fI(putprop 'xlate 'b 'beta)\fP
1280b
1281\-> \fI(plist 'xlate)\fP
1282(alpha a beta b)
1283\-> \fI(get 'xlate 'alpha)\fP
1284a
1285; use of a disembodied property list:
1286\-> \fI(get '(nil fateman rjf sklower kls foderaro jkf) 'sklower)\fP
1287kls
1288.Ee
1289.sh 3 tconc\ structure
1290.pp
1291A tconc structure is a special type of list designed to make it
1292easy to add objects to the end.
1293It consists of a list cell whose
1294.i car
1295points to a
1296list of the elements added with
1297.i tconc
1298or
1299.i lconc
1300and whose
1301.i cdr
1302points to the last list cell of the list pointed to by the
1303.i car.
1304.Lf tconc "'l_ptr 'g_x"
1305.Wh
1306l_ptr is a tconc structure.
1307.Re
1308l_ptr with g_x added to the end.
1309.Lf lconc "'l_ptr 'l_x"
1310.Wh
1311l_ptr is a tconc structure.
1312.Re
1313l_ptr with the list l_x spliced in at the end.
1314.Eb
1315; A \fItconc\fP structure can be initialized in two ways.
1316; nil can be given to \fItconc\fP in which case \fItconc\fP will generate
1317; a \fItconc\fP structure.
1318
1319\->\fI(setq foo (tconc nil 1))\fP
1320((1) 1)
1321
1322; Since \fItconc\fP destructively adds to
1323; the list, you can now add to foo without using \fIsetq\fP again.
1324
1325\->\fI(tconc foo 2)\fP
1326((1 2) 2)
1327\->\fIfoo\fP
1328((1 2) 2)
1329
1330; Another way to create a null \fItconc\fP structure
1331; is to use \fI(ncons\ nil)\fP.
1332
1333\->\fI(setq foo (ncons nil))\fP
1334(nil)
1335\->\fI(tconc foo 1)\fP
1336((1) 1)
1337
1338; now see what \fIlconc\fP can do
1339\-> \fI(lconc foo nil)\fP
1340((1) 1) ; no change
1341\-> \fI(lconc foo '(2 3 4))\fP
1342((1 2 3 4) 4)
1343.Ee
1344.sh 3 fclosures
1345.pp
1346An fclosure is a functional object which admits some data
1347manipulations. They are discussed in \(sc8.4.
1348Internally, they are constructed from vectors.
1349.Lf fclosure "'l_vars 'g_funobj"
1350.Wh
1351l_vars is a list of variables, g_funobj is any object
1352that can be funcalled (including, fclosures).
1353.Re
1354A vector which is the fclosure.
1355.Lf fclosure-alist "'v_fclosure"
1356.Re
1357An association list representing the variables in the fclosure.
1358This is a snapshot of the current state of the fclosure.
1359If the bindings in the fclosure are changed, any previously
1360calculated results of
1361.i fclosure-alist
1362will not change.
1363.Lf fclosure-function "'v_fclosure"
1364.Re
1365the functional object part of the fclosure.
1366.Lf fclosurep "'v_fclosure"
1367.Re
1368t iff the argument is an fclosure.
1369.Lf symeval-in-fclosure "'v_fclosure 's_symbol"
1370.Re
1371the current binding of a particular symbol in an fclosure.
1372.Lf set-in-fclosure "'v_fclosure 's_symbol 'g_newvalue"
1373.Re
1374g_newvalue.
1375.Se
1376The variable s_symbol is bound in the fclosure to g_newvalue.
1377.sh 2 Random\ functions
1378.pp
1379The following functions don't fall into any of the classifications above.
1380.Lf bcdad "'s_funcname"
1381.Re
1382a fixnum which is the address in memory where the function
1383s_funcname begins.
1384If s_funcname is not a machine coded function (binary) then
1385.i bcdad
1386returns nil.
1387.Lf copy "'g_arg"
1388.Re
1389A structure
1390.i equal
1391to g_arg but with new list cells.
1392.Lf copyint* "'x_arg"
1393.Re
1394a fixnum with the same value as x_arg but in a freshly allocated cell.
1395.Lf cpy1 "'xvt_arg"
1396.Re
1397a new cell of the same type as xvt_arg with the same value as xvt_arg.
1398.Lf getaddress "'s_entry1 's_binder1 'st_discipline1 [... ... ...]"
1399.Re
1400the binary object which s_binder1's function field is set to.
1401.No
1402This looks in the running lisp's symbol table for a symbol with the same
1403name as s_entry\fIi\fP.
1404It then creates a binary object
1405whose entry field points to s_entry\fIi\fP
1406and whose discipline is st_discipline\fIi\fP.
1407This binary object is stored in the function field of s_binder\fIi\fP.
1408If st_discipline\fIi\fP is nil, then "subroutine" is used by default.
1409This is especially useful for
1410.i cfasl
1411users.
1412.Lf macroexpand "'g_form"
1413.Re
1414g_form after all macros in it are
1415expanded.
1416.No
1417This function will only macroexpand
1418expressions which could be evaluated
1419and it does not know about the special nlambdas such as
1420.i cond
1421and
1422.i do ,
1423thus it misses many macro expansions.
1424.Lf ptr "'g_arg"
1425.Re
1426a value cell initialized to point to g_arg.
1427.Lf quote "g_arg"
1428.Re
1429g_arg.
1430.No
1431the reader allows you to abbreviate (quote foo) as 'foo.
1432.Lf kwote "'g_arg"
1433.Re
1434 \fI(list (quote quote) g_arg)\fP.
1435.Lf replace "'g_arg1 'g_arg2"
1436.Wh
1437g_arg1 and g_arg2 must be the same type of lispval and not symbols or hunks.
1438.Re
1439g_arg2.
1440.Se
1441The effect of
1442.i replace
1443is dependent on the type of the g_arg\fIi\fP although one will notice
1444a similarity in the effects.
1445To understand what
1446.i replace
1447does to fixnum and flonum arguments,
1448you must first understand that
1449such numbers are `boxed' in
1450.Fr .
1451What this means is that if the symbol x has a value 32412, then in
1452memory the value element of x's symbol structure contains the address of
1453another word of memory (called a box) with 32412 in it.
1454.br
1455.sp
1456Thus, there are two ways of changing the value of x:
1457the first is to change
1458the value element of x's symbol structure to point to a word of memory
1459with a different value.
1460The second way is to change the value in the box which x points to.
1461The former method is used almost all of the time, the latter is
1462used very rarely and has the potential to cause great confusion.
1463The function
1464.i replace
1465allows you to do the latter, i.e., to actually change the value in
1466the box.
1467.br
1468.sp
1469You should watch out for these situations.
1470If you do \fI(setq\ y\ x)\fP,
1471then both x and y will point to the same box.
1472If you now \fI(replace\ x\ 12345)\fP,
1473then y will also have the value 12345.
1474And, in fact, there may be many other pointers to that box.
1475.br
1476.sp
1477Another problem with replacing fixnums
1478is that some boxes are read-only.
1479The fixnums between -1024 and 1023 are stored in a read-only area
1480and attempts to replace them will result in an "Illegal memory reference"
1481error (see the description of
1482.i copyint*
1483for a way around this problem).
1484.br
1485.sp
1486For the other valid types, the effect of
1487.i replace
1488is easy to understand.
1489The fields of g_val1's structure are made eq to the corresponding fields of
1490g_val2's structure.
1491For example, if x and y have lists as values then the effect of
1492\fI(replace\ x\ y)\fP is the same as
1493\fI(rplaca\ x\ (car\ y))\fP and \fI(rplacd\ x\ (cdr\ y))\fP.
1494.Lf scons "'x_arg 'bs_rest"
1495.Wh
1496bs_rest is a bignum or nil.
1497.Re
1498a bignum whose first bigit is x_arg
1499and whose higher order bigits are bs_rest.
1500.Lf setf "g_refexpr 'g_value"
1501.No
1502.i setf
1503is a generalization of setq. Information may be stored by
1504binding variables, replacing entries of arrays, and vectors,
1505or being put on property lists, among others.
1506Setf will allow the user to store data into some location,
1507by mentioning the operation used to refer to the location.
1508Thus, the first argument may be partially evaluated, but only
1509to the extent needed to calculate a reference.
1510.i setf
1511returns g_value.
1512(Compare to
1513.i desetq
1514)
1515.Eb
1516 (setf x 3) = (setq x 3)
1517 (setf (car x) 3) = (rplaca x 3)
1518 (setf (get foo 'bar) 3) = (putprop foo 3 'bar)
1519 (setf (vref vector index) value) = (vset vector index value)
1520.Ee
1521.Lf sort "'l_data 'u_comparefn"
1522.Re
1523a list of the elements of l_data ordered by the comparison
1524function u_comparefn.
1525.Se
1526the list l_data is modified rather than allocated in new storage.
1527.No
1528\fI(comparefn 'g_x 'g_y)\fP should return something
1529non-nil if g_x can precede g_y in sorted order; nil if g_y must precede
1530g_x.
1531If u_comparefn is nil,
1532alphabetical order will be used.
1533.Lf sortcar "'l_list 'u_comparefn"
1534.Re
1535a list of the elements of l_list with the
1536.i car 's
1537ordered by the sort function u_comparefn.
1538.Se
1539the list l_list is modified rather than copied.
1540.No
1541Like \fIsort\fP,
1542if u_comparefn is nil,
1543alphabetical order will be used.