BSD 3 development
[unix-history] / usr / doc / lisp / ch2.n
CommitLineData
3551888b
JF
1.Lc Data\ Structure\ Access 2
2.\".ch 2
3.pp
4The following functions allow one to create and manipulate the various types
5of lisp data structures.
6Refer to \(sc1.3 for details of the data structures known to
7.Fr .
8.sp 3v
9.Lf *array "'s_name 's_type 'x_dim1 ... x_dim\fIn\fP"
10.Re
11an array of type s_type with n dimensions of extents given by the
12x_dim\fIi\fP.
13.No
14s_type may be any of the lisp data types or it may be t in which case
15it means an array of any type of lisp data.
16This is done by creating an array of value cells and doing an extra
17evaluation upon every reference to make it seem that the array
18contains heterogeneous data types.
19.Se
20If s_name is non nil, the value and function definition of s_name is
21set to the array structure returned.
22.No
23the above is true if you are using the default array package.
24Users who wish to make arrays look different will probably want to
25redefine *array.
26.Lf aexplode "'s_arg"
27.Re
28a list of single character symbols which
29.i print
30would use to print out
31g_arg, that is the list returned will contain quoting characters if
32.i print
33would have used them to print s_arg.
34.No
35this is restriced to symbols and is mainly for use by explode.
36.Lf aexplodec "'s_arg"
37.Re
38a list of symbols whose pnames are the characters
39in s_arg's pname.
40.\".pg
41.Lf aexploden "'s_arg"
42.Re
43a list of fixnums which represent the characters of s_arg's
44pname.
45.Lf alphalessp "'s_arg1 's_arg2"
46.Re
47t iff the print name of s_arg1 is alphabetically less than the
48print name of s_arg2.
49.Lf append "'l_arg1 'l_arg2"
50.Re
51a list containing the elemens of l_arg1 followed by l_arg2.
52.No
53To generate the result, the top level list cells of l_arg1 are duplicated
54and the cdr of the last list cell is set to point to l_arg2.
55Thus this is an expensive operation if l_arg1 is large.
56See the description of nconc for a cheaper way of doing the append.
57.Lf append1 "'l_arg1 'g_arg2"
58.Re
59a list like l_arg1 with g_arg2 as the last element.
60.No
61this is equivalent to (append 'l_arg1 (list 'g_arg2)).
62.Lf array "s_name s_type x_dim1 ... x_dim\fIi\fP"
63.No
64this is the same as *array except the arguments are not evaluated.
65.Lf arraycall "'s_type 'a_array 'x_ind1 ... "
66.Re
67the element selected by the indicies from the array a_array
68of type s_type.
69.Lf arraydims "'s_name"
70.Re
71a list of the type and bounds of the array s_name.
72.Lf arrayp "'g_arg"
73.Re
74t iff g_arg is of type array.
75.Lf arrayref "'s_name 'x_ind"
76.Re
77the x_ind\fIth\fP element of the array associated with s_name.
78x_ind of zero accesses the first element.
79.\".pg
80.Lf assoc "'g_arg1 'l_arg2"
81.Re
82the first top level element of l_arg2 whose
83.i car
84is
85.i equal
86to g_arg1.
87.No
88the test is make with the lisp function equal.
89Usually l_arg2 has an
90.i a-list
91structure and g_arg1 acts as key.
92.Lf assq "'g_arg1 'l_arg2"
93.Re
94the first top element of l_arg2 whose
95.i car
96is
97equal to g_arg1 using the
98lisp function
99.i eq.
100.No
101This is faster than assoc since eq is faster than equal but
102lisp objects which print alike are not always
103.i eq.
104See the description of eq for more details.
105.Lf atom "'g_arg"
106.Re
107t iff g_arg is not a list cell.
108.No
109(atom '()) returns t.
110.Lf bcdp "'g_arg"
111.Re
112t iff g_arg is a data object of type binary.
113.No
114the name of this function is a throwback to the PDP-11 Lisp system.
115.Lf bigp "'g_arg"
116.Re
117t iff g_arg is a bignum.
118.Lf c\.\.r "'l_arg"
119.Wh
120\.\. is any positive number of \fBa\fP's and \fBd\fP's.
121.Re
122the result of accessing the list structure in the way determined by
123the function name.
124The \fBa\fP's and \fBd\fP's are read from right to left, a
125.b d
126directing the access down the cdr part of the list cell and an
127.b a
128down the car part.
129.No
130l_arg may also be nil, and it is guaranteed that the car and cdr of nil
131is nil.
132.br
133Currently one may disect bignums with c..r as well although this is
134subject to change.
135.\".pg
136.Lf concat "['s_arg1 ... ]"
137.Re
138a symbol whose print name
139is the result of concatenating the print names
140of the s_arg\fIi\fP.
141.No
142If no arguments are given, a symbol with a null pname is returned.
143Concat places the symbol created on the oblist, the function uconcat
144does the same thing but does not place the new symbol on the oblist.
145.Lf cons "'g_arg1 'g_arg2"
146.Re
147a new list cell whose car is g_arg1 and whose cdr is g_arg2.
148.Lf copy "'g_arg"
149.Re
150A structure
151.i equal
152to g_arg but with new list cells.
153.Lf defprop "s_atm g_val g_ind"
154.Re
155g_val.
156.Se
157The property list of s_atm is updated by adding g_val as the value
158of indicator g_ind.
159.No
160this is similar to putprop except that the arguments to defprop
161are not evaluated.
162.Lf delete "'g_val 'l_list ['x_count]"
163.Re
164the result of splicing g_val from the top level of
165l_list no more than x_count times.
166.No
167x_count defaults to a very large number, thus if x_count is not given, all
168occurances of g_val are removed from the top level of l_list.
169g_val is compared with successive
170.i car 's
171of l_list using the function
172.i equal .
173.Se
174l_list is modifed using rplacd, no new list cells are used.
175.Lf delq "'g_val 'l_list ['x_count]"
176.Re
177the result of splicing g_val from the top level of l_list no more than
178x_count times.
179.No
180.i delq
181is the same as
182.i delete
183except that
184.i eq
185is used for comparison instead of
186.i equal .
187.Lf dtpr "'g_arg"
188.Re
189t iff g_arg is a list cell.
190.No
191that (dtpr '()) is nil.
192.Lf eq "'g_arg1 'g_arg2"
193.Re
194t if g_arg1 and g_arg2 are the exact same lisp object.
195.No
196.i Eq
197simply tests if g_arg1 and g_arg2 are located in the exact same
198place in memory.
199Lisp objects which print the same are not necessarily
200.i eq .
201The only objects guaranteed to be
202.i eq
203are interned symbols with the same print name.
204[Unless a symbol is created in a special way (such as with
205uconcat or maknam)
206it will be interned.]
207.Lf equal "'g_arg1 'g_arg2"
208.Re
209t iff g_arg1 and g_arg2 have the same structure as described below.
210.No
211g_arg and g_arg2 are
212.i equal
213if
214.np
215they are eq.
216.np
217they are both fixnums with the same value
218.np
219they are both flonums with the same value
220.np
221they are both bignums with the same value
222.np
223they are both lists and their cars and cdrs are
224.i equal .
225.\".pg
226.Lf explode "'g_arg"
227.Re
228a list of single character symbols which
229.i print
230would use to print g_arg.
231.Lf explodec "'g_val"
232.Re
233the list of characters which print would use to print g_val except that
234special characters in symbols are
235not escaped (just as if patom were used to print them).
236.Lf exploden "'g_val"
237.Re
238a list of fixnums which print would use to print g_val except that
239special characters in symbols are not escaped
240(just as if patom were used to print them).
241.Lf fillarray "'s_array 'l_itms"
242.Re
243s_array
244.Se
245the array s_array is filled with elements from l_itms.
246If there are not enough elements in l_itms to fill the entire array,
247then the last element of l_itms is used to fill the remaining parts
248of the array.
249.Lf gensym "'s_leader"
250.Re
251a new uninterned atom beginning with the first character of s_leader's
252pname, or beginning with g if s_leader is not given.
253.No
254The symbol looks like x0nnnnn where x is s_leader's first character and
255nnnnn is the number of times you have called gensym.
256.Lf get "'s_name 'g_ind"
257.Re
258the value under indicator g_ind in s_name's property list.
259.No
260If there is no indicator g_ind in s_name's property list nil is returned.
261If the first argument is not a symbol or disembodied property
262list, nil is returned (than atom but e lack of er,
263aclisp).
264.Lf get_pname "'s_arg"
265.Re
266the string which is the print name of s_arg.
267.\".pg
268.Lf getaccess "'a_array"
269.Re
270the access function for the array a_array.
271.Rm
272.Lf getaux "'a_array"
273.Re
274the auxilliary field for the array a_array.
275.Rm
276.Lf getchar "'s_arg 'x_index"
277.Re
278the x_index'th character of the print name of s_arg or nil if x_index
279is less than 1 or greater than the length of s_arg's print name.
280.Lf getcharn "'s_arg 'x_index"
281.Re
282the fixnum representation of the x_index'th character
283of the print name of s_arg or nil if x_index
284is less than 1 or greater than the length of s_arg's print name.
285.Lf getd "'s_arg"
286.Re
287the function definition of s_arg or nil if there is no function definition.
288.Lf getdelta "'a_array"
289.Re
290the delta field for a_array.
291.Rm
292.Lf getentry "'y_funchd"
293.Re
294the entry field of the binary y_funchd.
295.Rm
296.Lf getlength "'a_array"
297.Re
298the length field of the array a_array.
299.Rm
300.Lf implode "'l_arg"
301.Wh
302l_arg is a list of symbols and small fixnums.
303.Re
304The symbol whose print name is the result of concatentating the print names
305of the symbols in the list.
306Any fixnums are converted to the equivalent ascii character.
307.\".pg
308.Lf last "'l_arg"
309.Re
310the last list cell in the list l_arg.
311.No
312(last '(a b)) returns (b).
313.Lf length "'l_arg"
314.Re
315the number of elements in the top level of list l_arg.
316.Lf list "['g_arg1 ... ]"
317.Re
318a list whose elements are the g_arg\fIi\fP.
319.Lf maknam "'l_arg"
320.Re
321what implode would return except the resulting symbol is uninterned.
322.Lf marray "'g_data 's_access 'g_aux 'x_length 'x_delta"
323.Re
324an array type with the fields set up from the above arguments
325in the obvious way (see \(sc 1.3.9).
326.Lf member "'g_arg1 'l_arg2"
327.Re
328that part of the l_arg2 beginning with the first occurance
329of g_arg1.
330If g_arg1 is not in the top level of l_arg2, nil is returned.
331.No
332the test for equality is made with
333.i equal .
334.Lf memq "'g_arg1 'l_arg2"
335.Re.
336that part of the l_arg2 beginning with the first occurance
337of g_arg1.
338If g_arg1 is not in the top level of l_arg2, nil is returned.
339.No
340the test for equality is made with
341.i eq .
342.Lf nconc "'l_arg1 'l_arg2"
343.Re
344A list consisting of the elements of l_arg1 followed by the elements of
345l_arg2.
346.No
347The cdr of the last list cell of l_arg1 is changed to point to l_arg2.
348.\".pg
349.Lf ncons "'g_arg"
350.Re
351a new list cell with g_arg as car and nil as cdr.
352.Lf not "'g_arg"
353.Re
354t iff g_arg is nil.
355.Lf nreverse "'l_arg"
356.Re
357the reverse of l_arg.
358.No
359The reverse is done in place, that is the list structure is modified.
360No new list cells are allocated.
361.Lf nthelem "'n_arg1 'l_arg2"
362.Re
363The n_arg1'\fIst\fP element of the list l_arg2.
364.No
365If n_arg1 is non-positive or greater than the length
366of the list, nil is returned.
367.Lf null "'g_arg"
368.Re
369t iff g_arg is nil.
370.Eq
371not.
372.Lf plist "'s_name"
373.Re
374the property list of s_name.
375.Lf putaccess "'a_array 's_func"
376.Re
377s_func.
378.Se
379replaces the access field of a_array with s_func.
380.Rm
381.Lf putaux "'a_array 'g_aux"
382.Re
383s_aux.
384.Se
385replaces the auxillary field of a_array with g_aux.
386.Rm
387.\".pg
388.Lf putdelta "'a_array 'x_delta"
389.Re
390x_delta.
391.Se
392replaces the delta field of a_array with x_delta.
393.Rm
394.Lf putlength "'a_array 'x_length"
395.Re
396x_length
397.Se
398replaces the length field of a_array with x_length.
399.Rm
400.Lf putprop "'s_name 'g_val 'g_ind"
401.Re
402g_val.
403.Se
404Adds to the property list of s_name the value g_val under the indicator
405g_ind.
406.No
407this is similar to defprop except the arguments are evaluated to putprop.
408.Lf quote "g_arg"
409.Re
410g_arg.
411.No
412the reader allows you to abbreviate (quote foo) as 'foo.
413.Lf remprop "'s_name 'g_ind"
414.Re
415the portion of s_name's property list beginning with the
416property under the indicator g_ind.
417If there is no g_ind indicator in s_name's plist, nil is returned.
418.Se
419the value under indicator g_ind and g_ind itself is removed from
420the property list of s_name.
421.Lf replace "'g_arg1 'g_arg2"
422.Wh
423g_arg1 and g_arg2 must be the same type of lispval and not symbols.
424.Re
425g_arg2.
426.Se
427the contents of lispval g_arg1 is replaced by the contents of lispval g_arg2.
428.\".pg
429.Lf reverse "'l_arg"
430.Re
431the reverse of the list l_arg.
432.No
433The reverse is performed by allocating new list cells to duplicate
434the top level of l_arg. This can be expensive if l_arg is large.
435The function nreverse will reverse the list without allocating
436new list cells.
437.Lf rplaca "'l_arg1 'g_arg2"
438.Re
439the modified l_arg1.
440.Se
441the car of l_arg1 is set to g_arg2.
442.Lf rplacd "'l_arg1 'g_arg2"
443.Re
444the modified l_arg1.
445.Se
446the cdr of l_arg2 is set to g_arg2
447.Lf set "'s_arg1 'g_arg2"
448.Re
449g_arg2.
450.Se
451the value of s_arg1 is set to g_arg2.
452.Lf setplist "'s_atm 'l_plist"
453.Re
454l_plist.
455.Se
456the property list of s_atm is set to l_plist.
457.Lf setq "s_atm1 'g_val1 [ s_atm2 'g_val2 ... ... ]"
458.Wh
459the arguments are pairs of atom names and expressions.
460.Re
461the last g_val\fIi\fP.
462.Se
463each s_atm\fIi\fP is set to have the value g_val\fIi\fP.
464.Lf stringp "'g_arg"
465.Re
466t iff g_arg is a string.
467.Lf symbolp "'g_arg"
468.Re
469t iff g_arg is an symbol.
470.Lf type "'g_arg"
471.Re
472an symbol whose pname describes the type of g_arg.
473.\".pg
474.Lf typep "'g_arg"
475.Eq
476type.
477.Lf uconcat "['s_arg1 ... ]"
478.Re
479a symbol whose pname is the result of concatenating the print names (pnames)
480of the s_arg\fIi\fP.
481.No
482If no arguments are given, a symbol with a null pname is returned.
483Uconcat does not place the symbol created on the oblist, the function concat
484does the same thing but does place the new symbol on the oblist.
485.Lf valuep "'g_arg"
486.Re
487t iff g_arg is a value cell