2001-04-09 Martin Grabmueller <mgrabmue@cs.tu-berlin.de>
[bpt/guile.git] / doc / scheme-utility.texi
CommitLineData
38a93523
NJ
1@page
2@node Utility Functions
3@chapter General Utility Functions
4
5@menu
6* Equality:: When are two values `the same'?
7* Property Lists:: Managing metainformation about Scheme objects.
8* Primitive Properties:: A modern low-level interface to object properties.
9* Sorting:: Sort utility procedures.
10* Copying:: Copying deep structures.
11@end menu
12
13
14@node Equality
15@section Equality
16
5c4b24e1 17@rnindex eq?
38a93523
NJ
18@c docstring begin (texi-doc-string "guile" "eq?")
19@deffn primitive eq? x y
20Return @code{#t} iff @var{x} references the same object as @var{y}.
21@code{eq?} is similar to @code{eqv?} except that in some cases it is
22capable of discerning distinctions finer than those detectable by
23@code{eqv?}.
24@end deffn
25
5c4b24e1 26@rnindex eqv?
38a93523
NJ
27@c docstring begin (texi-doc-string "guile" "eqv?")
28@deffn primitive eqv? x y
29The @code{eqv?} procedure defines a useful equivalence relation on objects.
30Briefly, it returns @code{#t} if @var{x} and @var{y} should normally be
31regarded as the same object. This relation is left slightly open to
32interpretation, but works for comparing immediate integers, characters,
33and inexact numbers.
34@end deffn
35
5c4b24e1 36@rnindex equal?
38a93523
NJ
37@c docstring begin (texi-doc-string "guile" "equal?")
38@deffn primitive equal? x y
39Return @code{#t} iff @var{x} and @var{y} are recursively @code{eqv?} equivalent.
40@code{equal?} recursively compares the contents of pairs,
41vectors, and strings, applying @code{eqv?} on other objects such as
42numbers and symbols. A rule of thumb is that objects are generally
43@code{equal?} if they print the same. @code{equal?} may fail to
44terminate if its arguments are circular data structures.
45@end deffn
46
47
48@node Property Lists
49@section Property Lists
50
51Every object in the system can have a @dfn{property list} that may
52be used for information about that object. For example, a
53function may have a property list that includes information about
54the source file in which it is defined.
55
56Property lists are implemented as assq lists (@pxref{Association Lists}).
57
58Currently, property lists are implemented differently for procedures and
59closures than for other kinds of objects. Therefore, when manipulating
60a property list associated with a procedure object, use the
61@code{procedure} functions; otherwise, use the @code{object} functions.
62
63@c docstring begin (texi-doc-string "guile" "object-properties")
64@deffn primitive object-properties obj
65@deffnx primitive procedure-properties obj
66Return @var{obj}'s property list.
67@end deffn
68
38a93523 69@c docstring begin (texi-doc-string "guile" "set-object-properties!")
ae9f3a15 70@deffn primitive set-object-properties! obj alist
38a93523
NJ
71@deffnx primitive set-procedure-properties! obj alist
72Set @var{obj}'s property list to @var{alist}.
73@end deffn
74
75@c docstring begin (texi-doc-string "guile" "object-property")
76@deffn primitive object-property obj key
77@deffnx primitive procedure-property obj key
78Return the property of @var{obj} with name @var{key}.
79@end deffn
80
38a93523 81@c docstring begin (texi-doc-string "guile" "set-object-property!")
ae9f3a15 82@deffn primitive set-object-property! obj key value
38a93523 83@deffnx primitive set-procedure-property! obj key value
ae9f3a15
MG
84In @var{obj}'s property list, set the property named @var{key}
85to @var{value}.
38a93523
NJ
86@end deffn
87
88[Interface bug: there should be a second level of interface in which
89the user provides a "property table" that is possibly private.]
90
91
92@node Primitive Properties
93@section Primitive Properties
94
95@c docstring begin (texi-doc-string "guile" "primitive-make-property")
96@deffn primitive primitive-make-property not_found_proc
97Create a @dfn{property token} that can be used with
98@code{primitive-property-ref} and @code{primitive-property-set!}.
99See @code{primitive-property-ref} for the significance of
100@var{not_found_proc}.
101@end deffn
102
103@c docstring begin (texi-doc-string "guile" "primitive-property-ref")
104@deffn primitive primitive-property-ref prop obj
105Return the property @var{prop} of @var{obj}. When no value
106has yet been associated with @var{prop} and @var{obj}, call
107@var{not-found-proc} instead (see @code{primitive-make-property})
108and use its return value. That value is also associated with
109@var{obj} via @code{primitive-property-set!}. When
110@var{not-found-proc} is @code{#f}, use @code{#f} as the
111default value of @var{prop}.
112@end deffn
113
114@c docstring begin (texi-doc-string "guile" "primitive-property-set!")
115@deffn primitive primitive-property-set! prop obj val
116Associate @var{code} with @var{prop} and @var{obj}.
117@end deffn
118
119@c docstring begin (texi-doc-string "guile" "primitive-property-del!")
120@deffn primitive primitive-property-del! prop obj
121Remove any value associated with @var{prop} and @var{obj}.
122@end deffn
123
124
125@node Sorting
126@section Sorting
127
128@c docstring begin (texi-doc-string "guile" "merge!")
129@deffn primitive merge! alist blist less
130Takes two lists @var{alist} and @var{blist} such that
131@code{(sorted? alist less?)} and @code{(sorted? blist less?)} and
132returns a new list in which the elements of @var{alist} and
133@var{blist} have been stably interleaved so that
134 @code{(sorted? (merge alist blist less?) less?)}.
135This is the destructive variant of @code{merge}
136Note: this does _not_ accept vectors.
137@end deffn
138
139@c docstring begin (texi-doc-string "guile" "merge")
140@deffn primitive merge alist blist less
141@end deffn
142
143@c docstring begin (texi-doc-string "guile" "restricted-vector-sort!")
144@deffn primitive restricted-vector-sort! vec less startpos endpos
145Sort the vector @var{vec}, using @var{less} for comparing
146the vector elements. @var{startpos} and @var{endpos} delimit
147the range of the vector which gets sorted. The return value
148is not specified.
149@end deffn
150
151@c docstring begin (texi-doc-string "guile" "sort!")
152@deffn primitive sort! items less
153Sort the sequence @var{items}, which may be a list or a
154vector. @var{less} is used for comparing the sequence
155elements. The sorting is destructive, that means that the
156input sequence is modified to produce the sorted result.
157This is not a stable sort.
158@end deffn
159
160@c docstring begin (texi-doc-string "guile" "sort")
161@deffn primitive sort items less
162Sort the sequence @var{items}, which may be a list or a
163vector. @var{less} is used for comparing the sequence
164elements. This is not a stable sort.
165@end deffn
166
167@c docstring begin (texi-doc-string "guile" "sort-list!")
168@deffn primitive sort-list! items less
169Sort the list @var{items}, using @var{less} for comparing the
170list elements. The sorting is destructive, that means that the
171input list is modified to produce the sorted result.
172This is a stable sort.
173@end deffn
174
175@c docstring begin (texi-doc-string "guile" "sort-list")
176@deffn primitive sort-list items less
177Sort the list @var{items}, using @var{less} for comparing the
178list elements. This is a stable sort.
179@end deffn
180
181@c docstring begin (texi-doc-string "guile" "sorted?")
182@deffn primitive sorted? items less
183Return @code{#t} iff @var{items} is a list or a vector such that
184for all 1 <= i <= m, the predicate @var{less} returns true when
185applied to all elements i - 1 and i
186@end deffn
187
188@c docstring begin (texi-doc-string "guile" "stable-sort!")
189@deffn primitive stable-sort! items less
190Sort the sequence @var{items}, which may be a list or a
191vector. @var{less} is used for comparing the sequence elements.
192The sorting is destructive, that means that the input sequence
193is modified to produce the sorted result.
194This is a stable sort.
195@end deffn
196
197@c docstring begin (texi-doc-string "guile" "stable-sort")
198@deffn primitive stable-sort items less
199Sort the sequence @var{items}, which may be a list or a
200vector. @var{less} is used for comparing the sequence elements.
201This is a stable sort.
202@end deffn
203
204
205@node Copying
206@section Copying Deep Structures
207
208@c docstring begin (texi-doc-string "guile" "copy-tree")
209@deffn primitive copy-tree obj
210Recursively copy the data tree that is bound to @var{obj}, and return a
211pointer to the new data structure. @code{copy-tree} recurses down the
212contents of both pairs and vectors (since both cons cells and vector
213cells may point to arbitrary objects), and stops recursing when it hits
214any other object.
215@end deffn
216
217
218@c Local Variables:
219@c TeX-master: "guile.texi"
220@c End: