* syncase.scm: fix bad let.
[bpt/guile.git] / doc / maint / guile.texi
CommitLineData
780ee65e
NJ
1@paragraphindent 0
2
3\facons
8f85c0c6
NJ
4@deffn {Scheme Procedure} acons key value alist
5@deffnx {C Function} scm_acons (key, value, alist)
6Add a new key-value pair to @var{alist}. A new pair is
780ee65e
NJ
7created whose car is @var{key} and whose cdr is @var{value}, and the
8pair is consed onto @var{alist}, and the new list is returned. This
9function is @emph{not} destructive; @var{alist} is not modified.
10@end deffn
11
12\fsloppy-assq
8f85c0c6
NJ
13@deffn {Scheme Procedure} sloppy-assq key alist
14@deffnx {C Function} scm_sloppy_assq (key, alist)
780ee65e
NJ
15Behaves like @code{assq} but does not do any error checking.
16Recommended only for use in Guile internals.
17@end deffn
18
19\fsloppy-assv
8f85c0c6
NJ
20@deffn {Scheme Procedure} sloppy-assv key alist
21@deffnx {C Function} scm_sloppy_assv (key, alist)
780ee65e
NJ
22Behaves like @code{assv} but does not do any error checking.
23Recommended only for use in Guile internals.
24@end deffn
25
26\fsloppy-assoc
8f85c0c6
NJ
27@deffn {Scheme Procedure} sloppy-assoc key alist
28@deffnx {C Function} scm_sloppy_assoc (key, alist)
780ee65e
NJ
29Behaves like @code{assoc} but does not do any error checking.
30Recommended only for use in Guile internals.
31@end deffn
32
33\fassq
8f85c0c6
NJ
34@deffn {Scheme Procedure} assq key alist
35@deffnx {Scheme Procedure} assv key alist
36@deffnx {Scheme Procedure} assoc key alist
37@deffnx {C Function} scm_assq (key, alist)
38Fetch the entry in @var{alist} that is associated with @var{key}. To
780ee65e
NJ
39decide whether the argument @var{key} matches a particular entry in
40@var{alist}, @code{assq} compares keys with @code{eq?}, @code{assv}
41uses @code{eqv?} and @code{assoc} uses @code{equal?}. If @var{key}
42cannot be found in @var{alist} (according to whichever equality
8f85c0c6 43predicate is in use), then return @code{#f}. These functions
780ee65e
NJ
44return the entire alist entry found (i.e. both the key and the value).
45@end deffn
46
47\fassv
8f85c0c6
NJ
48@deffn {Scheme Procedure} assv key alist
49@deffnx {C Function} scm_assv (key, alist)
780ee65e
NJ
50Behaves like @code{assq} but uses @code{eqv?} for key comparison.
51@end deffn
52
53\fassoc
8f85c0c6
NJ
54@deffn {Scheme Procedure} assoc key alist
55@deffnx {C Function} scm_assoc (key, alist)
780ee65e
NJ
56Behaves like @code{assq} but uses @code{equal?} for key comparison.
57@end deffn
58
59\fassq-ref
8f85c0c6
NJ
60@deffn {Scheme Procedure} assq-ref alist key
61@deffnx {Scheme Procedure} assv-ref alist key
62@deffnx {Scheme Procedure} assoc-ref alist key
63@deffnx {C Function} scm_assq_ref (alist, key)
780ee65e
NJ
64Like @code{assq}, @code{assv} and @code{assoc}, except that only the
65value associated with @var{key} in @var{alist} is returned. These
66functions are equivalent to
67
68@lisp
69(let ((ent (@var{associator} @var{key} @var{alist})))
70 (and ent (cdr ent)))
71@end lisp
72
73where @var{associator} is one of @code{assq}, @code{assv} or @code{assoc}.
74@end deffn
75
76\fassv-ref
8f85c0c6
NJ
77@deffn {Scheme Procedure} assv-ref alist key
78@deffnx {C Function} scm_assv_ref (alist, key)
780ee65e
NJ
79Behaves like @code{assq-ref} but uses @code{eqv?} for key comparison.
80@end deffn
81
82\fassoc-ref
8f85c0c6
NJ
83@deffn {Scheme Procedure} assoc-ref alist key
84@deffnx {C Function} scm_assoc_ref (alist, key)
780ee65e
NJ
85Behaves like @code{assq-ref} but uses @code{equal?} for key comparison.
86@end deffn
87
88\fassq-set!
8f85c0c6
NJ
89@deffn {Scheme Procedure} assq-set! alist key val
90@deffnx {Scheme Procedure} assv-set! alist key value
91@deffnx {Scheme Procedure} assoc-set! alist key value
92@deffnx {C Function} scm_assq_set_x (alist, key, val)
780ee65e
NJ
93Reassociate @var{key} in @var{alist} with @var{value}: find any existing
94@var{alist} entry for @var{key} and associate it with the new
95@var{value}. If @var{alist} does not contain an entry for @var{key},
96add a new one. Return the (possibly new) alist.
97
98These functions do not attempt to verify the structure of @var{alist},
99and so may cause unusual results if passed an object that is not an
100association list.
101@end deffn
102
103\fassv-set!
8f85c0c6
NJ
104@deffn {Scheme Procedure} assv-set! alist key val
105@deffnx {C Function} scm_assv_set_x (alist, key, val)
780ee65e
NJ
106Behaves like @code{assq-set!} but uses @code{eqv?} for key comparison.
107@end deffn
108
109\fassoc-set!
8f85c0c6
NJ
110@deffn {Scheme Procedure} assoc-set! alist key val
111@deffnx {C Function} scm_assoc_set_x (alist, key, val)
780ee65e
NJ
112Behaves like @code{assq-set!} but uses @code{equal?} for key comparison.
113@end deffn
114
115\fassq-remove!
8f85c0c6
NJ
116@deffn {Scheme Procedure} assq-remove! alist key
117@deffnx {Scheme Procedure} assv-remove! alist key
118@deffnx {Scheme Procedure} assoc-remove! alist key
119@deffnx {C Function} scm_assq_remove_x (alist, key)
780ee65e
NJ
120Delete the first entry in @var{alist} associated with @var{key}, and return
121the resulting alist.
122@end deffn
123
124\fassv-remove!
8f85c0c6
NJ
125@deffn {Scheme Procedure} assv-remove! alist key
126@deffnx {C Function} scm_assv_remove_x (alist, key)
780ee65e
NJ
127Behaves like @code{assq-remove!} but uses @code{eqv?} for key comparison.
128@end deffn
129
130\fassoc-remove!
8f85c0c6
NJ
131@deffn {Scheme Procedure} assoc-remove! alist key
132@deffnx {C Function} scm_assoc_remove_x (alist, key)
780ee65e
NJ
133Behaves like @code{assq-remove!} but uses @code{equal?} for key comparison.
134@end deffn
135
136\fmake-arbiter
8f85c0c6
NJ
137@deffn {Scheme Procedure} make-arbiter name
138@deffnx {C Function} scm_make_arbiter (name)
780ee65e
NJ
139Return an object of type arbiter and name @var{name}. Its
140state is initially unlocked. Arbiters are a way to achieve
141process synchronization.
142@end deffn
143
144\ftry-arbiter
8f85c0c6
NJ
145@deffn {Scheme Procedure} try-arbiter arb
146@deffnx {C Function} scm_try_arbiter (arb)
780ee65e
NJ
147Return @code{#t} and lock the arbiter @var{arb} if the arbiter
148was unlocked. Otherwise, return @code{#f}.
149@end deffn
150
151\frelease-arbiter
8f85c0c6
NJ
152@deffn {Scheme Procedure} release-arbiter arb
153@deffnx {C Function} scm_release_arbiter (arb)
780ee65e
NJ
154Return @code{#t} and unlock the arbiter @var{arb} if the
155arbiter was locked. Otherwise, return @code{#f}.
156@end deffn
157
158\fasync
8f85c0c6
NJ
159@deffn {Scheme Procedure} async thunk
160@deffnx {C Function} scm_async (thunk)
780ee65e
NJ
161Create a new async for the procedure @var{thunk}.
162@end deffn
163
164\fsystem-async
8f85c0c6
NJ
165@deffn {Scheme Procedure} system-async thunk
166@deffnx {C Function} scm_system_async (thunk)
780ee65e
NJ
167Create a new async for the procedure @var{thunk}. Also
168add it to the system's list of active async objects.
169@end deffn
170
171\fasync-mark
8f85c0c6
NJ
172@deffn {Scheme Procedure} async-mark a
173@deffnx {C Function} scm_async_mark (a)
780ee65e
NJ
174Mark the async @var{a} for future execution.
175@end deffn
176
177\fsystem-async-mark
8f85c0c6
NJ
178@deffn {Scheme Procedure} system-async-mark a
179@deffnx {C Function} scm_system_async_mark (a)
780ee65e
NJ
180Mark the async @var{a} for future execution.
181@end deffn
182
183\frun-asyncs
8f85c0c6
NJ
184@deffn {Scheme Procedure} run-asyncs list_of_a
185@deffnx {C Function} scm_run_asyncs (list_of_a)
780ee65e
NJ
186Execute all thunks from the asyncs of the list @var{list_of_a}.
187@end deffn
188
189\fnoop
8f85c0c6
NJ
190@deffn {Scheme Procedure} noop . args
191@deffnx {C Function} scm_noop (args)
780ee65e
NJ
192Do nothing. When called without arguments, return @code{#f},
193otherwise return the first argument.
194@end deffn
195
196\funmask-signals
8f85c0c6
NJ
197@deffn {Scheme Procedure} unmask-signals
198@deffnx {C Function} scm_unmask_signals ()
780ee65e
NJ
199Unmask signals. The returned value is not specified.
200@end deffn
201
202\fmask-signals
8f85c0c6
NJ
203@deffn {Scheme Procedure} mask-signals
204@deffnx {C Function} scm_mask_signals ()
780ee65e
NJ
205Mask signals. The returned value is not specified.
206@end deffn
207
208\fdisplay-error
8f85c0c6
NJ
209@deffn {Scheme Procedure} display-error stack port subr message args rest
210@deffnx {C Function} scm_display_error (stack, port, subr, message, args, rest)
780ee65e
NJ
211Display an error message to the output port @var{port}.
212@var{stack} is the saved stack for the error, @var{subr} is
213the name of the procedure in which the error occured and
214@var{message} is the actual error message, which may contain
215formatting instructions. These will format the arguments in
216the list @var{args} accordingly. @var{rest} is currently
217ignored.
218@end deffn
219
220\fdisplay-application
8f85c0c6
NJ
221@deffn {Scheme Procedure} display-application frame [port [indent]]
222@deffnx {C Function} scm_display_application (frame, port, indent)
780ee65e
NJ
223Display a procedure application @var{frame} to the output port
224@var{port}. @var{indent} specifies the indentation of the
225output.
226@end deffn
227
228\fdisplay-backtrace
8f85c0c6
NJ
229@deffn {Scheme Procedure} display-backtrace stack port [first [depth]]
230@deffnx {C Function} scm_display_backtrace (stack, port, first, depth)
780ee65e
NJ
231Display a backtrace to the output port @var{port}. @var{stack}
232is the stack to take the backtrace from, @var{first} specifies
233where in the stack to start and @var{depth} how much frames
234to display. Both @var{first} and @var{depth} can be @code{#f},
235which means that default values will be used.
236@end deffn
237
238\fbacktrace
8f85c0c6
NJ
239@deffn {Scheme Procedure} backtrace
240@deffnx {C Function} scm_backtrace ()
780ee65e
NJ
241Display a backtrace of the stack saved by the last error
242to the current output port.
243@end deffn
244
245\fnot
8f85c0c6
NJ
246@deffn {Scheme Procedure} not x
247@deffnx {C Function} scm_not (x)
780ee65e
NJ
248Return @code{#t} iff @var{x} is @code{#f}, else return @code{#f}.
249@end deffn
250
251\fboolean?
8f85c0c6
NJ
252@deffn {Scheme Procedure} boolean? obj
253@deffnx {C Function} scm_boolean_p (obj)
780ee65e
NJ
254Return @code{#t} iff @var{obj} is either @code{#t} or @code{#f}.
255@end deffn
256
257\fchar?
8f85c0c6
NJ
258@deffn {Scheme Procedure} char? x
259@deffnx {C Function} scm_char_p (x)
780ee65e
NJ
260Return @code{#t} iff @var{x} is a character, else @code{#f}.
261@end deffn
262
263\fchar=?
8f85c0c6 264@deffn {Scheme Procedure} char=? x y
780ee65e
NJ
265Return @code{#t} iff @var{x} is the same character as @var{y}, else @code{#f}.
266@end deffn
267
268\fchar<?
8f85c0c6 269@deffn {Scheme Procedure} char<? x y
780ee65e
NJ
270Return @code{#t} iff @var{x} is less than @var{y} in the ASCII sequence,
271else @code{#f}.
272@end deffn
273
274\fchar<=?
8f85c0c6 275@deffn {Scheme Procedure} char<=? x y
780ee65e
NJ
276Return @code{#t} iff @var{x} is less than or equal to @var{y} in the
277ASCII sequence, else @code{#f}.
278@end deffn
279
280\fchar>?
8f85c0c6 281@deffn {Scheme Procedure} char>? x y
780ee65e
NJ
282Return @code{#t} iff @var{x} is greater than @var{y} in the ASCII
283sequence, else @code{#f}.
284@end deffn
285
286\fchar>=?
8f85c0c6 287@deffn {Scheme Procedure} char>=? x y
780ee65e
NJ
288Return @code{#t} iff @var{x} is greater than or equal to @var{y} in the
289ASCII sequence, else @code{#f}.
290@end deffn
291
292\fchar-ci=?
8f85c0c6 293@deffn {Scheme Procedure} char-ci=? x y
780ee65e
NJ
294Return @code{#t} iff @var{x} is the same character as @var{y} ignoring
295case, else @code{#f}.
296@end deffn
297
298\fchar-ci<?
8f85c0c6 299@deffn {Scheme Procedure} char-ci<? x y
780ee65e
NJ
300Return @code{#t} iff @var{x} is less than @var{y} in the ASCII sequence
301ignoring case, else @code{#f}.
302@end deffn
303
304\fchar-ci<=?
8f85c0c6 305@deffn {Scheme Procedure} char-ci<=? x y
780ee65e
NJ
306Return @code{#t} iff @var{x} is less than or equal to @var{y} in the
307ASCII sequence ignoring case, else @code{#f}.
308@end deffn
309
310\fchar-ci>?
8f85c0c6 311@deffn {Scheme Procedure} char-ci>? x y
780ee65e
NJ
312Return @code{#t} iff @var{x} is greater than @var{y} in the ASCII
313sequence ignoring case, else @code{#f}.
314@end deffn
315
316\fchar-ci>=?
8f85c0c6 317@deffn {Scheme Procedure} char-ci>=? x y
780ee65e
NJ
318Return @code{#t} iff @var{x} is greater than or equal to @var{y} in the
319ASCII sequence ignoring case, else @code{#f}.
320@end deffn
321
322\fchar-alphabetic?
8f85c0c6
NJ
323@deffn {Scheme Procedure} char-alphabetic? chr
324@deffnx {C Function} scm_char_alphabetic_p (chr)
780ee65e
NJ
325Return @code{#t} iff @var{chr} is alphabetic, else @code{#f}.
326Alphabetic means the same thing as the isalpha C library function.
327@end deffn
328
329\fchar-numeric?
8f85c0c6
NJ
330@deffn {Scheme Procedure} char-numeric? chr
331@deffnx {C Function} scm_char_numeric_p (chr)
780ee65e
NJ
332Return @code{#t} iff @var{chr} is numeric, else @code{#f}.
333Numeric means the same thing as the isdigit C library function.
334@end deffn
335
336\fchar-whitespace?
8f85c0c6
NJ
337@deffn {Scheme Procedure} char-whitespace? chr
338@deffnx {C Function} scm_char_whitespace_p (chr)
780ee65e
NJ
339Return @code{#t} iff @var{chr} is whitespace, else @code{#f}.
340Whitespace means the same thing as the isspace C library function.
341@end deffn
342
343\fchar-upper-case?
8f85c0c6
NJ
344@deffn {Scheme Procedure} char-upper-case? chr
345@deffnx {C Function} scm_char_upper_case_p (chr)
780ee65e
NJ
346Return @code{#t} iff @var{chr} is uppercase, else @code{#f}.
347Uppercase means the same thing as the isupper C library function.
348@end deffn
349
350\fchar-lower-case?
8f85c0c6
NJ
351@deffn {Scheme Procedure} char-lower-case? chr
352@deffnx {C Function} scm_char_lower_case_p (chr)
780ee65e
NJ
353Return @code{#t} iff @var{chr} is lowercase, else @code{#f}.
354Lowercase means the same thing as the islower C library function.
355@end deffn
356
357\fchar-is-both?
8f85c0c6
NJ
358@deffn {Scheme Procedure} char-is-both? chr
359@deffnx {C Function} scm_char_is_both_p (chr)
780ee65e
NJ
360Return @code{#t} iff @var{chr} is either uppercase or lowercase, else @code{#f}.
361Uppercase and lowercase are as defined by the isupper and islower
362C library functions.
363@end deffn
364
365\fchar->integer
8f85c0c6
NJ
366@deffn {Scheme Procedure} char->integer chr
367@deffnx {C Function} scm_char_to_integer (chr)
780ee65e
NJ
368Return the number corresponding to ordinal position of @var{chr} in the
369ASCII sequence.
370@end deffn
371
372\finteger->char
8f85c0c6
NJ
373@deffn {Scheme Procedure} integer->char n
374@deffnx {C Function} scm_integer_to_char (n)
780ee65e
NJ
375Return the character at position @var{n} in the ASCII sequence.
376@end deffn
377
378\fchar-upcase
8f85c0c6
NJ
379@deffn {Scheme Procedure} char-upcase chr
380@deffnx {C Function} scm_char_upcase (chr)
780ee65e
NJ
381Return the uppercase character version of @var{chr}.
382@end deffn
383
384\fchar-downcase
8f85c0c6
NJ
385@deffn {Scheme Procedure} char-downcase chr
386@deffnx {C Function} scm_char_downcase (chr)
780ee65e
NJ
387Return the lowercase character version of @var{chr}.
388@end deffn
389
390\fdebug-options-interface
8f85c0c6
NJ
391@deffn {Scheme Procedure} debug-options-interface [setting]
392@deffnx {C Function} scm_debug_options (setting)
780ee65e
NJ
393Option interface for the debug options. Instead of using
394this procedure directly, use the procedures @code{debug-enable},
395@code{debug-disable}, @code{debug-set!} and @var{debug-options}.
396@end deffn
397
398\fwith-traps
8f85c0c6
NJ
399@deffn {Scheme Procedure} with-traps thunk
400@deffnx {C Function} scm_with_traps (thunk)
780ee65e
NJ
401Call @var{thunk} with traps enabled.
402@end deffn
403
404\fmemoized?
8f85c0c6
NJ
405@deffn {Scheme Procedure} memoized? obj
406@deffnx {C Function} scm_memoized_p (obj)
780ee65e
NJ
407Return @code{#t} if @var{obj} is memoized.
408@end deffn
409
410\funmemoize
8f85c0c6
NJ
411@deffn {Scheme Procedure} unmemoize m
412@deffnx {C Function} scm_unmemoize (m)
780ee65e
NJ
413Unmemoize the memoized expression @var{m},
414@end deffn
415
416\fmemoized-environment
8f85c0c6
NJ
417@deffn {Scheme Procedure} memoized-environment m
418@deffnx {C Function} scm_memoized_environment (m)
780ee65e
NJ
419Return the environment of the memoized expression @var{m}.
420@end deffn
421
422\fprocedure-name
8f85c0c6
NJ
423@deffn {Scheme Procedure} procedure-name proc
424@deffnx {C Function} scm_procedure_name (proc)
780ee65e
NJ
425Return the name of the procedure @var{proc}
426@end deffn
427
428\fprocedure-source
8f85c0c6
NJ
429@deffn {Scheme Procedure} procedure-source proc
430@deffnx {C Function} scm_procedure_source (proc)
780ee65e
NJ
431Return the source of the procedure @var{proc}.
432@end deffn
433
434\fprocedure-environment
8f85c0c6
NJ
435@deffn {Scheme Procedure} procedure-environment proc
436@deffnx {C Function} scm_procedure_environment (proc)
780ee65e
NJ
437Return the environment of the procedure @var{proc}.
438@end deffn
439
440\flocal-eval
8f85c0c6
NJ
441@deffn {Scheme Procedure} local-eval exp [env]
442@deffnx {C Function} scm_local_eval (exp, env)
780ee65e
NJ
443Evaluate @var{exp} in its environment. If @var{env} is supplied,
444it is the environment in which to evaluate @var{exp}. Otherwise,
445@var{exp} must be a memoized code object (in which case, its environment
446is implicit).
447@end deffn
448
449\fdebug-object?
8f85c0c6
NJ
450@deffn {Scheme Procedure} debug-object? obj
451@deffnx {C Function} scm_debug_object_p (obj)
780ee65e
NJ
452Return @code{#t} if @var{obj} is a debug object.
453@end deffn
454
780ee65e 455\fdynamic-link
8f85c0c6
NJ
456@deffn {Scheme Procedure} dynamic-link filename
457@deffnx {C Function} scm_dynamic_link (filename)
ae9f3a15
MG
458Open the dynamic library called @var{filename}. A library
459handle representing the opened library is returned; this handle
460should be used as the @var{dobj} argument to the following
461functions.
780ee65e
NJ
462@end deffn
463
464\fdynamic-object?
8f85c0c6
NJ
465@deffn {Scheme Procedure} dynamic-object? obj
466@deffnx {C Function} scm_dynamic_object_p (obj)
780ee65e
NJ
467Return @code{#t} if @var{obj} is a dynamic library handle, or @code{#f}
468otherwise.
469@end deffn
470
471\fdynamic-unlink
8f85c0c6
NJ
472@deffn {Scheme Procedure} dynamic-unlink dobj
473@deffnx {C Function} scm_dynamic_unlink (dobj)
780ee65e 474Unlink the indicated object file from the application. The
ae9f3a15 475argument @var{dobj} must have been obtained by a call to
780ee65e 476@code{dynamic-link}. After @code{dynamic-unlink} has been
ae9f3a15 477called on @var{dobj}, its content is no longer accessible.
780ee65e
NJ
478@end deffn
479
480\fdynamic-func
8f85c0c6
NJ
481@deffn {Scheme Procedure} dynamic-func name dobj
482@deffnx {C Function} scm_dynamic_func (name, dobj)
780ee65e
NJ
483Search the dynamic object @var{dobj} for the C function
484indicated by the string @var{name} and return some Scheme
485handle that can later be used with @code{dynamic-call} to
486actually call the function.
487
488Regardless whether your C compiler prepends an underscore @samp{_} to
489the global names in a program, you should @strong{not} include this
490underscore in @var{function}. Guile knows whether the underscore is
491needed or not and will add it when necessary.
492@end deffn
493
494\fdynamic-call
8f85c0c6
NJ
495@deffn {Scheme Procedure} dynamic-call func dobj
496@deffnx {C Function} scm_dynamic_call (func, dobj)
ae9f3a15
MG
497Call the C function indicated by @var{func} and @var{dobj}.
498The function is passed no arguments and its return value is
499ignored. When @var{function} is something returned by
500@code{dynamic-func}, call that function and ignore @var{dobj}.
501When @var{func} is a string , look it up in @var{dynobj}; this
502is equivalent to
780ee65e 503@smallexample
ae9f3a15 504(dynamic-call (dynamic-func @var{func} @var{dobj} #f))
780ee65e
NJ
505@end smallexample
506
507Interrupts are deferred while the C function is executing (with
508@code{SCM_DEFER_INTS}/@code{SCM_ALLOW_INTS}).
509@end deffn
510
511\fdynamic-args-call
8f85c0c6
NJ
512@deffn {Scheme Procedure} dynamic-args-call func dobj args
513@deffnx {C Function} scm_dynamic_args_call (func, dobj, args)
ae9f3a15
MG
514Call the C function indicated by @var{func} and @var{dobj},
515just like @code{dynamic-call}, but pass it some arguments and
516return its return value. The C function is expected to take
517two arguments and return an @code{int}, just like @code{main}:
780ee65e
NJ
518@smallexample
519int c_func (int argc, char **argv);
520@end smallexample
521
ae9f3a15
MG
522The parameter @var{args} must be a list of strings and is
523converted into an array of @code{char *}. The array is passed
524in @var{argv} and its size in @var{argc}. The return value is
525converted to a Scheme number and returned from the call to
526@code{dynamic-args-call}.
780ee65e
NJ
527@end deffn
528
529\fdynamic-wind
8f85c0c6
NJ
530@deffn {Scheme Procedure} dynamic-wind in_guard thunk out_guard
531@deffnx {C Function} scm_dynamic_wind (in_guard, thunk, out_guard)
780ee65e 532All three arguments must be 0-argument procedures.
ae9f3a15
MG
533@var{in_guard} is called, then @var{thunk}, then
534@var{out_guard}.
7a095584 535
ae9f3a15
MG
536If, any time during the execution of @var{thunk}, the
537continuation of the @code{dynamic_wind} expression is escaped
538non-locally, @var{out_guard} is called. If the continuation of
539the dynamic-wind is re-entered, @var{in_guard} is called. Thus
540@var{in_guard} and @var{out_guard} may be called any number of
541times.
542@lisp
780ee65e
NJ
543(define x 'normal-binding)
544@result{} x
780ee65e
NJ
545(define a-cont (call-with-current-continuation
546 (lambda (escape)
547 (let ((old-x x))
548 (dynamic-wind
549 ;; in-guard:
550 ;;
551 (lambda () (set! x 'special-binding))
7a095584 552
780ee65e
NJ
553 ;; thunk
554 ;;
555 (lambda () (display x) (newline)
556 (call-with-current-continuation escape)
557 (display x) (newline)
558 x)
7a095584 559
780ee65e
NJ
560 ;; out-guard:
561 ;;
562 (lambda () (set! x old-x)))))))
7a095584 563
780ee65e
NJ
564;; Prints:
565special-binding
566;; Evaluates to:
567@result{} a-cont
780ee65e
NJ
568x
569@result{} normal-binding
780ee65e
NJ
570(a-cont #f)
571;; Prints:
572special-binding
573;; Evaluates to:
574@result{} a-cont ;; the value of the (define a-cont...)
780ee65e
NJ
575x
576@result{} normal-binding
780ee65e
NJ
577a-cont
578@result{} special-binding
ae9f3a15 579@end lisp
780ee65e
NJ
580@end deffn
581
582\fenvironment?
8f85c0c6
NJ
583@deffn {Scheme Procedure} environment? obj
584@deffnx {C Function} scm_environment_p (obj)
780ee65e
NJ
585Return @code{#t} if @var{obj} is an environment, or @code{#f}
586otherwise.
587@end deffn
588
589\fenvironment-bound?
8f85c0c6
NJ
590@deffn {Scheme Procedure} environment-bound? env sym
591@deffnx {C Function} scm_environment_bound_p (env, sym)
780ee65e
NJ
592Return @code{#t} if @var{sym} is bound in @var{env}, or
593@code{#f} otherwise.
594@end deffn
595
596\fenvironment-ref
8f85c0c6
NJ
597@deffn {Scheme Procedure} environment-ref env sym
598@deffnx {C Function} scm_environment_ref (env, sym)
780ee65e
NJ
599Return the value of the location bound to @var{sym} in
600@var{env}. If @var{sym} is unbound in @var{env}, signal an
601@code{environment:unbound} error.
602@end deffn
603
604\fenvironment-fold
8f85c0c6
NJ
605@deffn {Scheme Procedure} environment-fold env proc init
606@deffnx {C Function} scm_environment_fold (env, proc, init)
780ee65e
NJ
607Iterate over all the bindings in @var{env}, accumulating some
608value.
609For each binding in @var{env}, apply @var{proc} to the symbol
610bound, its value, and the result from the previous application
611of @var{proc}.
612Use @var{init} as @var{proc}'s third argument the first time
613@var{proc} is applied.
614If @var{env} contains no bindings, this function simply returns
615@var{init}.
616If @var{env} binds the symbol sym1 to the value val1, sym2 to
617val2, and so on, then this procedure computes:
ae9f3a15 618@lisp
780ee65e
NJ
619 (proc sym1 val1
620 (proc sym2 val2
621 ...
622 (proc symn valn
623 init)))
ae9f3a15 624@end lisp
780ee65e
NJ
625Each binding in @var{env} will be processed exactly once.
626@code{environment-fold} makes no guarantees about the order in
627which the bindings are processed.
628Here is a function which, given an environment, constructs an
629association list representing that environment's bindings,
630using environment-fold:
ae9f3a15 631@lisp
780ee65e
NJ
632 (define (environment->alist env)
633 (environment-fold env
634 (lambda (sym val tail)
635 (cons (cons sym val) tail))
636 '()))
ae9f3a15 637@end lisp
780ee65e
NJ
638@end deffn
639
640\fenvironment-define
8f85c0c6
NJ
641@deffn {Scheme Procedure} environment-define env sym val
642@deffnx {C Function} scm_environment_define (env, sym, val)
780ee65e
NJ
643Bind @var{sym} to a new location containing @var{val} in
644@var{env}. If @var{sym} is already bound to another location
645in @var{env} and the binding is mutable, that binding is
646replaced. The new binding and location are both mutable. The
647return value is unspecified.
648If @var{sym} is already bound in @var{env}, and the binding is
649immutable, signal an @code{environment:immutable-binding} error.
650@end deffn
651
652\fenvironment-undefine
8f85c0c6
NJ
653@deffn {Scheme Procedure} environment-undefine env sym
654@deffnx {C Function} scm_environment_undefine (env, sym)
780ee65e
NJ
655Remove any binding for @var{sym} from @var{env}. If @var{sym}
656is unbound in @var{env}, do nothing. The return value is
657unspecified.
658If @var{sym} is already bound in @var{env}, and the binding is
659immutable, signal an @code{environment:immutable-binding} error.
660@end deffn
661
662\fenvironment-set!
8f85c0c6
NJ
663@deffn {Scheme Procedure} environment-set! env sym val
664@deffnx {C Function} scm_environment_set_x (env, sym, val)
780ee65e
NJ
665If @var{env} binds @var{sym} to some location, change that
666location's value to @var{val}. The return value is
667unspecified.
668If @var{sym} is not bound in @var{env}, signal an
669@code{environment:unbound} error. If @var{env} binds @var{sym}
670to an immutable location, signal an
671@code{environment:immutable-location} error.
672@end deffn
673
674\fenvironment-cell
8f85c0c6
NJ
675@deffn {Scheme Procedure} environment-cell env sym for_write
676@deffnx {C Function} scm_environment_cell (env, sym, for_write)
780ee65e
NJ
677Return the value cell which @var{env} binds to @var{sym}, or
678@code{#f} if the binding does not live in a value cell.
679The argument @var{for-write} indicates whether the caller
680intends to modify the variable's value by mutating the value
681cell. If the variable is immutable, then
682@code{environment-cell} signals an
683@code{environment:immutable-location} error.
684If @var{sym} is unbound in @var{env}, signal an
685@code{environment:unbound} error.
686If you use this function, you should consider using
687@code{environment-observe}, to be notified when @var{sym} gets
688re-bound to a new value cell, or becomes undefined.
689@end deffn
690
691\fenvironment-observe
8f85c0c6
NJ
692@deffn {Scheme Procedure} environment-observe env proc
693@deffnx {C Function} scm_environment_observe (env, proc)
780ee65e
NJ
694Whenever @var{env}'s bindings change, apply @var{proc} to
695@var{env}.
696This function returns an object, token, which you can pass to
697@code{environment-unobserve} to remove @var{proc} from the set
698of procedures observing @var{env}. The type and value of
699token is unspecified.
700@end deffn
701
702\fenvironment-observe-weak
8f85c0c6
NJ
703@deffn {Scheme Procedure} environment-observe-weak env proc
704@deffnx {C Function} scm_environment_observe_weak (env, proc)
780ee65e
NJ
705This function is the same as environment-observe, except that
706the reference @var{env} retains to @var{proc} is a weak
707reference. This means that, if there are no other live,
708non-weak references to @var{proc}, it will be
709garbage-collected, and dropped from @var{env}'s
710list of observing procedures.
711@end deffn
712
713\fenvironment-unobserve
8f85c0c6
NJ
714@deffn {Scheme Procedure} environment-unobserve token
715@deffnx {C Function} scm_environment_unobserve (token)
780ee65e
NJ
716Cancel the observation request which returned the value
717@var{token}. The return value is unspecified.
718If a call @code{(environment-observe env proc)} returns
719@var{token}, then the call @code{(environment-unobserve token)}
720will cause @var{proc} to no longer be called when @var{env}'s
721bindings change.
722@end deffn
723
724\fmake-leaf-environment
8f85c0c6
NJ
725@deffn {Scheme Procedure} make-leaf-environment
726@deffnx {C Function} scm_make_leaf_environment ()
780ee65e
NJ
727Create a new leaf environment, containing no bindings.
728All bindings and locations created in the new environment
729will be mutable.
730@end deffn
731
732\fleaf-environment?
8f85c0c6
NJ
733@deffn {Scheme Procedure} leaf-environment? object
734@deffnx {C Function} scm_leaf_environment_p (object)
780ee65e
NJ
735Return @code{#t} if object is a leaf environment, or @code{#f}
736otherwise.
737@end deffn
738
739\fmake-eval-environment
8f85c0c6
NJ
740@deffn {Scheme Procedure} make-eval-environment local imported
741@deffnx {C Function} scm_make_eval_environment (local, imported)
780ee65e
NJ
742Return a new environment object eval whose bindings are the
743union of the bindings in the environments @var{local} and
744@var{imported}, with bindings from @var{local} taking
745precedence. Definitions made in eval are placed in @var{local}.
746Applying @code{environment-define} or
747@code{environment-undefine} to eval has the same effect as
748applying the procedure to @var{local}.
749Note that eval incorporates @var{local} and @var{imported} by
750reference:
751If, after creating eval, the program changes the bindings of
752@var{local} or @var{imported}, those changes will be visible
753in eval.
754Since most Scheme evaluation takes place in eval environments,
755they transparently cache the bindings received from @var{local}
756and @var{imported}. Thus, the first time the program looks up
757a symbol in eval, eval may make calls to @var{local} or
758@var{imported} to find their bindings, but subsequent
759references to that symbol will be as fast as references to
760bindings in finite environments.
761In typical use, @var{local} will be a finite environment, and
762@var{imported} will be an import environment
763@end deffn
764
765\feval-environment?
8f85c0c6
NJ
766@deffn {Scheme Procedure} eval-environment? object
767@deffnx {C Function} scm_eval_environment_p (object)
780ee65e
NJ
768Return @code{#t} if object is an eval environment, or @code{#f}
769otherwise.
770@end deffn
771
772\feval-environment-local
8f85c0c6
NJ
773@deffn {Scheme Procedure} eval-environment-local env
774@deffnx {C Function} scm_eval_environment_local (env)
780ee65e
NJ
775Return the local environment of eval environment @var{env}.
776@end deffn
777
778\feval-environment-set-local!
8f85c0c6
NJ
779@deffn {Scheme Procedure} eval-environment-set-local! env local
780@deffnx {C Function} scm_eval_environment_set_local_x (env, local)
780ee65e
NJ
781Change @var{env}'s local environment to @var{local}.
782@end deffn
783
784\feval-environment-imported
8f85c0c6
NJ
785@deffn {Scheme Procedure} eval-environment-imported env
786@deffnx {C Function} scm_eval_environment_imported (env)
780ee65e
NJ
787Return the imported environment of eval environment @var{env}.
788@end deffn
789
790\feval-environment-set-imported!
8f85c0c6
NJ
791@deffn {Scheme Procedure} eval-environment-set-imported! env imported
792@deffnx {C Function} scm_eval_environment_set_imported_x (env, imported)
780ee65e
NJ
793Change @var{env}'s imported environment to @var{imported}.
794@end deffn
795
796\fmake-import-environment
8f85c0c6
NJ
797@deffn {Scheme Procedure} make-import-environment imports conflict_proc
798@deffnx {C Function} scm_make_import_environment (imports, conflict_proc)
780ee65e
NJ
799Return a new environment @var{imp} whose bindings are the union
800of the bindings from the environments in @var{imports};
801@var{imports} must be a list of environments. That is,
802@var{imp} binds a symbol to a location when some element of
803@var{imports} does.
804If two different elements of @var{imports} have a binding for
805the same symbol, the @var{conflict-proc} is called with the
806following parameters: the import environment, the symbol and
807the list of the imported environments that bind the symbol.
808If the @var{conflict-proc} returns an environment @var{env},
809the conflict is considered as resolved and the binding from
810@var{env} is used. If the @var{conflict-proc} returns some
811non-environment object, the conflict is considered unresolved
812and the symbol is treated as unspecified in the import
813environment.
814The checking for conflicts may be performed lazily, i. e. at
815the moment when a value or binding for a certain symbol is
816requested instead of the moment when the environment is
817created or the bindings of the imports change.
818All bindings in @var{imp} are immutable. If you apply
819@code{environment-define} or @code{environment-undefine} to
820@var{imp}, Guile will signal an
821 @code{environment:immutable-binding} error. However,
822notice that the set of bindings in @var{imp} may still change,
823if one of its imported environments changes.
824@end deffn
825
826\fimport-environment?
8f85c0c6
NJ
827@deffn {Scheme Procedure} import-environment? object
828@deffnx {C Function} scm_import_environment_p (object)
780ee65e
NJ
829Return @code{#t} if object is an import environment, or
830@code{#f} otherwise.
831@end deffn
832
833\fimport-environment-imports
8f85c0c6
NJ
834@deffn {Scheme Procedure} import-environment-imports env
835@deffnx {C Function} scm_import_environment_imports (env)
780ee65e
NJ
836Return the list of environments imported by the import
837environment @var{env}.
838@end deffn
839
840\fimport-environment-set-imports!
8f85c0c6
NJ
841@deffn {Scheme Procedure} import-environment-set-imports! env imports
842@deffnx {C Function} scm_import_environment_set_imports_x (env, imports)
780ee65e
NJ
843Change @var{env}'s list of imported environments to
844@var{imports}, and check for conflicts.
845@end deffn
846
847\fmake-export-environment
8f85c0c6
NJ
848@deffn {Scheme Procedure} make-export-environment private signature
849@deffnx {C Function} scm_make_export_environment (private, signature)
780ee65e
NJ
850Return a new environment @var{exp} containing only those
851bindings in private whose symbols are present in
852@var{signature}. The @var{private} argument must be an
853environment.
854
855The environment @var{exp} binds symbol to location when
856@var{env} does, and symbol is exported by @var{signature}.
857
858@var{signature} is a list specifying which of the bindings in
859@var{private} should be visible in @var{exp}. Each element of
860@var{signature} should be a list of the form:
861 (symbol attribute ...)
862where each attribute is one of the following:
863@table @asis
864@item the symbol @code{mutable-location}
865 @var{exp} should treat the
866 location bound to symbol as mutable. That is, @var{exp}
867 will pass calls to @code{environment-set!} or
868 @code{environment-cell} directly through to private.
869@item the symbol @code{immutable-location}
870 @var{exp} should treat
871 the location bound to symbol as immutable. If the program
872 applies @code{environment-set!} to @var{exp} and symbol, or
873 calls @code{environment-cell} to obtain a writable value
874 cell, @code{environment-set!} will signal an
875 @code{environment:immutable-location} error. Note that, even
876 if an export environment treats a location as immutable, the
877 underlying environment may treat it as mutable, so its
878 value may change.
879@end table
880It is an error for an element of signature to specify both
881@code{mutable-location} and @code{immutable-location}. If
882neither is specified, @code{immutable-location} is assumed.
883
884As a special case, if an element of signature is a lone
885symbol @var{sym}, it is equivalent to an element of the form
886@code{(sym)}.
887
888All bindings in @var{exp} are immutable. If you apply
889@code{environment-define} or @code{environment-undefine} to
890@var{exp}, Guile will signal an
891@code{environment:immutable-binding} error. However,
892notice that the set of bindings in @var{exp} may still change,
893if the bindings in private change.
894@end deffn
895
896\fexport-environment?
8f85c0c6
NJ
897@deffn {Scheme Procedure} export-environment? object
898@deffnx {C Function} scm_export_environment_p (object)
780ee65e
NJ
899Return @code{#t} if object is an export environment, or
900@code{#f} otherwise.
901@end deffn
902
903\fexport-environment-private
8f85c0c6
NJ
904@deffn {Scheme Procedure} export-environment-private env
905@deffnx {C Function} scm_export_environment_private (env)
780ee65e
NJ
906Return the private environment of export environment @var{env}.
907@end deffn
908
909\fexport-environment-set-private!
8f85c0c6
NJ
910@deffn {Scheme Procedure} export-environment-set-private! env private
911@deffnx {C Function} scm_export_environment_set_private_x (env, private)
780ee65e
NJ
912Change the private environment of export environment @var{env}.
913@end deffn
914
915\fexport-environment-signature
8f85c0c6
NJ
916@deffn {Scheme Procedure} export-environment-signature env
917@deffnx {C Function} scm_export_environment_signature (env)
780ee65e
NJ
918Return the signature of export environment @var{env}.
919@end deffn
920
921\fexport-environment-set-signature!
8f85c0c6
NJ
922@deffn {Scheme Procedure} export-environment-set-signature! env signature
923@deffnx {C Function} scm_export_environment_set_signature_x (env, signature)
780ee65e
NJ
924Change the signature of export environment @var{env}.
925@end deffn
926
927\feq?
8f85c0c6 928@deffn {Scheme Procedure} eq? x y
780ee65e
NJ
929Return @code{#t} iff @var{x} references the same object as @var{y}.
930@code{eq?} is similar to @code{eqv?} except that in some cases it is
931capable of discerning distinctions finer than those detectable by
932@code{eqv?}.
933@end deffn
934
935\feqv?
8f85c0c6 936@deffn {Scheme Procedure} eqv? x y
780ee65e
NJ
937The @code{eqv?} procedure defines a useful equivalence relation on objects.
938Briefly, it returns @code{#t} if @var{x} and @var{y} should normally be
939regarded as the same object. This relation is left slightly open to
940interpretation, but works for comparing immediate integers, characters,
941and inexact numbers.
942@end deffn
943
944\fequal?
8f85c0c6 945@deffn {Scheme Procedure} equal? x y
780ee65e
NJ
946Return @code{#t} iff @var{x} and @var{y} are recursively @code{eqv?} equivalent.
947@code{equal?} recursively compares the contents of pairs,
948vectors, and strings, applying @code{eqv?} on other objects such as
949numbers and symbols. A rule of thumb is that objects are generally
950@code{equal?} if they print the same. @code{equal?} may fail to
951terminate if its arguments are circular data structures.
952@end deffn
953
954\fscm-error
8f85c0c6
NJ
955@deffn {Scheme Procedure} scm-error key subr message args data
956@deffnx {C Function} scm_error_scm (key, subr, message, args, data)
ae9f3a15
MG
957Raise an error with key @var{key}. @var{subr} can be a string
958naming the procedure associated with the error, or @code{#f}.
959@var{message} is the error message string, possibly containing
960@code{~S} and @code{~A} escapes. When an error is reported,
961these are replaced by formatting the corresponding members of
962@var{args}: @code{~A} (was @code{%s} in older versions of
963Guile) formats using @code{display} and @code{~S} (was
964@code{%S}) formats using @code{write}. @var{data} is a list or
965@code{#f} depending on @var{key}: if @var{key} is
966@code{system-error} then it should be a list containing the
967Unix @code{errno} value; If @var{key} is @code{signal} then it
968should be a list containing the Unix signal number; otherwise
969it will usually be @code{#f}.
780ee65e
NJ
970@end deffn
971
972\fstrerror
8f85c0c6
NJ
973@deffn {Scheme Procedure} strerror err
974@deffnx {C Function} scm_strerror (err)
ae9f3a15
MG
975Return the Unix error message corresponding to @var{err}, which
976must be an integer value.
780ee65e
NJ
977@end deffn
978
979\fapply:nconc2last
8f85c0c6
NJ
980@deffn {Scheme Procedure} apply:nconc2last lst
981@deffnx {C Function} scm_nconc2last (lst)
780ee65e
NJ
982Given a list (@var{arg1} @dots{} @var{args}), this function
983conses the @var{arg1} @dots{} arguments onto the front of
984@var{args}, and returns the resulting list. Note that
985@var{args} is a list; thus, the argument to this function is
986a list whose last element is a list.
987Note: Rather than do new consing, @code{apply:nconc2last}
988destroys its argument, so use with care.
989@end deffn
990
991\fforce
8f85c0c6
NJ
992@deffn {Scheme Procedure} force x
993@deffnx {C Function} scm_force (x)
780ee65e
NJ
994If the promise @var{x} has not been computed yet, compute and
995return @var{x}, otherwise just return the previously computed
996value.
997@end deffn
998
999\fpromise?
8f85c0c6
NJ
1000@deffn {Scheme Procedure} promise? obj
1001@deffnx {C Function} scm_promise_p (obj)
780ee65e 1002Return true if @var{obj} is a promise, i.e. a delayed computation
9401323e 1003(@pxref{Delayed evaluation,,,r5rs.info,The Revised^5 Report on Scheme}).
780ee65e
NJ
1004@end deffn
1005
1006\fcons-source
8f85c0c6
NJ
1007@deffn {Scheme Procedure} cons-source xorig x y
1008@deffnx {C Function} scm_cons_source (xorig, x, y)
780ee65e
NJ
1009Create and return a new pair whose car and cdr are @var{x} and @var{y}.
1010Any source properties associated with @var{xorig} are also associated
1011with the new pair.
1012@end deffn
1013
1014\fcopy-tree
8f85c0c6
NJ
1015@deffn {Scheme Procedure} copy-tree obj
1016@deffnx {C Function} scm_copy_tree (obj)
780ee65e
NJ
1017Recursively copy the data tree that is bound to @var{obj}, and return a
1018pointer to the new data structure. @code{copy-tree} recurses down the
1019contents of both pairs and vectors (since both cons cells and vector
1020cells may point to arbitrary objects), and stops recursing when it hits
1021any other object.
1022@end deffn
1023
1024\fprimitive-eval
8f85c0c6
NJ
1025@deffn {Scheme Procedure} primitive-eval exp
1026@deffnx {C Function} scm_primitive_eval (exp)
780ee65e
NJ
1027Evaluate @var{exp} in the top-level environment specified by
1028the current module.
1029@end deffn
1030
1031\feval
8f85c0c6
NJ
1032@deffn {Scheme Procedure} eval exp module
1033@deffnx {C Function} scm_eval (exp, module)
780ee65e
NJ
1034Evaluate @var{exp}, a list representing a Scheme expression,
1035in the top-level environment specified by @var{module}.
8f85c0c6 1036While @var{exp} is evaluated (using @code{primitive-eval}),
780ee65e
NJ
1037@var{module} is made the current module. The current module
1038is reset to its previous value when @var{eval} returns.
1039@end deffn
1040
780ee65e 1041\feval-options-interface
8f85c0c6
NJ
1042@deffn {Scheme Procedure} eval-options-interface [setting]
1043@deffnx {C Function} scm_eval_options_interface (setting)
780ee65e
NJ
1044Option interface for the evaluation options. Instead of using
1045this procedure directly, use the procedures @code{eval-enable},
1046@code{eval-disable}, @code{eval-set!} and @var{eval-options}.
1047@end deffn
1048
1049\fevaluator-traps-interface
8f85c0c6
NJ
1050@deffn {Scheme Procedure} evaluator-traps-interface [setting]
1051@deffnx {C Function} scm_evaluator_traps (setting)
780ee65e
NJ
1052Option interface for the evaluator trap options.
1053@end deffn
1054
1055\fdefined?
8f85c0c6
NJ
1056@deffn {Scheme Procedure} defined? sym [env]
1057@deffnx {C Function} scm_definedp (sym, env)
9401323e 1058Return @code{#t} if @var{sym} is defined in the lexical environment @var{env}. When @var{env} is not specified, look in the top-level environment as defined by the current module.
780ee65e
NJ
1059@end deffn
1060
1061\fmap-in-order
8f85c0c6 1062@deffn {Scheme Procedure} map-in-order
9401323e
NJ
1063implemented by the C function "scm_map"
1064@end deffn
1065
1066\fload-extension
8f85c0c6
NJ
1067@deffn {Scheme Procedure} load-extension lib init
1068@deffnx {C Function} scm_load_extension (lib, init)
72dd0a03 1069Load and initialize the extension designated by LIB and INIT.
9401323e
NJ
1070When there is no pre-registered function for LIB/INIT, this is
1071equivalent to
1072
1073@lisp
1074(dynamic-call INIT (dynamic-link LIB))
1075@end lisp
1076
1077When there is a pre-registered function, that function is called
1078instead.
1079
1080Normally, there is no pre-registered function. This option exists
1081only for situations where dynamic linking is unavailable or unwanted.
1082In that case, you would statically link your program with the desired
1083library, and register its init function right after Guile has been
1084initialized.
1085
1086LIB should be a string denoting a shared library without any file type
1087suffix such as ".so". The suffix is provided automatically. It
1088should also not contain any directory components. Libraries that
1089implement Guile Extensions should be put into the normal locations for
1090shared libraries. We recommend to use the naming convention
1091libguile-bla-blum for a extension related to a module `(bla blum)'.
1092
1093The normal way for a extension to be used is to write a small Scheme
1094file that defines a module, and to load the extension into this
1095module. When the module is auto-loaded, the extension is loaded as
1096well. For example,
1097
1098@lisp
1099(define-module (bla blum))
1100
1101(load-extension "libguile-bla-blum" "bla_init_blum")
1102@end lisp
780ee65e
NJ
1103@end deffn
1104
1105\fprogram-arguments
8f85c0c6
NJ
1106@deffn {Scheme Procedure} program-arguments
1107@deffnx {Scheme Procedure} command-line
1108@deffnx {C Function} scm_program_arguments ()
780ee65e
NJ
1109Return the list of command line arguments passed to Guile, as a list of
1110strings. The list includes the invoked program name, which is usually
1111@code{"guile"}, but excludes switches and parameters for command line
1112options like @code{-e} and @code{-l}.
1113@end deffn
1114
9401323e 1115\fmake-fluid
8f85c0c6
NJ
1116@deffn {Scheme Procedure} make-fluid
1117@deffnx {C Function} scm_make_fluid ()
9401323e
NJ
1118Return a newly created fluid.
1119Fluids are objects of a certain type (a smob) that can hold one SCM
1120value per dynamic root. That is, modifications to this value are
1121only visible to code that executes within the same dynamic root as
1122the modifying code. When a new dynamic root is constructed, it
1123inherits the values from its parent. Because each thread executes
1124in its own dynamic root, you can use fluids for thread local storage.
780ee65e
NJ
1125@end deffn
1126
9401323e 1127\ffluid?
8f85c0c6
NJ
1128@deffn {Scheme Procedure} fluid? obj
1129@deffnx {C Function} scm_fluid_p (obj)
9401323e
NJ
1130Return @code{#t} iff @var{obj} is a fluid; otherwise, return
1131@code{#f}.
780ee65e
NJ
1132@end deffn
1133
9401323e 1134\ffluid-ref
8f85c0c6
NJ
1135@deffn {Scheme Procedure} fluid-ref fluid
1136@deffnx {C Function} scm_fluid_ref (fluid)
9401323e
NJ
1137Return the value associated with @var{fluid} in the current
1138dynamic root. If @var{fluid} has not been set, then return
1139@code{#f}.
780ee65e
NJ
1140@end deffn
1141
9401323e 1142\ffluid-set!
8f85c0c6
NJ
1143@deffn {Scheme Procedure} fluid-set! fluid value
1144@deffnx {C Function} scm_fluid_set_x (fluid, value)
9401323e 1145Set the value associated with @var{fluid} in the current dynamic root.
780ee65e
NJ
1146@end deffn
1147
9401323e 1148\fwith-fluids*
8f85c0c6
NJ
1149@deffn {Scheme Procedure} with-fluids* fluids values thunk
1150@deffnx {C Function} scm_with_fluids (fluids, values, thunk)
9401323e
NJ
1151Set @var{fluids} to @var{values} temporary, and call @var{thunk}.
1152@var{fluids} must be a list of fluids and @var{values} must be the same
1153number of their values to be applied. Each substitution is done
1154one after another. @var{thunk} must be a procedure with no argument.
780ee65e
NJ
1155@end deffn
1156
9401323e 1157\fsetvbuf
8f85c0c6
NJ
1158@deffn {Scheme Procedure} setvbuf port mode [size]
1159@deffnx {C Function} scm_setvbuf (port, mode, size)
9401323e
NJ
1160Set the buffering mode for @var{port}. @var{mode} can be:
1161@table @code
1162@item _IONBF
1163non-buffered
1164@item _IOLBF
1165line buffered
1166@item _IOFBF
1167block buffered, using a newly allocated buffer of @var{size} bytes.
1168If @var{size} is omitted, a default size will be used.
1169@end table
780ee65e
NJ
1170@end deffn
1171
9401323e 1172\ffile-port?
8f85c0c6
NJ
1173@deffn {Scheme Procedure} file-port? obj
1174@deffnx {C Function} scm_file_port_p (obj)
9401323e 1175Determine whether @var{obj} is a port that is related to a file.
780ee65e
NJ
1176@end deffn
1177
9401323e 1178\fopen-file
8f85c0c6
NJ
1179@deffn {Scheme Procedure} open-file filename mode
1180@deffnx {C Function} scm_open_file (filename, mode)
9401323e
NJ
1181Open the file whose name is @var{filename}, and return a port
1182representing that file. The attributes of the port are
1183determined by the @var{mode} string. The way in which this is
1184interpreted is similar to C stdio. The first character must be
1185one of the following:
1186@table @samp
1187@item r
1188Open an existing file for input.
1189@item w
1190Open a file for output, creating it if it doesn't already exist
1191or removing its contents if it does.
1192@item a
1193Open a file for output, creating it if it doesn't already
1194exist. All writes to the port will go to the end of the file.
1195The "append mode" can be turned off while the port is in use
1196@pxref{Ports and File Descriptors, fcntl}
780ee65e 1197@end table
9401323e
NJ
1198The following additional characters can be appended:
1199@table @samp
1200@item +
1201Open the port for both input and output. E.g., @code{r+}: open
1202an existing file for both input and output.
1203@item 0
1204Create an "unbuffered" port. In this case input and output
1205operations are passed directly to the underlying port
1206implementation without additional buffering. This is likely to
1207slow down I/O operations. The buffering mode can be changed
1208while a port is in use @pxref{Ports and File Descriptors,
1209setvbuf}
1210@item l
1211Add line-buffering to the port. The port output buffer will be
1212automatically flushed whenever a newline character is written.
780ee65e 1213@end table
9401323e
NJ
1214In theory we could create read/write ports which were buffered
1215in one direction only. However this isn't included in the
1216current interfaces. If a file cannot be opened with the access
1217requested, @code{open-file} throws an exception.
780ee65e
NJ
1218@end deffn
1219
9401323e 1220\fgc-stats
8f85c0c6
NJ
1221@deffn {Scheme Procedure} gc-stats
1222@deffnx {C Function} scm_gc_stats ()
9401323e
NJ
1223Return an association list of statistics about Guile's current
1224use of storage.
780ee65e
NJ
1225@end deffn
1226
9401323e 1227\fobject-address
8f85c0c6
NJ
1228@deffn {Scheme Procedure} object-address obj
1229@deffnx {C Function} scm_object_address (obj)
9401323e
NJ
1230Return an integer that for the lifetime of @var{obj} is uniquely
1231returned by this function for @var{obj}
780ee65e
NJ
1232@end deffn
1233
9401323e 1234\fgc
8f85c0c6
NJ
1235@deffn {Scheme Procedure} gc
1236@deffnx {C Function} scm_gc ()
9401323e
NJ
1237Scans all of SCM objects and reclaims for further use those that are
1238no longer accessible.
780ee65e
NJ
1239@end deffn
1240
9401323e 1241\f%compute-slots
8f85c0c6
NJ
1242@deffn {Scheme Procedure} %compute-slots class
1243@deffnx {C Function} scm_sys_compute_slots (class)
9401323e
NJ
1244Return a list consisting of the names of all slots belonging to
1245class @var{class}, i. e. the slots of @var{class} and of all of
1246its superclasses.
780ee65e
NJ
1247@end deffn
1248
9401323e 1249\fget-keyword
8f85c0c6
NJ
1250@deffn {Scheme Procedure} get-keyword key l default_value
1251@deffnx {C Function} scm_get_keyword (key, l, default_value)
9401323e
NJ
1252Determine an associated value for the keyword @var{key} from
1253the list @var{l}. The list @var{l} has to consist of an even
1254number of elements, where, starting with the first, every
1255second element is a keyword, followed by its associated value.
1256If @var{l} does not hold a value for @var{key}, the value
1257@var{default_value} is returned.
780ee65e
NJ
1258@end deffn
1259
9401323e 1260\f%initialize-object
8f85c0c6
NJ
1261@deffn {Scheme Procedure} %initialize-object obj initargs
1262@deffnx {C Function} scm_sys_initialize_object (obj, initargs)
9401323e
NJ
1263Initialize the object @var{obj} with the given arguments
1264@var{initargs}.
780ee65e
NJ
1265@end deffn
1266
9401323e 1267\f%prep-layout!
8f85c0c6
NJ
1268@deffn {Scheme Procedure} %prep-layout! class
1269@deffnx {C Function} scm_sys_prep_layout_x (class)
780ee65e 1270
780ee65e
NJ
1271@end deffn
1272
9401323e 1273\f%inherit-magic!
8f85c0c6
NJ
1274@deffn {Scheme Procedure} %inherit-magic! class dsupers
1275@deffnx {C Function} scm_sys_inherit_magic_x (class, dsupers)
780ee65e 1276
780ee65e
NJ
1277@end deffn
1278
9401323e 1279\finstance?
8f85c0c6
NJ
1280@deffn {Scheme Procedure} instance? obj
1281@deffnx {C Function} scm_instance_p (obj)
9401323e 1282Return @code{#t} if @var{obj} is an instance.
780ee65e
NJ
1283@end deffn
1284
9401323e 1285\fclass-name
8f85c0c6
NJ
1286@deffn {Scheme Procedure} class-name obj
1287@deffnx {C Function} scm_class_name (obj)
9401323e 1288Return the class name of @var{obj}.
780ee65e
NJ
1289@end deffn
1290
9401323e 1291\fclass-direct-supers
8f85c0c6
NJ
1292@deffn {Scheme Procedure} class-direct-supers obj
1293@deffnx {C Function} scm_class_direct_supers (obj)
9401323e
NJ
1294Return the direct superclasses of the class @var{obj}.
1295@end deffn
780ee65e 1296
9401323e 1297\fclass-direct-slots
8f85c0c6
NJ
1298@deffn {Scheme Procedure} class-direct-slots obj
1299@deffnx {C Function} scm_class_direct_slots (obj)
9401323e
NJ
1300Return the direct slots of the class @var{obj}.
1301@end deffn
780ee65e 1302
9401323e 1303\fclass-direct-subclasses
8f85c0c6
NJ
1304@deffn {Scheme Procedure} class-direct-subclasses obj
1305@deffnx {C Function} scm_class_direct_subclasses (obj)
9401323e
NJ
1306Return the direct subclasses of the class @var{obj}.
1307@end deffn
780ee65e 1308
9401323e 1309\fclass-direct-methods
8f85c0c6
NJ
1310@deffn {Scheme Procedure} class-direct-methods obj
1311@deffnx {C Function} scm_class_direct_methods (obj)
9401323e 1312Return the direct methods of the class @var{obj}
780ee65e
NJ
1313@end deffn
1314
9401323e 1315\fclass-precedence-list
8f85c0c6
NJ
1316@deffn {Scheme Procedure} class-precedence-list obj
1317@deffnx {C Function} scm_class_precedence_list (obj)
9401323e
NJ
1318Return the class precedence list of the class @var{obj}.
1319@end deffn
780ee65e 1320
9401323e 1321\fclass-slots
8f85c0c6
NJ
1322@deffn {Scheme Procedure} class-slots obj
1323@deffnx {C Function} scm_class_slots (obj)
9401323e
NJ
1324Return the slot list of the class @var{obj}.
1325@end deffn
780ee65e 1326
9401323e 1327\fclass-environment
8f85c0c6
NJ
1328@deffn {Scheme Procedure} class-environment obj
1329@deffnx {C Function} scm_class_environment (obj)
9401323e 1330Return the environment of the class @var{obj}.
780ee65e
NJ
1331@end deffn
1332
9401323e 1333\fgeneric-function-name
8f85c0c6
NJ
1334@deffn {Scheme Procedure} generic-function-name obj
1335@deffnx {C Function} scm_generic_function_name (obj)
9401323e 1336Return the name of the generic function @var{obj}.
780ee65e
NJ
1337@end deffn
1338
9401323e 1339\fgeneric-function-methods
8f85c0c6
NJ
1340@deffn {Scheme Procedure} generic-function-methods obj
1341@deffnx {C Function} scm_generic_function_methods (obj)
9401323e 1342Return the methods of the generic function @var{obj}.
780ee65e
NJ
1343@end deffn
1344
9401323e 1345\fmethod-generic-function
8f85c0c6
NJ
1346@deffn {Scheme Procedure} method-generic-function obj
1347@deffnx {C Function} scm_method_generic_function (obj)
9401323e 1348Return the generic function fot the method @var{obj}.
780ee65e
NJ
1349@end deffn
1350
9401323e 1351\fmethod-specializers
8f85c0c6
NJ
1352@deffn {Scheme Procedure} method-specializers obj
1353@deffnx {C Function} scm_method_specializers (obj)
9401323e 1354Return specializers of the method @var{obj}.
780ee65e
NJ
1355@end deffn
1356
9401323e 1357\fmethod-procedure
8f85c0c6
NJ
1358@deffn {Scheme Procedure} method-procedure obj
1359@deffnx {C Function} scm_method_procedure (obj)
9401323e 1360Return the procedure of the method @var{obj}.
780ee65e
NJ
1361@end deffn
1362
9401323e 1363\faccessor-method-slot-definition
8f85c0c6
NJ
1364@deffn {Scheme Procedure} accessor-method-slot-definition obj
1365@deffnx {C Function} scm_accessor_method_slot_definition (obj)
9401323e 1366Return the slot definition of the accessor @var{obj}.
780ee65e
NJ
1367@end deffn
1368
9401323e 1369\f%tag-body
8f85c0c6
NJ
1370@deffn {Scheme Procedure} %tag-body body
1371@deffnx {C Function} scm_sys_tag_body (body)
9401323e 1372Internal GOOPS magic---don't use this function!
780ee65e
NJ
1373@end deffn
1374
9401323e 1375\fmake-unbound
8f85c0c6
NJ
1376@deffn {Scheme Procedure} make-unbound
1377@deffnx {C Function} scm_make_unbound ()
9401323e 1378Return the unbound value.
780ee65e
NJ
1379@end deffn
1380
9401323e 1381\funbound?
8f85c0c6
NJ
1382@deffn {Scheme Procedure} unbound? obj
1383@deffnx {C Function} scm_unbound_p (obj)
9401323e 1384Return @code{#t} if @var{obj} is unbound.
780ee65e
NJ
1385@end deffn
1386
9401323e 1387\fassert-bound
8f85c0c6
NJ
1388@deffn {Scheme Procedure} assert-bound value obj
1389@deffnx {C Function} scm_assert_bound (value, obj)
9401323e
NJ
1390Return @var{value} if it is bound, and invoke the
1391@var{slot-unbound} method of @var{obj} if it is not.
780ee65e
NJ
1392@end deffn
1393
9401323e 1394\f@@assert-bound-ref
8f85c0c6
NJ
1395@deffn {Scheme Procedure} @@assert-bound-ref obj index
1396@deffnx {C Function} scm_at_assert_bound_ref (obj, index)
9401323e
NJ
1397Like @code{assert-bound}, but use @var{index} for accessing
1398the value from @var{obj}.
780ee65e
NJ
1399@end deffn
1400
9401323e 1401\f%fast-slot-ref
8f85c0c6
NJ
1402@deffn {Scheme Procedure} %fast-slot-ref obj index
1403@deffnx {C Function} scm_sys_fast_slot_ref (obj, index)
9401323e 1404Return the slot value with index @var{index} from @var{obj}.
780ee65e
NJ
1405@end deffn
1406
1407\f%fast-slot-set!
8f85c0c6
NJ
1408@deffn {Scheme Procedure} %fast-slot-set! obj index value
1409@deffnx {C Function} scm_sys_fast_slot_set_x (obj, index, value)
780ee65e
NJ
1410Set the slot with index @var{index} in @var{obj} to
1411@var{value}.
1412@end deffn
1413
1414\fslot-ref-using-class
8f85c0c6
NJ
1415@deffn {Scheme Procedure} slot-ref-using-class class obj slot_name
1416@deffnx {C Function} scm_slot_ref_using_class (class, obj, slot_name)
9401323e 1417
780ee65e
NJ
1418@end deffn
1419
1420\fslot-set-using-class!
8f85c0c6
NJ
1421@deffn {Scheme Procedure} slot-set-using-class! class obj slot_name value
1422@deffnx {C Function} scm_slot_set_using_class_x (class, obj, slot_name, value)
9401323e 1423
780ee65e
NJ
1424@end deffn
1425
1426\fslot-bound-using-class?
8f85c0c6
NJ
1427@deffn {Scheme Procedure} slot-bound-using-class? class obj slot_name
1428@deffnx {C Function} scm_slot_bound_using_class_p (class, obj, slot_name)
9401323e 1429
780ee65e
NJ
1430@end deffn
1431
1432\fslot-exists-using-class?
8f85c0c6
NJ
1433@deffn {Scheme Procedure} slot-exists-using-class? class obj slot_name
1434@deffnx {C Function} scm_slot_exists_using_class_p (class, obj, slot_name)
9401323e 1435
780ee65e
NJ
1436@end deffn
1437
1438\fslot-ref
8f85c0c6
NJ
1439@deffn {Scheme Procedure} slot-ref obj slot_name
1440@deffnx {C Function} scm_slot_ref (obj, slot_name)
780ee65e
NJ
1441Return the value from @var{obj}'s slot with the name
1442@var{slot_name}.
1443@end deffn
1444
1445\fslot-set!
8f85c0c6
NJ
1446@deffn {Scheme Procedure} slot-set! obj slot_name value
1447@deffnx {C Function} scm_slot_set_x (obj, slot_name, value)
780ee65e
NJ
1448Set the slot named @var{slot_name} of @var{obj} to @var{value}.
1449@end deffn
1450
1451\fslot-bound?
8f85c0c6
NJ
1452@deffn {Scheme Procedure} slot-bound? obj slot_name
1453@deffnx {C Function} scm_slot_bound_p (obj, slot_name)
780ee65e
NJ
1454Return @code{#t} if the slot named @var{slot_name} of @var{obj}
1455is bound.
1456@end deffn
1457
1458\fslot-exists?
8f85c0c6
NJ
1459@deffn {Scheme Procedure} slot-exists? obj slot_name
1460@deffnx {C Function} scm_slots_exists_p (obj, slot_name)
780ee65e
NJ
1461Return @code{#t} if @var{obj} has a slot named @var{slot_name}.
1462@end deffn
1463
1464\f%allocate-instance
8f85c0c6
NJ
1465@deffn {Scheme Procedure} %allocate-instance class initargs
1466@deffnx {C Function} scm_sys_allocate_instance (class, initargs)
780ee65e
NJ
1467Create a new instance of class @var{class} and initialize it
1468from the arguments @var{initargs}.
1469@end deffn
1470
1471\f%set-object-setter!
8f85c0c6
NJ
1472@deffn {Scheme Procedure} %set-object-setter! obj setter
1473@deffnx {C Function} scm_sys_set_object_setter_x (obj, setter)
9401323e 1474
780ee65e
NJ
1475@end deffn
1476
1477\f%modify-instance
8f85c0c6
NJ
1478@deffn {Scheme Procedure} %modify-instance old new
1479@deffnx {C Function} scm_sys_modify_instance (old, new)
9401323e 1480
780ee65e
NJ
1481@end deffn
1482
1483\f%modify-class
8f85c0c6
NJ
1484@deffn {Scheme Procedure} %modify-class old new
1485@deffnx {C Function} scm_sys_modify_class (old, new)
9401323e 1486
780ee65e
NJ
1487@end deffn
1488
1489\f%invalidate-class
8f85c0c6
NJ
1490@deffn {Scheme Procedure} %invalidate-class class
1491@deffnx {C Function} scm_sys_invalidate_class (class)
9401323e 1492
780ee65e
NJ
1493@end deffn
1494
1495\f%invalidate-method-cache!
8f85c0c6
NJ
1496@deffn {Scheme Procedure} %invalidate-method-cache! gf
1497@deffnx {C Function} scm_sys_invalidate_method_cache_x (gf)
9401323e 1498
780ee65e
NJ
1499@end deffn
1500
1501\fgeneric-capability?
8f85c0c6
NJ
1502@deffn {Scheme Procedure} generic-capability? proc
1503@deffnx {C Function} scm_generic_capability_p (proc)
9401323e 1504
780ee65e
NJ
1505@end deffn
1506
1507\fenable-primitive-generic!
8f85c0c6
NJ
1508@deffn {Scheme Procedure} enable-primitive-generic! . subrs
1509@deffnx {C Function} scm_enable_primitive_generic_x (subrs)
9401323e 1510
780ee65e
NJ
1511@end deffn
1512
1513\fprimitive-generic-generic
8f85c0c6
NJ
1514@deffn {Scheme Procedure} primitive-generic-generic subr
1515@deffnx {C Function} scm_primitive_generic_generic (subr)
9401323e 1516
780ee65e
NJ
1517@end deffn
1518
1519\fmake
8f85c0c6
NJ
1520@deffn {Scheme Procedure} make . args
1521@deffnx {C Function} scm_make (args)
780ee65e
NJ
1522Make a new object. @var{args} must contain the class and
1523all necessary initialization information.
1524@end deffn
1525
1526\ffind-method
8f85c0c6
NJ
1527@deffn {Scheme Procedure} find-method . l
1528@deffnx {C Function} scm_find_method (l)
9401323e 1529
780ee65e
NJ
1530@end deffn
1531
1532\f%method-more-specific?
8f85c0c6
NJ
1533@deffn {Scheme Procedure} %method-more-specific? m1 m2 targs
1534@deffnx {C Function} scm_sys_method_more_specific_p (m1, m2, targs)
9401323e 1535
780ee65e
NJ
1536@end deffn
1537
1538\f%goops-loaded
8f85c0c6
NJ
1539@deffn {Scheme Procedure} %goops-loaded
1540@deffnx {C Function} scm_sys_goops_loaded ()
780ee65e
NJ
1541Announce that GOOPS is loaded and perform initialization
1542on the C level which depends on the loaded GOOPS modules.
1543@end deffn
1544
1545\fmake-guardian
8f85c0c6
NJ
1546@deffn {Scheme Procedure} make-guardian [greedy_p]
1547@deffnx {C Function} scm_make_guardian (greedy_p)
780ee65e
NJ
1548Create a new guardian.
1549A guardian protects a set of objects from garbage collection,
1550allowing a program to apply cleanup or other actions.
1551
1552@code{make-guardian} returns a procedure representing the guardian.
1553Calling the guardian procedure with an argument adds the
1554argument to the guardian's set of protected objects.
1555Calling the guardian procedure without an argument returns
1556one of the protected objects which are ready for garbage
1557collection, or @code{#f} if no such object is available.
1558Objects which are returned in this way are removed from
1559the guardian.
1560
1561@code{make-guardian} takes one optional argument that says whether the
1562new guardian should be greedy or sharing. If there is any chance
1563that any object protected by the guardian may be resurrected,
1564then you should make the guardian greedy (this is the default).
1565
1566See R. Kent Dybvig, Carl Bruggeman, and David Eby (1993)
1567"Guardians in a Generation-Based Garbage Collector".
1568ACM SIGPLAN Conference on Programming Language Design
1569and Implementation, June 1993.
1570
1571(the semantics are slightly different at this point, but the
1572paper still (mostly) accurately describes the interface).
1573@end deffn
1574
1575\fguardian-destroyed?
8f85c0c6
NJ
1576@deffn {Scheme Procedure} guardian-destroyed? guardian
1577@deffnx {C Function} scm_guardian_destroyed_p (guardian)
780ee65e
NJ
1578Return @code{#t} if @var{guardian} has been destroyed, otherwise @code{#f}.
1579@end deffn
1580
1581\fguardian-greedy?
8f85c0c6
NJ
1582@deffn {Scheme Procedure} guardian-greedy? guardian
1583@deffnx {C Function} scm_guardian_greedy_p (guardian)
780ee65e
NJ
1584Return @code{#t} if @var{guardian} is a greedy guardian, otherwise @code{#f}.
1585@end deffn
1586
1587\fdestroy-guardian!
8f85c0c6
NJ
1588@deffn {Scheme Procedure} destroy-guardian! guardian
1589@deffnx {C Function} scm_destroy_guardian_x (guardian)
780ee65e
NJ
1590Destroys @var{guardian}, by making it impossible to put any more
1591objects in it or get any objects from it. It also unguards any
1592objects guarded by @var{guardian}.
1593@end deffn
1594
1595\fhashq
8f85c0c6
NJ
1596@deffn {Scheme Procedure} hashq key size
1597@deffnx {C Function} scm_hashq (key, size)
780ee65e
NJ
1598Determine a hash value for @var{key} that is suitable for
1599lookups in a hashtable of size @var{size}, where @code{eq?} is
1600used as the equality predicate. The function returns an
1601integer in the range 0 to @var{size} - 1. Note that
1602@code{hashq} may use internal addresses. Thus two calls to
1603hashq where the keys are @code{eq?} are not guaranteed to
1604deliver the same value if the key object gets garbage collected
1605in between. This can happen, for example with symbols:
1606@code{(hashq 'foo n) (gc) (hashq 'foo n)} may produce two
1607different values, since @code{foo} will be garbage collected.
1608@end deffn
1609
1610\fhashv
8f85c0c6
NJ
1611@deffn {Scheme Procedure} hashv key size
1612@deffnx {C Function} scm_hashv (key, size)
780ee65e
NJ
1613Determine a hash value for @var{key} that is suitable for
1614lookups in a hashtable of size @var{size}, where @code{eqv?} is
1615used as the equality predicate. The function returns an
1616integer in the range 0 to @var{size} - 1. Note that
1617@code{(hashv key)} may use internal addresses. Thus two calls
1618to hashv where the keys are @code{eqv?} are not guaranteed to
1619deliver the same value if the key object gets garbage collected
1620in between. This can happen, for example with symbols:
1621@code{(hashv 'foo n) (gc) (hashv 'foo n)} may produce two
1622different values, since @code{foo} will be garbage collected.
1623@end deffn
1624
1625\fhash
8f85c0c6
NJ
1626@deffn {Scheme Procedure} hash key size
1627@deffnx {C Function} scm_hash (key, size)
780ee65e
NJ
1628Determine a hash value for @var{key} that is suitable for
1629lookups in a hashtable of size @var{size}, where @code{equal?}
1630is used as the equality predicate. The function returns an
1631integer in the range 0 to @var{size} - 1.
1632@end deffn
1633
1634\fhashq-get-handle
8f85c0c6
NJ
1635@deffn {Scheme Procedure} hashq-get-handle table key
1636@deffnx {C Function} scm_hashq_get_handle (table, key)
ae9f3a15
MG
1637This procedure returns the @code{(key . value)} pair from the
1638hash table @var{table}. If @var{table} does not hold an
1639associated value for @var{key}, @code{#f} is returned.
1640Uses @code{eq?} for equality testing.
780ee65e
NJ
1641@end deffn
1642
1643\fhashq-create-handle!
8f85c0c6
NJ
1644@deffn {Scheme Procedure} hashq-create-handle! table key init
1645@deffnx {C Function} scm_hashq_create_handle_x (table, key, init)
780ee65e
NJ
1646This function looks up @var{key} in @var{table} and returns its handle.
1647If @var{key} is not already present, a new handle is created which
1648associates @var{key} with @var{init}.
1649@end deffn
1650
1651\fhashq-ref
8f85c0c6
NJ
1652@deffn {Scheme Procedure} hashq-ref table key [dflt]
1653@deffnx {C Function} scm_hashq_ref (table, key, dflt)
780ee65e
NJ
1654Look up @var{key} in the hash table @var{table}, and return the
1655value (if any) associated with it. If @var{key} is not found,
1656return @var{default} (or @code{#f} if no @var{default} argument
1657is supplied). Uses @code{eq?} for equality testing.
1658@end deffn
1659
1660\fhashq-set!
8f85c0c6
NJ
1661@deffn {Scheme Procedure} hashq-set! table key val
1662@deffnx {C Function} scm_hashq_set_x (table, key, val)
780ee65e
NJ
1663Find the entry in @var{table} associated with @var{key}, and
1664store @var{value} there. Uses @code{eq?} for equality testing.
1665@end deffn
1666
1667\fhashq-remove!
8f85c0c6
NJ
1668@deffn {Scheme Procedure} hashq-remove! table key
1669@deffnx {C Function} scm_hashq_remove_x (table, key)
780ee65e
NJ
1670Remove @var{key} (and any value associated with it) from
1671@var{table}. Uses @code{eq?} for equality tests.
1672@end deffn
1673
1674\fhashv-get-handle
8f85c0c6
NJ
1675@deffn {Scheme Procedure} hashv-get-handle table key
1676@deffnx {C Function} scm_hashv_get_handle (table, key)
ae9f3a15
MG
1677This procedure returns the @code{(key . value)} pair from the
1678hash table @var{table}. If @var{table} does not hold an
1679associated value for @var{key}, @code{#f} is returned.
1680Uses @code{eqv?} for equality testing.
780ee65e
NJ
1681@end deffn
1682
1683\fhashv-create-handle!
8f85c0c6
NJ
1684@deffn {Scheme Procedure} hashv-create-handle! table key init
1685@deffnx {C Function} scm_hashv_create_handle_x (table, key, init)
780ee65e
NJ
1686This function looks up @var{key} in @var{table} and returns its handle.
1687If @var{key} is not already present, a new handle is created which
1688associates @var{key} with @var{init}.
1689@end deffn
1690
1691\fhashv-ref
8f85c0c6
NJ
1692@deffn {Scheme Procedure} hashv-ref table key [dflt]
1693@deffnx {C Function} scm_hashv_ref (table, key, dflt)
780ee65e
NJ
1694Look up @var{key} in the hash table @var{table}, and return the
1695value (if any) associated with it. If @var{key} is not found,
1696return @var{default} (or @code{#f} if no @var{default} argument
1697is supplied). Uses @code{eqv?} for equality testing.
1698@end deffn
1699
1700\fhashv-set!
8f85c0c6
NJ
1701@deffn {Scheme Procedure} hashv-set! table key val
1702@deffnx {C Function} scm_hashv_set_x (table, key, val)
780ee65e
NJ
1703Find the entry in @var{table} associated with @var{key}, and
1704store @var{value} there. Uses @code{eqv?} for equality testing.
1705@end deffn
1706
1707\fhashv-remove!
8f85c0c6
NJ
1708@deffn {Scheme Procedure} hashv-remove! table key
1709@deffnx {C Function} scm_hashv_remove_x (table, key)
780ee65e
NJ
1710Remove @var{key} (and any value associated with it) from
1711@var{table}. Uses @code{eqv?} for equality tests.
1712@end deffn
1713
1714\fhash-get-handle
8f85c0c6
NJ
1715@deffn {Scheme Procedure} hash-get-handle table key
1716@deffnx {C Function} scm_hash_get_handle (table, key)
ae9f3a15
MG
1717This procedure returns the @code{(key . value)} pair from the
1718hash table @var{table}. If @var{table} does not hold an
1719associated value for @var{key}, @code{#f} is returned.
1720Uses @code{equal?} for equality testing.
780ee65e
NJ
1721@end deffn
1722
1723\fhash-create-handle!
8f85c0c6
NJ
1724@deffn {Scheme Procedure} hash-create-handle! table key init
1725@deffnx {C Function} scm_hash_create_handle_x (table, key, init)
780ee65e
NJ
1726This function looks up @var{key} in @var{table} and returns its handle.
1727If @var{key} is not already present, a new handle is created which
1728associates @var{key} with @var{init}.
1729@end deffn
1730
1731\fhash-ref
8f85c0c6
NJ
1732@deffn {Scheme Procedure} hash-ref table key [dflt]
1733@deffnx {C Function} scm_hash_ref (table, key, dflt)
780ee65e
NJ
1734Look up @var{key} in the hash table @var{table}, and return the
1735value (if any) associated with it. If @var{key} is not found,
1736return @var{default} (or @code{#f} if no @var{default} argument
1737is supplied). Uses @code{equal?} for equality testing.
1738@end deffn
1739
1740\fhash-set!
8f85c0c6
NJ
1741@deffn {Scheme Procedure} hash-set! table key val
1742@deffnx {C Function} scm_hash_set_x (table, key, val)
780ee65e
NJ
1743Find the entry in @var{table} associated with @var{key}, and
1744store @var{value} there. Uses @code{equal?} for equality
1745testing.
1746@end deffn
1747
1748\fhash-remove!
8f85c0c6
NJ
1749@deffn {Scheme Procedure} hash-remove! table key
1750@deffnx {C Function} scm_hash_remove_x (table, key)
780ee65e
NJ
1751Remove @var{key} (and any value associated with it) from
1752@var{table}. Uses @code{equal?} for equality tests.
1753@end deffn
1754
1755\fhashx-get-handle
8f85c0c6
NJ
1756@deffn {Scheme Procedure} hashx-get-handle hash assoc table key
1757@deffnx {C Function} scm_hashx_get_handle (hash, assoc, table, key)
ae9f3a15
MG
1758This behaves the same way as the corresponding
1759@code{-get-handle} function, but uses @var{hash} as a hash
1760function and @var{assoc} to compare keys. @code{hash} must be
1761a function that takes two arguments, a key to be hashed and a
780ee65e
NJ
1762table size. @code{assoc} must be an associator function, like
1763@code{assoc}, @code{assq} or @code{assv}.
1764@end deffn
1765
1766\fhashx-create-handle!
8f85c0c6
NJ
1767@deffn {Scheme Procedure} hashx-create-handle! hash assoc table key init
1768@deffnx {C Function} scm_hashx_create_handle_x (hash, assoc, table, key, init)
ae9f3a15
MG
1769This behaves the same way as the corresponding
1770@code{-create-handle} function, but uses @var{hash} as a hash
1771function and @var{assoc} to compare keys. @code{hash} must be
1772a function that takes two arguments, a key to be hashed and a
780ee65e
NJ
1773table size. @code{assoc} must be an associator function, like
1774@code{assoc}, @code{assq} or @code{assv}.
1775@end deffn
1776
1777\fhashx-ref
8f85c0c6
NJ
1778@deffn {Scheme Procedure} hashx-ref hash assoc table key [dflt]
1779@deffnx {C Function} scm_hashx_ref (hash, assoc, table, key, dflt)
780ee65e 1780This behaves the same way as the corresponding @code{ref}
ae9f3a15
MG
1781function, but uses @var{hash} as a hash function and
1782@var{assoc} to compare keys. @code{hash} must be a function
1783that takes two arguments, a key to be hashed and a table size.
1784@code{assoc} must be an associator function, like @code{assoc},
1785@code{assq} or @code{assv}.
7a095584 1786
ae9f3a15
MG
1787By way of illustration, @code{hashq-ref table key} is
1788equivalent to @code{hashx-ref hashq assq table key}.
780ee65e
NJ
1789@end deffn
1790
1791\fhashx-set!
8f85c0c6
NJ
1792@deffn {Scheme Procedure} hashx-set! hash assoc table key val
1793@deffnx {C Function} scm_hashx_set_x (hash, assoc, table, key, val)
780ee65e 1794This behaves the same way as the corresponding @code{set!}
ae9f3a15
MG
1795function, but uses @var{hash} as a hash function and
1796@var{assoc} to compare keys. @code{hash} must be a function
1797that takes two arguments, a key to be hashed and a table size.
1798@code{assoc} must be an associator function, like @code{assoc},
1799@code{assq} or @code{assv}.
7a095584 1800
ae9f3a15
MG
1801 By way of illustration, @code{hashq-set! table key} is
1802equivalent to @code{hashx-set! hashq assq table key}.
780ee65e
NJ
1803@end deffn
1804
1805\fhash-fold
8f85c0c6
NJ
1806@deffn {Scheme Procedure} hash-fold proc init table
1807@deffnx {C Function} scm_hash_fold (proc, init, table)
780ee65e
NJ
1808An iterator over hash-table elements.
1809Accumulates and returns a result by applying PROC successively.
1810The arguments to PROC are "(key value prior-result)" where key
1811and value are successive pairs from the hash table TABLE, and
1812prior-result is either INIT (for the first application of PROC)
1813or the return value of the previous application of PROC.
72dd0a03 1814For example, @code{(hash-fold acons '() tab)} will convert a hash
780ee65e
NJ
1815table into an a-list of key-value pairs.
1816@end deffn
1817
780ee65e 1818\fmake-hook
8f85c0c6
NJ
1819@deffn {Scheme Procedure} make-hook [n_args]
1820@deffnx {C Function} scm_make_hook (n_args)
9401323e
NJ
1821Create a hook for storing procedure of arity @var{n_args}.
1822@var{n_args} defaults to zero. The returned value is a hook
1823object to be used with the other hook procedures.
780ee65e
NJ
1824@end deffn
1825
1826\fhook?
8f85c0c6
NJ
1827@deffn {Scheme Procedure} hook? x
1828@deffnx {C Function} scm_hook_p (x)
5c4b24e1 1829Return @code{#t} if @var{x} is a hook, @code{#f} otherwise.
780ee65e
NJ
1830@end deffn
1831
1832\fhook-empty?
8f85c0c6
NJ
1833@deffn {Scheme Procedure} hook-empty? hook
1834@deffnx {C Function} scm_hook_empty_p (hook)
5c4b24e1
MG
1835Return @code{#t} if @var{hook} is an empty hook, @code{#f}
1836otherwise.
780ee65e
NJ
1837@end deffn
1838
1839\fadd-hook!
8f85c0c6
NJ
1840@deffn {Scheme Procedure} add-hook! hook proc [append_p]
1841@deffnx {C Function} scm_add_hook_x (hook, proc, append_p)
780ee65e
NJ
1842Add the procedure @var{proc} to the hook @var{hook}. The
1843procedure is added to the end if @var{append_p} is true,
9401323e
NJ
1844otherwise it is added to the front. The return value of this
1845procedure is not specified.
780ee65e
NJ
1846@end deffn
1847
1848\fremove-hook!
8f85c0c6
NJ
1849@deffn {Scheme Procedure} remove-hook! hook proc
1850@deffnx {C Function} scm_remove_hook_x (hook, proc)
9401323e
NJ
1851Remove the procedure @var{proc} from the hook @var{hook}. The
1852return value of this procedure is not specified.
780ee65e
NJ
1853@end deffn
1854
1855\freset-hook!
8f85c0c6
NJ
1856@deffn {Scheme Procedure} reset-hook! hook
1857@deffnx {C Function} scm_reset_hook_x (hook)
9401323e
NJ
1858Remove all procedures from the hook @var{hook}. The return
1859value of this procedure is not specified.
780ee65e
NJ
1860@end deffn
1861
1862\frun-hook
8f85c0c6
NJ
1863@deffn {Scheme Procedure} run-hook hook . args
1864@deffnx {C Function} scm_run_hook (hook, args)
780ee65e 1865Apply all procedures from the hook @var{hook} to the arguments
5c4b24e1 1866@var{args}. The order of the procedure application is first to
9401323e 1867last. The return value of this procedure is not specified.
780ee65e
NJ
1868@end deffn
1869
1870\fhook->list
8f85c0c6
NJ
1871@deffn {Scheme Procedure} hook->list hook
1872@deffnx {C Function} scm_hook_to_list (hook)
780ee65e
NJ
1873Convert the procedure list of @var{hook} to a list.
1874@end deffn
1875
780ee65e 1876\fftell
8f85c0c6
NJ
1877@deffn {Scheme Procedure} ftell fd_port
1878@deffnx {C Function} scm_ftell (fd_port)
ae9f3a15
MG
1879Return an integer representing the current position of
1880@var{fd/port}, measured from the beginning. Equivalent to:
7a095584 1881
ae9f3a15 1882@lisp
780ee65e 1883(seek port 0 SEEK_CUR)
ae9f3a15 1884@end lisp
780ee65e
NJ
1885@end deffn
1886
780ee65e 1887\fredirect-port
8f85c0c6
NJ
1888@deffn {Scheme Procedure} redirect-port old new
1889@deffnx {C Function} scm_redirect_port (old, new)
780ee65e
NJ
1890This procedure takes two ports and duplicates the underlying file
1891descriptor from @var{old-port} into @var{new-port}. The
1892current file descriptor in @var{new-port} will be closed.
1893After the redirection the two ports will share a file position
1894and file status flags.
1895
1896The return value is unspecified.
1897
1898Unexpected behaviour can result if both ports are subsequently used
1899and the original and/or duplicate ports are buffered.
1900
1901This procedure does not have any side effects on other ports or
1902revealed counts.
1903@end deffn
1904
1905\fdup->fdes
8f85c0c6
NJ
1906@deffn {Scheme Procedure} dup->fdes fd_or_port [fd]
1907@deffnx {C Function} scm_dup_to_fdes (fd_or_port, fd)
ae9f3a15
MG
1908Return a new integer file descriptor referring to the open file
1909designated by @var{fd_or_port}, which must be either an open
1910file port or a file descriptor.
780ee65e
NJ
1911@end deffn
1912
1913\fdup2
8f85c0c6
NJ
1914@deffn {Scheme Procedure} dup2 oldfd newfd
1915@deffnx {C Function} scm_dup2 (oldfd, newfd)
780ee65e
NJ
1916A simple wrapper for the @code{dup2} system call.
1917Copies the file descriptor @var{oldfd} to descriptor
1918number @var{newfd}, replacing the previous meaning
1919of @var{newfd}. Both @var{oldfd} and @var{newfd} must
1920be integers.
1921Unlike for dup->fdes or primitive-move->fdes, no attempt
1922is made to move away ports which are using @var{newfd}.
1923The return value is unspecified.
1924@end deffn
1925
1926\ffileno
8f85c0c6
NJ
1927@deffn {Scheme Procedure} fileno port
1928@deffnx {C Function} scm_fileno (port)
ae9f3a15
MG
1929Return the integer file descriptor underlying @var{port}. Does
1930not change its revealed count.
780ee65e
NJ
1931@end deffn
1932
1933\fisatty?
8f85c0c6
NJ
1934@deffn {Scheme Procedure} isatty? port
1935@deffnx {C Function} scm_isatty_p (port)
ae9f3a15
MG
1936Return @code{#t} if @var{port} is using a serial non--file
1937device, otherwise @code{#f}.
780ee65e
NJ
1938@end deffn
1939
1940\ffdopen
8f85c0c6
NJ
1941@deffn {Scheme Procedure} fdopen fdes modes
1942@deffnx {C Function} scm_fdopen (fdes, modes)
ae9f3a15
MG
1943Return a new port based on the file descriptor @var{fdes}.
1944Modes are given by the string @var{modes}. The revealed count
1945of the port is initialized to zero. The modes string is the
1946same as that accepted by @ref{File Ports, open-file}.
780ee65e
NJ
1947@end deffn
1948
1949\fprimitive-move->fdes
8f85c0c6
NJ
1950@deffn {Scheme Procedure} primitive-move->fdes port fd
1951@deffnx {C Function} scm_primitive_move_to_fdes (port, fd)
780ee65e
NJ
1952Moves the underlying file descriptor for @var{port} to the integer
1953value @var{fdes} without changing the revealed count of @var{port}.
1954Any other ports already using this descriptor will be automatically
1955shifted to new descriptors and their revealed counts reset to zero.
1956The return value is @code{#f} if the file descriptor already had the
1957required value or @code{#t} if it was moved.
1958@end deffn
1959
1960\ffdes->ports
8f85c0c6
NJ
1961@deffn {Scheme Procedure} fdes->ports fd
1962@deffnx {C Function} scm_fdes_to_ports (fd)
ae9f3a15
MG
1963Return a list of existing ports which have @var{fdes} as an
1964underlying file descriptor, without changing their revealed
1965counts.
780ee65e
NJ
1966@end deffn
1967
1968\fmake-keyword-from-dash-symbol
8f85c0c6
NJ
1969@deffn {Scheme Procedure} make-keyword-from-dash-symbol symbol
1970@deffnx {C Function} scm_make_keyword_from_dash_symbol (symbol)
780ee65e
NJ
1971Make a keyword object from a @var{symbol} that starts with a dash.
1972@end deffn
1973
1974\fkeyword?
8f85c0c6
NJ
1975@deffn {Scheme Procedure} keyword? obj
1976@deffnx {C Function} scm_keyword_p (obj)
ae9f3a15
MG
1977Return @code{#t} if the argument @var{obj} is a keyword, else
1978@code{#f}.
780ee65e
NJ
1979@end deffn
1980
1981\fkeyword-dash-symbol
8f85c0c6
NJ
1982@deffn {Scheme Procedure} keyword-dash-symbol keyword
1983@deffnx {C Function} scm_keyword_dash_symbol (keyword)
780ee65e
NJ
1984Return the dash symbol for @var{keyword}.
1985This is the inverse of @code{make-keyword-from-dash-symbol}.
1986@end deffn
1987
1988\fnil-cons
8f85c0c6
NJ
1989@deffn {Scheme Procedure} nil-cons x y
1990@deffnx {C Function} scm_nil_cons (x, y)
780ee65e
NJ
1991Create a new cons cell with @var{x} as the car and @var{y} as
1992the cdr, but convert @var{y} to Scheme's end-of-list if it is
1993a LISP nil.
1994@end deffn
1995
1996\fnil-car
8f85c0c6
NJ
1997@deffn {Scheme Procedure} nil-car x
1998@deffnx {C Function} scm_nil_car (x)
780ee65e
NJ
1999Return the car of @var{x}, but convert it to LISP nil if it
2000is Scheme's end-of-list.
2001@end deffn
2002
2003\fnil-cdr
8f85c0c6
NJ
2004@deffn {Scheme Procedure} nil-cdr x
2005@deffnx {C Function} scm_nil_cdr (x)
780ee65e
NJ
2006Return the cdr of @var{x}, but convert it to LISP nil if it
2007is Scheme's end-of-list.
2008@end deffn
2009
2010\fnull
8f85c0c6
NJ
2011@deffn {Scheme Procedure} null x
2012@deffnx {C Function} scm_null (x)
780ee65e
NJ
2013Return LISP's @code{t} if @var{x} is nil in the LISP sense,
2014return LISP's nil otherwise.
2015@end deffn
2016
2017\fnil-eq
8f85c0c6 2018@deffn {Scheme Procedure} nil-eq x y
780ee65e
NJ
2019Compare @var{x} and @var{y} and return LISP's t if they are
2020@code{eq?}, return LISP's nil otherwise.
2021@end deffn
2022
2023\flist
8f85c0c6
NJ
2024@deffn {Scheme Procedure} list . objs
2025@deffnx {C Function} scm_list (objs)
780ee65e
NJ
2026Return a list containing @var{objs}, the arguments to
2027@code{list}.
2028@end deffn
2029
780ee65e 2030\fcons*
8f85c0c6
NJ
2031@deffn {Scheme Procedure} cons* arg . rest
2032@deffnx {C Function} scm_cons_star (arg, rest)
780ee65e
NJ
2033Like @code{list}, but the last arg provides the tail of the
2034constructed list, returning @code{(cons @var{arg1} (cons
a6be01a4 2035@var{arg2} (cons @dots{} @var{argn})))}. Requires at least one
780ee65e
NJ
2036argument. If given one argument, that argument is returned as
2037result. This function is called @code{list*} in some other
2038Schemes and in Common LISP.
2039@end deffn
2040
2041\fnull?
8f85c0c6
NJ
2042@deffn {Scheme Procedure} null? x
2043@deffnx {C Function} scm_null_p (x)
780ee65e
NJ
2044Return @code{#t} iff @var{x} is the empty list, else @code{#f}.
2045@end deffn
2046
2047\flist?
8f85c0c6
NJ
2048@deffn {Scheme Procedure} list? x
2049@deffnx {C Function} scm_list_p (x)
780ee65e
NJ
2050Return @code{#t} iff @var{x} is a proper list, else @code{#f}.
2051@end deffn
2052
2053\flength
8f85c0c6
NJ
2054@deffn {Scheme Procedure} length lst
2055@deffnx {C Function} scm_length (lst)
780ee65e
NJ
2056Return the number of elements in list @var{lst}.
2057@end deffn
2058
2059\fappend
8f85c0c6
NJ
2060@deffn {Scheme Procedure} append . args
2061@deffnx {C Function} scm_append (args)
780ee65e
NJ
2062Return a list consisting of the elements the lists passed as
2063arguments.
ae9f3a15 2064@lisp
780ee65e
NJ
2065(append '(x) '(y)) @result{} (x y)
2066(append '(a) '(b c d)) @result{} (a b c d)
2067(append '(a (b)) '((c))) @result{} (a (b) (c))
ae9f3a15 2068@end lisp
780ee65e
NJ
2069The resulting list is always newly allocated, except that it
2070shares structure with the last list argument. The last
2071argument may actually be any object; an improper list results
2072if the last argument is not a proper list.
ae9f3a15 2073@lisp
780ee65e
NJ
2074(append '(a b) '(c . d)) @result{} (a b c . d)
2075(append '() 'a) @result{} a
ae9f3a15 2076@end lisp
780ee65e
NJ
2077@end deffn
2078
2079\fappend!
8f85c0c6
NJ
2080@deffn {Scheme Procedure} append! . lists
2081@deffnx {C Function} scm_append_x (lists)
ae9f3a15 2082A destructive version of @code{append} (@pxref{Pairs and
9401323e 2083Lists,,,r5rs, The Revised^5 Report on Scheme}). The cdr field
ae9f3a15
MG
2084of each list's final pair is changed to point to the head of
2085the next list, so no consing is performed. Return a pointer to
2086the mutated list.
780ee65e
NJ
2087@end deffn
2088
2089\flast-pair
8f85c0c6
NJ
2090@deffn {Scheme Procedure} last-pair lst
2091@deffnx {C Function} scm_last_pair (lst)
780ee65e
NJ
2092Return a pointer to the last pair in @var{lst}, signalling an error if
2093@var{lst} is circular.
2094@end deffn
2095
2096\freverse
8f85c0c6
NJ
2097@deffn {Scheme Procedure} reverse lst
2098@deffnx {C Function} scm_reverse (lst)
780ee65e
NJ
2099Return a new list that contains the elements of @var{lst} but
2100in reverse order.
2101@end deffn
2102
2103\freverse!
8f85c0c6
NJ
2104@deffn {Scheme Procedure} reverse! lst [new_tail]
2105@deffnx {C Function} scm_reverse_x (lst, new_tail)
9401323e
NJ
2106A destructive version of @code{reverse} (@pxref{Pairs and Lists,,,r5rs,
2107The Revised^5 Report on Scheme}). The cdr of each cell in @var{lst} is
780ee65e
NJ
2108modified to point to the previous list element. Return a pointer to the
2109head of the reversed list.
2110
2111Caveat: because the list is modified in place, the tail of the original
2112list now becomes its head, and the head of the original list now becomes
2113the tail. Therefore, the @var{lst} symbol to which the head of the
2114original list was bound now points to the tail. To ensure that the head
2115of the modified list is not lost, it is wise to save the return value of
2116@code{reverse!}
2117@end deffn
2118
2119\flist-ref
8f85c0c6
NJ
2120@deffn {Scheme Procedure} list-ref list k
2121@deffnx {C Function} scm_list_ref (list, k)
780ee65e
NJ
2122Return the @var{k}th element from @var{list}.
2123@end deffn
2124
2125\flist-set!
8f85c0c6
NJ
2126@deffn {Scheme Procedure} list-set! list k val
2127@deffnx {C Function} scm_list_set_x (list, k, val)
780ee65e
NJ
2128Set the @var{k}th element of @var{list} to @var{val}.
2129@end deffn
2130
2131\flist-cdr-ref
8f85c0c6 2132@deffn {Scheme Procedure} list-cdr-ref
9401323e 2133implemented by the C function "scm_list_tail"
780ee65e
NJ
2134@end deffn
2135
2136\flist-tail
8f85c0c6
NJ
2137@deffn {Scheme Procedure} list-tail lst k
2138@deffnx {Scheme Procedure} list-cdr-ref lst k
2139@deffnx {C Function} scm_list_tail (lst, k)
780ee65e
NJ
2140Return the "tail" of @var{lst} beginning with its @var{k}th element.
2141The first element of the list is considered to be element 0.
2142
2143@code{list-tail} and @code{list-cdr-ref} are identical. It may help to
2144think of @code{list-cdr-ref} as accessing the @var{k}th cdr of the list,
2145or returning the results of cdring @var{k} times down @var{lst}.
2146@end deffn
2147
2148\flist-cdr-set!
8f85c0c6
NJ
2149@deffn {Scheme Procedure} list-cdr-set! list k val
2150@deffnx {C Function} scm_list_cdr_set_x (list, k, val)
780ee65e
NJ
2151Set the @var{k}th cdr of @var{list} to @var{val}.
2152@end deffn
2153
2154\flist-head
8f85c0c6
NJ
2155@deffn {Scheme Procedure} list-head lst k
2156@deffnx {C Function} scm_list_head (lst, k)
780ee65e
NJ
2157Copy the first @var{k} elements from @var{lst} into a new list, and
2158return it.
2159@end deffn
2160
2161\flist-copy
8f85c0c6
NJ
2162@deffn {Scheme Procedure} list-copy lst
2163@deffnx {C Function} scm_list_copy (lst)
780ee65e
NJ
2164Return a (newly-created) copy of @var{lst}.
2165@end deffn
2166
780ee65e 2167\fmemq
8f85c0c6
NJ
2168@deffn {Scheme Procedure} memq x lst
2169@deffnx {C Function} scm_memq (x, lst)
780ee65e
NJ
2170Return the first sublist of @var{lst} whose car is @code{eq?}
2171to @var{x} where the sublists of @var{lst} are the non-empty
2172lists returned by @code{(list-tail @var{lst} @var{k})} for
2173@var{k} less than the length of @var{lst}. If @var{x} does not
2174occur in @var{lst}, then @code{#f} (not the empty list) is
2175returned.
2176@end deffn
2177
2178\fmemv
8f85c0c6
NJ
2179@deffn {Scheme Procedure} memv x lst
2180@deffnx {C Function} scm_memv (x, lst)
780ee65e
NJ
2181Return the first sublist of @var{lst} whose car is @code{eqv?}
2182to @var{x} where the sublists of @var{lst} are the non-empty
2183lists returned by @code{(list-tail @var{lst} @var{k})} for
2184@var{k} less than the length of @var{lst}. If @var{x} does not
2185occur in @var{lst}, then @code{#f} (not the empty list) is
2186returned.
2187@end deffn
2188
2189\fmember
8f85c0c6
NJ
2190@deffn {Scheme Procedure} member x lst
2191@deffnx {C Function} scm_member (x, lst)
780ee65e
NJ
2192Return the first sublist of @var{lst} whose car is
2193@code{equal?} to @var{x} where the sublists of @var{lst} are
2194the non-empty lists returned by @code{(list-tail @var{lst}
2195@var{k})} for @var{k} less than the length of @var{lst}. If
2196@var{x} does not occur in @var{lst}, then @code{#f} (not the
2197empty list) is returned.
2198@end deffn
2199
2200\fdelq!
8f85c0c6
NJ
2201@deffn {Scheme Procedure} delq! item lst
2202@deffnx {Scheme Procedure} delv! item lst
2203@deffnx {Scheme Procedure} delete! item lst
2204@deffnx {C Function} scm_delq_x (item, lst)
780ee65e
NJ
2205These procedures are destructive versions of @code{delq}, @code{delv}
2206and @code{delete}: they modify the pointers in the existing @var{lst}
2207rather than creating a new list. Caveat evaluator: Like other
2208destructive list functions, these functions cannot modify the binding of
2209@var{lst}, and so cannot be used to delete the first element of
2210@var{lst} destructively.
2211@end deffn
2212
2213\fdelv!
8f85c0c6
NJ
2214@deffn {Scheme Procedure} delv! item lst
2215@deffnx {C Function} scm_delv_x (item, lst)
780ee65e
NJ
2216Destructively remove all elements from @var{lst} that are
2217@code{eqv?} to @var{item}.
2218@end deffn
2219
2220\fdelete!
8f85c0c6
NJ
2221@deffn {Scheme Procedure} delete! item lst
2222@deffnx {C Function} scm_delete_x (item, lst)
780ee65e
NJ
2223Destructively remove all elements from @var{lst} that are
2224@code{equal?} to @var{item}.
2225@end deffn
2226
2227\fdelq
8f85c0c6
NJ
2228@deffn {Scheme Procedure} delq item lst
2229@deffnx {C Function} scm_delq (item, lst)
780ee65e
NJ
2230Return a newly-created copy of @var{lst} with elements
2231@code{eq?} to @var{item} removed. This procedure mirrors
2232@code{memq}: @code{delq} compares elements of @var{lst} against
2233@var{item} with @code{eq?}.
2234@end deffn
2235
2236\fdelv
8f85c0c6
NJ
2237@deffn {Scheme Procedure} delv item lst
2238@deffnx {C Function} scm_delv (item, lst)
780ee65e
NJ
2239Return a newly-created copy of @var{lst} with elements
2240@code{eqv?} to @var{item} removed. This procedure mirrors
2241@code{memv}: @code{delv} compares elements of @var{lst} against
2242@var{item} with @code{eqv?}.
2243@end deffn
2244
2245\fdelete
8f85c0c6
NJ
2246@deffn {Scheme Procedure} delete item lst
2247@deffnx {C Function} scm_delete (item, lst)
780ee65e
NJ
2248Return a newly-created copy of @var{lst} with elements
2249@code{equal?} to @var{item} removed. This procedure mirrors
2250@code{member}: @code{delete} compares elements of @var{lst}
2251against @var{item} with @code{equal?}.
2252@end deffn
2253
2254\fdelq1!
8f85c0c6
NJ
2255@deffn {Scheme Procedure} delq1! item lst
2256@deffnx {C Function} scm_delq1_x (item, lst)
780ee65e
NJ
2257Like @code{delq!}, but only deletes the first occurrence of
2258@var{item} from @var{lst}. Tests for equality using
2259@code{eq?}. See also @code{delv1!} and @code{delete1!}.
2260@end deffn
2261
2262\fdelv1!
8f85c0c6
NJ
2263@deffn {Scheme Procedure} delv1! item lst
2264@deffnx {C Function} scm_delv1_x (item, lst)
780ee65e
NJ
2265Like @code{delv!}, but only deletes the first occurrence of
2266@var{item} from @var{lst}. Tests for equality using
2267@code{eqv?}. See also @code{delq1!} and @code{delete1!}.
2268@end deffn
2269
2270\fdelete1!
8f85c0c6
NJ
2271@deffn {Scheme Procedure} delete1! item lst
2272@deffnx {C Function} scm_delete1_x (item, lst)
780ee65e
NJ
2273Like @code{delete!}, but only deletes the first occurrence of
2274@var{item} from @var{lst}. Tests for equality using
2275@code{equal?}. See also @code{delq1!} and @code{delv1!}.
2276@end deffn
2277
2278\fprimitive-load
8f85c0c6
NJ
2279@deffn {Scheme Procedure} primitive-load filename
2280@deffnx {C Function} scm_primitive_load (filename)
780ee65e
NJ
2281Load the file named @var{filename} and evaluate its contents in
2282the top-level environment. The load paths are not searched;
2283@var{filename} must either be a full pathname or be a pathname
2284relative to the current directory. If the variable
2285@code{%load-hook} is defined, it should be bound to a procedure
2286that will be called before any code is loaded. See the
2287documentation for @code{%load-hook} later in this section.
2288@end deffn
2289
2290\f%package-data-dir
8f85c0c6
NJ
2291@deffn {Scheme Procedure} %package-data-dir
2292@deffnx {C Function} scm_sys_package_data_dir ()
780ee65e
NJ
2293Return the name of the directory where Scheme packages, modules and
2294libraries are kept. On most Unix systems, this will be
2295@samp{/usr/local/share/guile}.
2296@end deffn
2297
2298\f%library-dir
8f85c0c6
NJ
2299@deffn {Scheme Procedure} %library-dir
2300@deffnx {C Function} scm_sys_library_dir ()
780ee65e
NJ
2301Return the directory where the Guile Scheme library files are installed.
2302E.g., may return "/usr/share/guile/1.3.5".
2303@end deffn
2304
2305\f%site-dir
8f85c0c6
NJ
2306@deffn {Scheme Procedure} %site-dir
2307@deffnx {C Function} scm_sys_site_dir ()
780ee65e
NJ
2308Return the directory where the Guile site files are installed.
2309E.g., may return "/usr/share/guile/site".
2310@end deffn
2311
2312\fparse-path
8f85c0c6
NJ
2313@deffn {Scheme Procedure} parse-path path [tail]
2314@deffnx {C Function} scm_parse_path (path, tail)
780ee65e
NJ
2315Parse @var{path}, which is expected to be a colon-separated
2316string, into a list and return the resulting list with
2317@var{tail} appended. If @var{path} is @code{#f}, @var{tail}
2318is returned.
2319@end deffn
2320
2321\fsearch-path
8f85c0c6
NJ
2322@deffn {Scheme Procedure} search-path path filename [extensions]
2323@deffnx {C Function} scm_search_path (path, filename, extensions)
780ee65e
NJ
2324Search @var{path} for a directory containing a file named
2325@var{filename}. The file must be readable, and not a directory.
2326If we find one, return its full filename; otherwise, return
2327@code{#f}. If @var{filename} is absolute, return it unchanged.
2328If given, @var{extensions} is a list of strings; for each
2329directory in @var{path}, we search for @var{filename}
2330concatenated with each @var{extension}.
2331@end deffn
2332
2333\f%search-load-path
8f85c0c6
NJ
2334@deffn {Scheme Procedure} %search-load-path filename
2335@deffnx {C Function} scm_sys_search_load_path (filename)
780ee65e
NJ
2336Search @var{%load-path} for the file named @var{filename},
2337which must be readable by the current user. If @var{filename}
2338is found in the list of paths to search or is an absolute
2339pathname, return its full pathname. Otherwise, return
2340@code{#f}. Filenames may have any of the optional extensions
2341in the @code{%load-extensions} list; @code{%search-load-path}
2342will try each extension automatically.
2343@end deffn
2344
2345\fprimitive-load-path
8f85c0c6
NJ
2346@deffn {Scheme Procedure} primitive-load-path filename
2347@deffnx {C Function} scm_primitive_load_path (filename)
780ee65e
NJ
2348Search @var{%load-path} for the file named @var{filename} and
2349load it into the top-level environment. If @var{filename} is a
2350relative pathname and is not found in the list of search paths,
2351an error is signalled.
2352@end deffn
2353
780ee65e 2354\fprocedure->syntax
8f85c0c6
NJ
2355@deffn {Scheme Procedure} procedure->syntax code
2356@deffnx {C Function} scm_makacro (code)
ae9f3a15
MG
2357Return a @dfn{macro} which, when a symbol defined to this value
2358appears as the first symbol in an expression, returns the
2359result of applying @var{code} to the expression and the
2360environment.
780ee65e
NJ
2361@end deffn
2362
2363\fprocedure->macro
8f85c0c6
NJ
2364@deffn {Scheme Procedure} procedure->macro code
2365@deffnx {C Function} scm_makmacro (code)
ae9f3a15
MG
2366Return a @dfn{macro} which, when a symbol defined to this value
2367appears as the first symbol in an expression, evaluates the
2368result of applying @var{code} to the expression and the
2369environment. The value returned from @var{code} which has been
2370passed to @code{procedure->memoizing-macro} replaces the form
2371passed to @var{code}. For example:
7a095584 2372
ae9f3a15 2373@lisp
780ee65e
NJ
2374(define trace
2375 (procedure->macro
2376 (lambda (x env) `(set! ,(cadr x) (tracef ,(cadr x) ',(cadr x))))))
2377
2378(trace @i{foo}) @equiv{} (set! @i{foo} (tracef @i{foo} '@i{foo})).
ae9f3a15 2379@end lisp
780ee65e
NJ
2380@end deffn
2381
2382\fprocedure->memoizing-macro
8f85c0c6
NJ
2383@deffn {Scheme Procedure} procedure->memoizing-macro code
2384@deffnx {C Function} scm_makmmacro (code)
ae9f3a15
MG
2385Return a @dfn{macro} which, when a symbol defined to this value
2386appears as the first symbol in an expression, evaluates the
2387result of applying @var{proc} to the expression and the
2388environment. The value returned from @var{proc} which has been
2389passed to @code{procedure->memoizing-macro} replaces the form
2390passed to @var{proc}. For example:
7a095584 2391
ae9f3a15 2392@lisp
780ee65e
NJ
2393(define trace
2394 (procedure->macro
2395 (lambda (x env) `(set! ,(cadr x) (tracef ,(cadr x) ',(cadr x))))))
2396
2397(trace @i{foo}) @equiv{} (set! @i{foo} (tracef @i{foo} '@i{foo})).
ae9f3a15 2398@end lisp
780ee65e
NJ
2399@end deffn
2400
2401\fmacro?
8f85c0c6
NJ
2402@deffn {Scheme Procedure} macro? obj
2403@deffnx {C Function} scm_macro_p (obj)
780ee65e
NJ
2404Return @code{#t} if @var{obj} is a regular macro, a memoizing macro or a
2405syntax transformer.
2406@end deffn
2407
2408\fmacro-type
8f85c0c6
NJ
2409@deffn {Scheme Procedure} macro-type m
2410@deffnx {C Function} scm_macro_type (m)
ae9f3a15
MG
2411Return one of the symbols @code{syntax}, @code{macro} or
2412@code{macro!}, depending on whether @var{m} is a syntax
8f85c0c6 2413transformer, a regular macro, or a memoizing macro,
ae9f3a15
MG
2414respectively. If @var{m} is not a macro, @code{#f} is
2415returned.
780ee65e
NJ
2416@end deffn
2417
2418\fmacro-name
8f85c0c6
NJ
2419@deffn {Scheme Procedure} macro-name m
2420@deffnx {C Function} scm_macro_name (m)
780ee65e
NJ
2421Return the name of the macro @var{m}.
2422@end deffn
2423
2424\fmacro-transformer
8f85c0c6
NJ
2425@deffn {Scheme Procedure} macro-transformer m
2426@deffnx {C Function} scm_macro_transformer (m)
780ee65e
NJ
2427Return the transformer of the macro @var{m}.
2428@end deffn
2429
7a095584 2430\fcurrent-module
8f85c0c6
NJ
2431@deffn {Scheme Procedure} current-module
2432@deffnx {C Function} scm_current_module ()
7a095584
NJ
2433Return the current module.
2434@end deffn
2435
2436\fset-current-module
8f85c0c6
NJ
2437@deffn {Scheme Procedure} set-current-module module
2438@deffnx {C Function} scm_set_current_module (module)
7a095584
NJ
2439Set the current module to @var{module} and return
2440the previous current module.
2441@end deffn
2442
780ee65e 2443\finteraction-environment
8f85c0c6
NJ
2444@deffn {Scheme Procedure} interaction-environment
2445@deffnx {C Function} scm_interaction_environment ()
ae9f3a15
MG
2446Return a specifier for the environment that contains
2447implementation--defined bindings, typically a superset of those
2448listed in the report. The intent is that this procedure will
2449return the environment in which the implementation would
2450evaluate expressions dynamically typed by the user.
780ee65e
NJ
2451@end deffn
2452
9401323e 2453\fenv-module
8f85c0c6
NJ
2454@deffn {Scheme Procedure} env-module env
2455@deffnx {C Function} scm_env_module (env)
9401323e
NJ
2456Return the module of @var{ENV}, a lexical environment.
2457@end deffn
2458
780ee65e 2459\fstandard-eval-closure
8f85c0c6
NJ
2460@deffn {Scheme Procedure} standard-eval-closure module
2461@deffnx {C Function} scm_standard_eval_closure (module)
780ee65e
NJ
2462Return an eval closure for the module @var{module}.
2463@end deffn
2464
9401323e 2465\fstandard-interface-eval-closure
8f85c0c6
NJ
2466@deffn {Scheme Procedure} standard-interface-eval-closure module
2467@deffnx {C Function} scm_standard_interface_eval_closure (module)
9401323e 2468Return a interface eval closure for the module @var{module}. Such a closure does not allow new bindings to be added.
780ee65e
NJ
2469@end deffn
2470
9401323e 2471\f%get-pre-modules-obarray
8f85c0c6
NJ
2472@deffn {Scheme Procedure} %get-pre-modules-obarray
2473@deffnx {C Function} scm_get_pre_modules_obarray ()
9401323e 2474Return the obarray that is used for all new bindings before the module system is booted. The first call to @code{set-current-module} will boot the module system.
780ee65e
NJ
2475@end deffn
2476
2477\fexact?
8f85c0c6
NJ
2478@deffn {Scheme Procedure} exact? x
2479@deffnx {C Function} scm_exact_p (x)
780ee65e
NJ
2480Return @code{#t} if @var{x} is an exact number, @code{#f}
2481otherwise.
2482@end deffn
2483
2484\fodd?
8f85c0c6
NJ
2485@deffn {Scheme Procedure} odd? n
2486@deffnx {C Function} scm_odd_p (n)
780ee65e
NJ
2487Return @code{#t} if @var{n} is an odd number, @code{#f}
2488otherwise.
2489@end deffn
2490
2491\feven?
8f85c0c6
NJ
2492@deffn {Scheme Procedure} even? n
2493@deffnx {C Function} scm_even_p (n)
780ee65e
NJ
2494Return @code{#t} if @var{n} is an even number, @code{#f}
2495otherwise.
2496@end deffn
2497
2498\flogand
8f85c0c6 2499@deffn {Scheme Procedure} logand n1 n2
9401323e 2500Return the bitwise AND of the integer arguments.
7a095584 2501
780ee65e 2502@lisp
9401323e
NJ
2503(logand) @result{} -1
2504(logand 7) @result{} 7
2505(logand #b111 #b011 #b001) @result{} 1
780ee65e
NJ
2506@end lisp
2507@end deffn
2508
2509\flogior
8f85c0c6 2510@deffn {Scheme Procedure} logior n1 n2
9401323e 2511Return the bitwise OR of the integer arguments.
7a095584 2512
780ee65e 2513@lisp
9401323e
NJ
2514(logior) @result{} 0
2515(logior 7) @result{} 7
2516(logior #b000 #b001 #b011) @result{} 3
780ee65e
NJ
2517@end lisp
2518@end deffn
2519
2520\flogxor
8f85c0c6 2521@deffn {Scheme Procedure} logxor n1 n2
9401323e
NJ
2522Return the bitwise XOR of the integer arguments. A bit is
2523set in the result if it is set in an odd number of arguments.
780ee65e 2524@lisp
9401323e
NJ
2525(logxor) @result{} 0
2526(logxor 7) @result{} 7
2527(logxor #b000 #b001 #b011) @result{} 2
2528(logxor #b000 #b001 #b011 #b011) @result{} 1
780ee65e
NJ
2529@end lisp
2530@end deffn
2531
2532\flogtest
8f85c0c6
NJ
2533@deffn {Scheme Procedure} logtest j k
2534@deffnx {C Function} scm_logtest (j, k)
ae9f3a15 2535@lisp
780ee65e
NJ
2536(logtest j k) @equiv{} (not (zero? (logand j k)))
2537
2538(logtest #b0100 #b1011) @result{} #f
2539(logtest #b0100 #b0111) @result{} #t
ae9f3a15 2540@end lisp
780ee65e
NJ
2541@end deffn
2542
2543\flogbit?
8f85c0c6
NJ
2544@deffn {Scheme Procedure} logbit? index j
2545@deffnx {C Function} scm_logbit_p (index, j)
ae9f3a15 2546@lisp
780ee65e
NJ
2547(logbit? index j) @equiv{} (logtest (integer-expt 2 index) j)
2548
2549(logbit? 0 #b1101) @result{} #t
2550(logbit? 1 #b1101) @result{} #f
2551(logbit? 2 #b1101) @result{} #t
2552(logbit? 3 #b1101) @result{} #t
2553(logbit? 4 #b1101) @result{} #f
ae9f3a15 2554@end lisp
780ee65e
NJ
2555@end deffn
2556
2557\flognot
8f85c0c6
NJ
2558@deffn {Scheme Procedure} lognot n
2559@deffnx {C Function} scm_lognot (n)
ae9f3a15
MG
2560Return the integer which is the 2s-complement of the integer
2561argument.
7a095584 2562
780ee65e
NJ
2563@lisp
2564(number->string (lognot #b10000000) 2)
2565 @result{} "-10000001"
2566(number->string (lognot #b0) 2)
2567 @result{} "-1"
2568@end lisp
2569@end deffn
2570
2571\finteger-expt
8f85c0c6
NJ
2572@deffn {Scheme Procedure} integer-expt n k
2573@deffnx {C Function} scm_integer_expt (n, k)
ae9f3a15
MG
2574Return @var{n} raised to the non-negative integer exponent
2575@var{k}.
7a095584 2576
780ee65e
NJ
2577@lisp
2578(integer-expt 2 5)
2579 @result{} 32
2580(integer-expt -3 3)
2581 @result{} -27
2582@end lisp
2583@end deffn
2584
2585\fash
8f85c0c6
NJ
2586@deffn {Scheme Procedure} ash n cnt
2587@deffnx {C Function} scm_ash (n, cnt)
ae9f3a15
MG
2588The function ash performs an arithmetic shift left by @var{cnt}
2589bits (or shift right, if @var{cnt} is negative). 'Arithmetic'
2590means, that the function does not guarantee to keep the bit
2591structure of @var{n}, but rather guarantees that the result
2592will always be rounded towards minus infinity. Therefore, the
2593results of ash and a corresponding bitwise shift will differ if
2594@var{n} is negative.
7a095584 2595
780ee65e
NJ
2596Formally, the function returns an integer equivalent to
2597@code{(inexact->exact (floor (* @var{n} (expt 2 @var{cnt}))))}.
7a095584 2598
780ee65e 2599@lisp
ae9f3a15
MG
2600(number->string (ash #b1 3) 2) @result{} "1000"
2601(number->string (ash #b1010 -1) 2) @result{} "101"
780ee65e
NJ
2602@end lisp
2603@end deffn
2604
2605\fbit-extract
8f85c0c6
NJ
2606@deffn {Scheme Procedure} bit-extract n start end
2607@deffnx {C Function} scm_bit_extract (n, start, end)
ae9f3a15
MG
2608Return the integer composed of the @var{start} (inclusive)
2609through @var{end} (exclusive) bits of @var{n}. The
2610@var{start}th bit becomes the 0-th bit in the result.
7a095584 2611
780ee65e
NJ
2612@lisp
2613(number->string (bit-extract #b1101101010 0 4) 2)
2614 @result{} "1010"
2615(number->string (bit-extract #b1101101010 4 9) 2)
2616 @result{} "10110"
2617@end lisp
2618@end deffn
2619
2620\flogcount
8f85c0c6
NJ
2621@deffn {Scheme Procedure} logcount n
2622@deffnx {C Function} scm_logcount (n)
ae9f3a15
MG
2623Return the number of bits in integer @var{n}. If integer is
2624positive, the 1-bits in its binary representation are counted.
2625If negative, the 0-bits in its two's-complement binary
2626representation are counted. If 0, 0 is returned.
7a095584 2627
780ee65e
NJ
2628@lisp
2629(logcount #b10101010)
2630 @result{} 4
2631(logcount 0)
2632 @result{} 0
2633(logcount -2)
2634 @result{} 1
2635@end lisp
2636@end deffn
2637
2638\finteger-length
8f85c0c6
NJ
2639@deffn {Scheme Procedure} integer-length n
2640@deffnx {C Function} scm_integer_length (n)
ae9f3a15 2641Return the number of bits neccessary to represent @var{n}.
7a095584 2642
780ee65e
NJ
2643@lisp
2644(integer-length #b10101010)
2645 @result{} 8
2646(integer-length 0)
2647 @result{} 0
2648(integer-length #b1111)
2649 @result{} 4
2650@end lisp
2651@end deffn
2652
2653\fnumber->string
8f85c0c6
NJ
2654@deffn {Scheme Procedure} number->string n [radix]
2655@deffnx {C Function} scm_number_to_string (n, radix)
780ee65e
NJ
2656Return a string holding the external representation of the
2657number @var{n} in the given @var{radix}. If @var{n} is
2658inexact, a radix of 10 will be used.
2659@end deffn
2660
2661\fstring->number
8f85c0c6
NJ
2662@deffn {Scheme Procedure} string->number string [radix]
2663@deffnx {C Function} scm_string_to_number (string, radix)
ae9f3a15 2664Return a number of the maximally precise representation
780ee65e
NJ
2665expressed by the given @var{string}. @var{radix} must be an
2666exact integer, either 2, 8, 10, or 16. If supplied, @var{radix}
2667is a default radix that may be overridden by an explicit radix
2668prefix in @var{string} (e.g. "#o177"). If @var{radix} is not
2669supplied, then the default radix is 10. If string is not a
2670syntactically valid notation for a number, then
2671@code{string->number} returns @code{#f}.
2672@end deffn
2673
2674\fnumber?
8f85c0c6 2675@deffn {Scheme Procedure} number?
9401323e 2676implemented by the C function "scm_number_p"
780ee65e
NJ
2677@end deffn
2678
2679\fcomplex?
8f85c0c6
NJ
2680@deffn {Scheme Procedure} complex? x
2681@deffnx {C Function} scm_number_p (x)
780ee65e
NJ
2682Return @code{#t} if @var{x} is a complex number, @code{#f}
2683else. Note that the sets of real, rational and integer
2684values form subsets of the set of complex numbers, i. e. the
2685predicate will also be fulfilled if @var{x} is a real,
2686rational or integer number.
2687@end deffn
2688
2689\freal?
8f85c0c6 2690@deffn {Scheme Procedure} real?
9401323e 2691implemented by the C function "scm_real_p"
780ee65e
NJ
2692@end deffn
2693
2694\frational?
8f85c0c6
NJ
2695@deffn {Scheme Procedure} rational? x
2696@deffnx {C Function} scm_real_p (x)
780ee65e
NJ
2697Return @code{#t} if @var{x} is a rational number, @code{#f}
2698else. Note that the set of integer values forms a subset of
2699the set of rational numbers, i. e. the predicate will also be
2700fulfilled if @var{x} is an integer number. Real numbers
2701will also satisfy this predicate, because of their limited
2702precision.
2703@end deffn
2704
2705\finteger?
8f85c0c6
NJ
2706@deffn {Scheme Procedure} integer? x
2707@deffnx {C Function} scm_integer_p (x)
780ee65e
NJ
2708Return @code{#t} if @var{x} is an integer number, @code{#f}
2709else.
2710@end deffn
2711
2712\finexact?
8f85c0c6
NJ
2713@deffn {Scheme Procedure} inexact? x
2714@deffnx {C Function} scm_inexact_p (x)
780ee65e
NJ
2715Return @code{#t} if @var{x} is an inexact number, @code{#f}
2716else.
2717@end deffn
2718
2719\f$expt
8f85c0c6
NJ
2720@deffn {Scheme Procedure} $expt x y
2721@deffnx {C Function} scm_sys_expt (x, y)
780ee65e
NJ
2722Return @var{x} raised to the power of @var{y}. This
2723procedure does not accept complex arguments.
2724@end deffn
2725
2726\f$atan2
8f85c0c6
NJ
2727@deffn {Scheme Procedure} $atan2 x y
2728@deffnx {C Function} scm_sys_atan2 (x, y)
780ee65e
NJ
2729Return the arc tangent of the two arguments @var{x} and
2730@var{y}. This is similar to calculating the arc tangent of
2731@var{x} / @var{y}, except that the signs of both arguments
2732are used to determine the quadrant of the result. This
2733procedure does not accept complex arguments.
2734@end deffn
2735
2736\fmake-rectangular
8f85c0c6
NJ
2737@deffn {Scheme Procedure} make-rectangular real imaginary
2738@deffnx {C Function} scm_make_rectangular (real, imaginary)
780ee65e
NJ
2739Return a complex number constructed of the given @var{real} and
2740@var{imaginary} parts.
2741@end deffn
2742
2743\fmake-polar
8f85c0c6
NJ
2744@deffn {Scheme Procedure} make-polar x y
2745@deffnx {C Function} scm_make_polar (x, y)
780ee65e
NJ
2746Return the complex number @var{x} * e^(i * @var{y}).
2747@end deffn
2748
2749\finexact->exact
8f85c0c6
NJ
2750@deffn {Scheme Procedure} inexact->exact z
2751@deffnx {C Function} scm_inexact_to_exact (z)
ae9f3a15 2752Return an exact number that is numerically closest to @var{z}.
780ee65e
NJ
2753@end deffn
2754
2755\fclass-of
8f85c0c6
NJ
2756@deffn {Scheme Procedure} class-of x
2757@deffnx {C Function} scm_class_of (x)
780ee65e
NJ
2758Return the class of @var{x}.
2759@end deffn
2760
2761\fentity?
8f85c0c6
NJ
2762@deffn {Scheme Procedure} entity? obj
2763@deffnx {C Function} scm_entity_p (obj)
780ee65e
NJ
2764Return @code{#t} if @var{obj} is an entity.
2765@end deffn
2766
2767\foperator?
8f85c0c6
NJ
2768@deffn {Scheme Procedure} operator? obj
2769@deffnx {C Function} scm_operator_p (obj)
780ee65e
NJ
2770Return @code{#t} if @var{obj} is an operator.
2771@end deffn
2772
9401323e 2773\fvalid-object-procedure?
8f85c0c6
NJ
2774@deffn {Scheme Procedure} valid-object-procedure? proc
2775@deffnx {C Function} scm_valid_object_procedure_p (proc)
9401323e
NJ
2776Return @code{#t} iff @var{proc} is a procedure that can be used with @code{set-object-procedure}. It is always valid to use a closure constructed by @code{lambda}.
2777@end deffn
2778
780ee65e 2779\fset-object-procedure!
8f85c0c6
NJ
2780@deffn {Scheme Procedure} set-object-procedure! obj proc
2781@deffnx {C Function} scm_set_object_procedure_x (obj, proc)
9401323e 2782Set the object procedure of @var{obj} to @var{proc}.
780ee65e
NJ
2783@var{obj} must be either an entity or an operator.
2784@end deffn
2785
2786\fmake-class-object
8f85c0c6
NJ
2787@deffn {Scheme Procedure} make-class-object metaclass layout
2788@deffnx {C Function} scm_make_class_object (metaclass, layout)
780ee65e
NJ
2789Create a new class object of class @var{metaclass}, with the
2790slot layout specified by @var{layout}.
2791@end deffn
2792
2793\fmake-subclass-object
8f85c0c6
NJ
2794@deffn {Scheme Procedure} make-subclass-object class layout
2795@deffnx {C Function} scm_make_subclass_object (class, layout)
780ee65e
NJ
2796Create a subclass object of @var{class}, with the slot layout
2797specified by @var{layout}.
2798@end deffn
2799
2800\fobject-properties
8f85c0c6
NJ
2801@deffn {Scheme Procedure} object-properties obj
2802@deffnx {C Function} scm_object_properties (obj)
780ee65e
NJ
2803Return @var{obj}'s property list.
2804@end deffn
2805
2806\fset-object-properties!
8f85c0c6
NJ
2807@deffn {Scheme Procedure} set-object-properties! obj alist
2808@deffnx {C Function} scm_set_object_properties_x (obj, alist)
780ee65e
NJ
2809Set @var{obj}'s property list to @var{alist}.
2810@end deffn
2811
2812\fobject-property
8f85c0c6
NJ
2813@deffn {Scheme Procedure} object-property obj key
2814@deffnx {C Function} scm_object_property (obj, key)
780ee65e
NJ
2815Return the property of @var{obj} with name @var{key}.
2816@end deffn
2817
2818\fset-object-property!
8f85c0c6
NJ
2819@deffn {Scheme Procedure} set-object-property! obj key value
2820@deffnx {C Function} scm_set_object_property_x (obj, key, value)
ae9f3a15
MG
2821In @var{obj}'s property list, set the property named @var{key}
2822to @var{value}.
780ee65e
NJ
2823@end deffn
2824
2825\fcons
8f85c0c6
NJ
2826@deffn {Scheme Procedure} cons x y
2827@deffnx {C Function} scm_cons (x, y)
ae9f3a15
MG
2828Return a newly allocated pair whose car is @var{x} and whose
2829cdr is @var{y}. The pair is guaranteed to be different (in the
2830sense of @code{eq?}) from every previously existing object.
780ee65e
NJ
2831@end deffn
2832
2833\fpair?
8f85c0c6
NJ
2834@deffn {Scheme Procedure} pair? x
2835@deffnx {C Function} scm_pair_p (x)
ae9f3a15
MG
2836Return @code{#t} if @var{x} is a pair; otherwise return
2837@code{#f}.
780ee65e
NJ
2838@end deffn
2839
2840\fset-car!
8f85c0c6
NJ
2841@deffn {Scheme Procedure} set-car! pair value
2842@deffnx {C Function} scm_set_car_x (pair, value)
780ee65e
NJ
2843Stores @var{value} in the car field of @var{pair}. The value returned
2844by @code{set-car!} is unspecified.
2845@end deffn
2846
2847\fset-cdr!
8f85c0c6
NJ
2848@deffn {Scheme Procedure} set-cdr! pair value
2849@deffnx {C Function} scm_set_cdr_x (pair, value)
780ee65e
NJ
2850Stores @var{value} in the cdr field of @var{pair}. The value returned
2851by @code{set-cdr!} is unspecified.
2852@end deffn
2853
2854\fchar-ready?
8f85c0c6
NJ
2855@deffn {Scheme Procedure} char-ready? [port]
2856@deffnx {C Function} scm_char_ready_p (port)
ae9f3a15
MG
2857Return @code{#t} if a character is ready on input @var{port}
2858and return @code{#f} otherwise. If @code{char-ready?} returns
2859@code{#t} then the next @code{read-char} operation on
2860@var{port} is guaranteed not to hang. If @var{port} is a file
2861port at end of file then @code{char-ready?} returns @code{#t}.
780ee65e 2862@footnote{@code{char-ready?} exists to make it possible for a
ae9f3a15
MG
2863program to accept characters from interactive ports without
2864getting stuck waiting for input. Any input editors associated
2865with such ports must make sure that characters whose existence
2866has been asserted by @code{char-ready?} cannot be rubbed out.
2867If @code{char-ready?} were to return @code{#f} at end of file,
2868a port at end of file would be indistinguishable from an
2869interactive port that has no ready characters.}
780ee65e
NJ
2870@end deffn
2871
2872\fdrain-input
8f85c0c6
NJ
2873@deffn {Scheme Procedure} drain-input port
2874@deffnx {C Function} scm_drain_input (port)
9401323e
NJ
2875This procedure clears a port's input buffers, similar
2876to the way that force-output clears the output buffer. The
2877contents of the buffers are returned as a single string, e.g.,
2878
2879@lisp
2880(define p (open-input-file ...))
2881(drain-input p) => empty string, nothing buffered yet.
2882(unread-char (read-char p) p)
2883(drain-input p) => initial chars from p, up to the buffer size.
2884@end lisp
2885
2886Draining the buffers may be useful for cleanly finishing
2887buffered I/O so that the file descriptor can be used directly
2888for further input.
780ee65e
NJ
2889@end deffn
2890
2891\fcurrent-input-port
8f85c0c6
NJ
2892@deffn {Scheme Procedure} current-input-port
2893@deffnx {C Function} scm_current_input_port ()
780ee65e
NJ
2894Return the current input port. This is the default port used
2895by many input procedures. Initially, @code{current-input-port}
2896returns the @dfn{standard input} in Unix and C terminology.
2897@end deffn
2898
2899\fcurrent-output-port
8f85c0c6
NJ
2900@deffn {Scheme Procedure} current-output-port
2901@deffnx {C Function} scm_current_output_port ()
780ee65e
NJ
2902Return the current output port. This is the default port used
2903by many output procedures. Initially,
2904@code{current-output-port} returns the @dfn{standard output} in
2905Unix and C terminology.
2906@end deffn
2907
2908\fcurrent-error-port
8f85c0c6
NJ
2909@deffn {Scheme Procedure} current-error-port
2910@deffnx {C Function} scm_current_error_port ()
780ee65e
NJ
2911Return the port to which errors and warnings should be sent (the
2912@dfn{standard error} in Unix and C terminology).
2913@end deffn
2914
2915\fcurrent-load-port
8f85c0c6
NJ
2916@deffn {Scheme Procedure} current-load-port
2917@deffnx {C Function} scm_current_load_port ()
780ee65e
NJ
2918Return the current-load-port.
2919The load port is used internally by @code{primitive-load}.
2920@end deffn
2921
2922\fset-current-input-port
8f85c0c6
NJ
2923@deffn {Scheme Procedure} set-current-input-port port
2924@deffnx {Scheme Procedure} set-current-output-port port
2925@deffnx {Scheme Procedure} set-current-error-port port
2926@deffnx {C Function} scm_set_current_input_port (port)
780ee65e
NJ
2927Change the ports returned by @code{current-input-port},
2928@code{current-output-port} and @code{current-error-port}, respectively,
2929so that they use the supplied @var{port} for input or output.
2930@end deffn
2931
2932\fset-current-output-port
8f85c0c6
NJ
2933@deffn {Scheme Procedure} set-current-output-port port
2934@deffnx {C Function} scm_set_current_output_port (port)
780ee65e
NJ
2935Set the current default output port to @var{port}.
2936@end deffn
2937
2938\fset-current-error-port
8f85c0c6
NJ
2939@deffn {Scheme Procedure} set-current-error-port port
2940@deffnx {C Function} scm_set_current_error_port (port)
780ee65e
NJ
2941Set the current default error port to @var{port}.
2942@end deffn
2943
2944\fport-revealed
8f85c0c6
NJ
2945@deffn {Scheme Procedure} port-revealed port
2946@deffnx {C Function} scm_port_revealed (port)
ae9f3a15 2947Return the revealed count for @var{port}.
780ee65e
NJ
2948@end deffn
2949
2950\fset-port-revealed!
8f85c0c6
NJ
2951@deffn {Scheme Procedure} set-port-revealed! port rcount
2952@deffnx {C Function} scm_set_port_revealed_x (port, rcount)
780ee65e
NJ
2953Sets the revealed count for a port to a given value.
2954The return value is unspecified.
2955@end deffn
2956
2957\fport-mode
8f85c0c6
NJ
2958@deffn {Scheme Procedure} port-mode port
2959@deffnx {C Function} scm_port_mode (port)
ae9f3a15
MG
2960Return the port modes associated with the open port @var{port}.
2961These will not necessarily be identical to the modes used when
2962the port was opened, since modes such as "append" which are
2963used only during port creation are not retained.
780ee65e
NJ
2964@end deffn
2965
2966\fclose-port
8f85c0c6
NJ
2967@deffn {Scheme Procedure} close-port port
2968@deffnx {C Function} scm_close_port (port)
ae9f3a15
MG
2969Close the specified port object. Return @code{#t} if it
2970successfully closes a port or @code{#f} if it was already
2971closed. An exception may be raised if an error occurs, for
2972example when flushing buffered output. See also @ref{Ports and
2973File Descriptors, close}, for a procedure which can close file
2974descriptors.
780ee65e
NJ
2975@end deffn
2976
2977\fclose-input-port
8f85c0c6
NJ
2978@deffn {Scheme Procedure} close-input-port port
2979@deffnx {C Function} scm_close_input_port (port)
780ee65e
NJ
2980Close the specified input port object. The routine has no effect if
2981the file has already been closed. An exception may be raised if an
2982error occurs. The value returned is unspecified.
2983
2984See also @ref{Ports and File Descriptors, close}, for a procedure
2985which can close file descriptors.
2986@end deffn
2987
2988\fclose-output-port
8f85c0c6
NJ
2989@deffn {Scheme Procedure} close-output-port port
2990@deffnx {C Function} scm_close_output_port (port)
780ee65e
NJ
2991Close the specified output port object. The routine has no effect if
2992the file has already been closed. An exception may be raised if an
2993error occurs. The value returned is unspecified.
2994
2995See also @ref{Ports and File Descriptors, close}, for a procedure
2996which can close file descriptors.
2997@end deffn
2998
2999\fport-for-each
8f85c0c6
NJ
3000@deffn {Scheme Procedure} port-for-each proc
3001@deffnx {C Function} scm_port_for_each (proc)
780ee65e
NJ
3002Apply @var{proc} to each port in the Guile port table
3003in turn. The return value is unspecified. More specifically,
3004@var{proc} is applied exactly once to every port that exists
3005in the system at the time @var{port-for-each} is invoked.
3006Changes to the port table while @var{port-for-each} is running
3007have no effect as far as @var{port-for-each} is concerned.
3008@end deffn
3009
780ee65e 3010\finput-port?
8f85c0c6
NJ
3011@deffn {Scheme Procedure} input-port? x
3012@deffnx {C Function} scm_input_port_p (x)
ae9f3a15 3013Return @code{#t} if @var{x} is an input port, otherwise return
780ee65e
NJ
3014@code{#f}. Any object satisfying this predicate also satisfies
3015@code{port?}.
3016@end deffn
3017
3018\foutput-port?
8f85c0c6
NJ
3019@deffn {Scheme Procedure} output-port? x
3020@deffnx {C Function} scm_output_port_p (x)
ae9f3a15 3021Return @code{#t} if @var{x} is an output port, otherwise return
780ee65e
NJ
3022@code{#f}. Any object satisfying this predicate also satisfies
3023@code{port?}.
3024@end deffn
3025
3026\fport?
8f85c0c6
NJ
3027@deffn {Scheme Procedure} port? x
3028@deffnx {C Function} scm_port_p (x)
ae9f3a15 3029Return a boolean indicating whether @var{x} is a port.
780ee65e
NJ
3030Equivalent to @code{(or (input-port? @var{x}) (output-port?
3031@var{x}))}.
3032@end deffn
3033
3034\fport-closed?
8f85c0c6
NJ
3035@deffn {Scheme Procedure} port-closed? port
3036@deffnx {C Function} scm_port_closed_p (port)
ae9f3a15
MG
3037Return @code{#t} if @var{port} is closed or @code{#f} if it is
3038open.
780ee65e
NJ
3039@end deffn
3040
3041\feof-object?
8f85c0c6
NJ
3042@deffn {Scheme Procedure} eof-object? x
3043@deffnx {C Function} scm_eof_object_p (x)
ae9f3a15
MG
3044Return @code{#t} if @var{x} is an end-of-file object; otherwise
3045return @code{#f}.
780ee65e
NJ
3046@end deffn
3047
3048\fforce-output
8f85c0c6
NJ
3049@deffn {Scheme Procedure} force-output [port]
3050@deffnx {C Function} scm_force_output (port)
780ee65e
NJ
3051Flush the specified output port, or the current output port if @var{port}
3052is omitted. The current output buffer contents are passed to the
3053underlying port implementation (e.g., in the case of fports, the
3054data will be written to the file and the output buffer will be cleared.)
3055It has no effect on an unbuffered port.
3056
3057The return value is unspecified.
3058@end deffn
3059
3060\fflush-all-ports
8f85c0c6
NJ
3061@deffn {Scheme Procedure} flush-all-ports
3062@deffnx {C Function} scm_flush_all_ports ()
780ee65e
NJ
3063Equivalent to calling @code{force-output} on
3064all open output ports. The return value is unspecified.
3065@end deffn
3066
3067\fread-char
8f85c0c6
NJ
3068@deffn {Scheme Procedure} read-char [port]
3069@deffnx {C Function} scm_read_char (port)
ae9f3a15 3070Return the next character available from @var{port}, updating
780ee65e 3071@var{port} to point to the following character. If no more
ae9f3a15 3072characters are available, the end-of-file object is returned.
780ee65e
NJ
3073@end deffn
3074
3075\fpeek-char
8f85c0c6
NJ
3076@deffn {Scheme Procedure} peek-char [port]
3077@deffnx {C Function} scm_peek_char (port)
ae9f3a15 3078Return the next character available from @var{port},
780ee65e 3079@emph{without} updating @var{port} to point to the following
ae9f3a15
MG
3080character. If no more characters are available, the
3081end-of-file object is returned.@footnote{The value returned by
3082a call to @code{peek-char} is the same as the value that would
3083have been returned by a call to @code{read-char} on the same
3084port. The only difference is that the very next call to
3085@code{read-char} or @code{peek-char} on that @var{port} will
3086return the value returned by the preceding call to
3087@code{peek-char}. In particular, a call to @code{peek-char} on
3088an interactive port will hang waiting for input whenever a call
3089to @code{read-char} would have hung.}
780ee65e
NJ
3090@end deffn
3091
3092\funread-char
8f85c0c6
NJ
3093@deffn {Scheme Procedure} unread-char cobj [port]
3094@deffnx {C Function} scm_unread_char (cobj, port)
780ee65e
NJ
3095Place @var{char} in @var{port} so that it will be read by the
3096next read operation. If called multiple times, the unread characters
3097will be read again in last-in first-out order. If @var{port} is
3098not supplied, the current input port is used.
3099@end deffn
3100
3101\funread-string
8f85c0c6
NJ
3102@deffn {Scheme Procedure} unread-string str port
3103@deffnx {C Function} scm_unread_string (str, port)
780ee65e
NJ
3104Place the string @var{str} in @var{port} so that its characters will be
3105read in subsequent read operations. If called multiple times, the
3106unread characters will be read again in last-in first-out order. If
3107@var{port} is not supplied, the current-input-port is used.
3108@end deffn
3109
3110\fseek
8f85c0c6
NJ
3111@deffn {Scheme Procedure} seek fd_port offset whence
3112@deffnx {C Function} scm_seek (fd_port, offset, whence)
ae9f3a15
MG
3113Sets the current position of @var{fd/port} to the integer
3114@var{offset}, which is interpreted according to the value of
3115@var{whence}.
7a095584 3116
ae9f3a15
MG
3117One of the following variables should be supplied for
3118@var{whence}:
780ee65e
NJ
3119@defvar SEEK_SET
3120Seek from the beginning of the file.
3121@end defvar
3122@defvar SEEK_CUR
3123Seek from the current position.
3124@end defvar
3125@defvar SEEK_END
3126Seek from the end of the file.
3127@end defvar
ae9f3a15
MG
3128If @var{fd/port} is a file descriptor, the underlying system
3129call is @code{lseek}. @var{port} may be a string port.
7a095584 3130
ae9f3a15
MG
3131The value returned is the new position in the file. This means
3132that the current position of a port can be obtained using:
3133@lisp
780ee65e 3134(seek port 0 SEEK_CUR)
ae9f3a15 3135@end lisp
780ee65e
NJ
3136@end deffn
3137
3138\ftruncate-file
8f85c0c6
NJ
3139@deffn {Scheme Procedure} truncate-file object [length]
3140@deffnx {C Function} scm_truncate_file (object, length)
ae9f3a15
MG
3141Truncates the object referred to by @var{object} to at most
3142@var{length} bytes. @var{object} can be a string containing a
3143file name or an integer file descriptor or a port.
3144@var{length} may be omitted if @var{object} is not a file name,
3145in which case the truncation occurs at the current port.
3146position. The return value is unspecified.
780ee65e
NJ
3147@end deffn
3148
3149\fport-line
8f85c0c6
NJ
3150@deffn {Scheme Procedure} port-line port
3151@deffnx {C Function} scm_port_line (port)
780ee65e
NJ
3152Return the current line number for @var{port}.
3153@end deffn
3154
3155\fset-port-line!
8f85c0c6
NJ
3156@deffn {Scheme Procedure} set-port-line! port line
3157@deffnx {C Function} scm_set_port_line_x (port, line)
780ee65e
NJ
3158Set the current line number for @var{port} to @var{line}.
3159@end deffn
3160
3161\fport-column
8f85c0c6
NJ
3162@deffn {Scheme Procedure} port-column port
3163@deffnx {Scheme Procedure} port-line port
3164@deffnx {C Function} scm_port_column (port)
780ee65e
NJ
3165Return the current column number or line number of @var{port},
3166using the current input port if none is specified. If the number is
3167unknown, the result is #f. Otherwise, the result is a 0-origin integer
3168- i.e. the first character of the first line is line 0, column 0.
3169(However, when you display a file position, for example in an error
3170message, we recommend you add 1 to get 1-origin integers. This is
3171because lines and column numbers traditionally start with 1, and that is
3172what non-programmers will find most natural.)
3173@end deffn
3174
3175\fset-port-column!
8f85c0c6
NJ
3176@deffn {Scheme Procedure} set-port-column! port column
3177@deffnx {Scheme Procedure} set-port-line! port line
3178@deffnx {C Function} scm_set_port_column_x (port, column)
780ee65e
NJ
3179Set the current column or line number of @var{port}, using the
3180current input port if none is specified.
3181@end deffn
3182
3183\fport-filename
8f85c0c6
NJ
3184@deffn {Scheme Procedure} port-filename port
3185@deffnx {C Function} scm_port_filename (port)
780ee65e
NJ
3186Return the filename associated with @var{port}. This function returns
3187the strings "standard input", "standard output" and "standard error"
3188when called on the current input, output and error ports respectively.
3189@end deffn
3190
3191\fset-port-filename!
8f85c0c6
NJ
3192@deffn {Scheme Procedure} set-port-filename! port filename
3193@deffnx {C Function} scm_set_port_filename_x (port, filename)
780ee65e
NJ
3194Change the filename associated with @var{port}, using the current input
3195port if none is specified. Note that this does not change the port's
3196source of data, but only the value that is returned by
3197@code{port-filename} and reported in diagnostic output.
3198@end deffn
3199
3200\f%make-void-port
8f85c0c6
NJ
3201@deffn {Scheme Procedure} %make-void-port mode
3202@deffnx {C Function} scm_sys_make_void_port (mode)
780ee65e
NJ
3203Create and return a new void port. A void port acts like
3204/dev/null. The @var{mode} argument
3205specifies the input/output modes for this port: see the
3206documentation for @code{open-file} in @ref{File Ports}.
3207@end deffn
3208
9401323e 3209\fprint-options-interface
8f85c0c6
NJ
3210@deffn {Scheme Procedure} print-options-interface [setting]
3211@deffnx {C Function} scm_print_options (setting)
9401323e
NJ
3212Option interface for the print options. Instead of using
3213this procedure directly, use the procedures
3214@code{print-enable}, @code{print-disable}, @code{print-set!}
3215and @code{print-options}.
3216@end deffn
7a095584 3217
9401323e 3218\fsimple-format
8f85c0c6
NJ
3219@deffn {Scheme Procedure} simple-format destination message . args
3220@deffnx {C Function} scm_simple_format (destination, message, args)
9401323e
NJ
3221Write @var{message} to @var{destination}, defaulting to
3222the current output port.
3223@var{message} can contain @code{~A} (was @code{%s}) and
3224@code{~S} (was @code{%S}) escapes. When printed,
3225the escapes are replaced with corresponding members of
3226@var{ARGS}:
3227@code{~A} formats using @code{display} and @code{~S} formats
3228using @code{write}.
3229If @var{destination} is @code{#t}, then use the current output
3230port, if @var{destination} is @code{#f}, then return a string
3231containing the formatted text. Does not add a trailing newline.
780ee65e
NJ
3232@end deffn
3233
9401323e 3234\fnewline
8f85c0c6
NJ
3235@deffn {Scheme Procedure} newline [port]
3236@deffnx {C Function} scm_newline (port)
9401323e 3237Send a newline to @var{port}.
8f85c0c6 3238If @var{port} is omitted, send to the current output port.
780ee65e
NJ
3239@end deffn
3240
9401323e 3241\fwrite-char
8f85c0c6
NJ
3242@deffn {Scheme Procedure} write-char chr [port]
3243@deffnx {C Function} scm_write_char (chr, port)
9401323e 3244Send character @var{chr} to @var{port}.
780ee65e
NJ
3245@end deffn
3246
9401323e 3247\fport-with-print-state
8f85c0c6
NJ
3248@deffn {Scheme Procedure} port-with-print-state port pstate
3249@deffnx {C Function} scm_port_with_print_state (port, pstate)
9401323e
NJ
3250Create a new port which behaves like @var{port}, but with an
3251included print state @var{pstate}.
780ee65e
NJ
3252@end deffn
3253
9401323e 3254\fget-print-state
8f85c0c6
NJ
3255@deffn {Scheme Procedure} get-print-state port
3256@deffnx {C Function} scm_get_print_state (port)
9401323e
NJ
3257Return the print state of the port @var{port}. If @var{port}
3258has no associated print state, @code{#f} is returned.
780ee65e
NJ
3259@end deffn
3260
9401323e 3261\fprocedure-properties
8f85c0c6
NJ
3262@deffn {Scheme Procedure} procedure-properties proc
3263@deffnx {C Function} scm_procedure_properties (proc)
9401323e 3264Return @var{obj}'s property list.
780ee65e
NJ
3265@end deffn
3266
9401323e 3267\fset-procedure-properties!
8f85c0c6
NJ
3268@deffn {Scheme Procedure} set-procedure-properties! proc new_val
3269@deffnx {C Function} scm_set_procedure_properties_x (proc, new_val)
9401323e
NJ
3270Set @var{obj}'s property list to @var{alist}.
3271@end deffn
780ee65e 3272
9401323e 3273\fprocedure-property
8f85c0c6
NJ
3274@deffn {Scheme Procedure} procedure-property p k
3275@deffnx {C Function} scm_procedure_property (p, k)
9401323e
NJ
3276Return the property of @var{obj} with name @var{key}.
3277@end deffn
780ee65e 3278
9401323e 3279\fset-procedure-property!
8f85c0c6
NJ
3280@deffn {Scheme Procedure} set-procedure-property! p k v
3281@deffnx {C Function} scm_set_procedure_property_x (p, k, v)
9401323e
NJ
3282In @var{obj}'s property list, set the property named @var{key} to
3283@var{value}.
3284@end deffn
780ee65e 3285
9401323e 3286\fprocedure?
8f85c0c6
NJ
3287@deffn {Scheme Procedure} procedure? obj
3288@deffnx {C Function} scm_procedure_p (obj)
9401323e
NJ
3289Return @code{#t} if @var{obj} is a procedure.
3290@end deffn
780ee65e 3291
9401323e 3292\fclosure?
8f85c0c6
NJ
3293@deffn {Scheme Procedure} closure? obj
3294@deffnx {C Function} scm_closure_p (obj)
9401323e
NJ
3295Return @code{#t} if @var{obj} is a closure.
3296@end deffn
780ee65e 3297
9401323e 3298\fthunk?
8f85c0c6
NJ
3299@deffn {Scheme Procedure} thunk? obj
3300@deffnx {C Function} scm_thunk_p (obj)
9401323e 3301Return @code{#t} if @var{obj} is a thunk.
780ee65e
NJ
3302@end deffn
3303
9401323e 3304\fprocedure-documentation
8f85c0c6
NJ
3305@deffn {Scheme Procedure} procedure-documentation proc
3306@deffnx {C Function} scm_procedure_documentation (proc)
9401323e
NJ
3307Return the documentation string associated with @code{proc}. By
3308convention, if a procedure contains more than one expression and the
3309first expression is a string constant, that string is assumed to contain
3310documentation for that procedure.
3311@end deffn
780ee65e 3312
9401323e 3313\fprocedure-with-setter?
8f85c0c6
NJ
3314@deffn {Scheme Procedure} procedure-with-setter? obj
3315@deffnx {C Function} scm_procedure_with_setter_p (obj)
9401323e
NJ
3316Return @code{#t} if @var{obj} is a procedure with an
3317associated setter procedure.
3318@end deffn
780ee65e 3319
9401323e 3320\fmake-procedure-with-setter
8f85c0c6
NJ
3321@deffn {Scheme Procedure} make-procedure-with-setter procedure setter
3322@deffnx {C Function} scm_make_procedure_with_setter (procedure, setter)
9401323e
NJ
3323Create a new procedure which behaves like @var{procedure}, but
3324with the associated setter @var{setter}.
3325@end deffn
780ee65e 3326
9401323e 3327\fprocedure
8f85c0c6
NJ
3328@deffn {Scheme Procedure} procedure proc
3329@deffnx {C Function} scm_procedure (proc)
9401323e
NJ
3330Return the procedure of @var{proc}, which must be either a
3331procedure with setter, or an operator struct.
3332@end deffn
780ee65e 3333
9401323e 3334\fprimitive-make-property
8f85c0c6
NJ
3335@deffn {Scheme Procedure} primitive-make-property not_found_proc
3336@deffnx {C Function} scm_primitive_make_property (not_found_proc)
9401323e
NJ
3337Create a @dfn{property token} that can be used with
3338@code{primitive-property-ref} and @code{primitive-property-set!}.
3339See @code{primitive-property-ref} for the significance of
3340@var{not_found_proc}.
3341@end deffn
780ee65e 3342
9401323e 3343\fprimitive-property-ref
8f85c0c6
NJ
3344@deffn {Scheme Procedure} primitive-property-ref prop obj
3345@deffnx {C Function} scm_primitive_property_ref (prop, obj)
9401323e
NJ
3346Return the property @var{prop} of @var{obj}. When no value
3347has yet been associated with @var{prop} and @var{obj}, call
3348@var{not-found-proc} instead (see @code{primitive-make-property})
3349and use its return value. That value is also associated with
3350@var{obj} via @code{primitive-property-set!}. When
3351@var{not-found-proc} is @code{#f}, use @code{#f} as the
3352default value of @var{prop}.
780ee65e
NJ
3353@end deffn
3354
9401323e 3355\fprimitive-property-set!
8f85c0c6
NJ
3356@deffn {Scheme Procedure} primitive-property-set! prop obj val
3357@deffnx {C Function} scm_primitive_property_set_x (prop, obj, val)
9401323e 3358Associate @var{code} with @var{prop} and @var{obj}.
780ee65e
NJ
3359@end deffn
3360
9401323e 3361\fprimitive-property-del!
8f85c0c6
NJ
3362@deffn {Scheme Procedure} primitive-property-del! prop obj
3363@deffnx {C Function} scm_primitive_property_del_x (prop, obj)
9401323e 3364Remove any value associated with @var{prop} and @var{obj}.
780ee65e
NJ
3365@end deffn
3366
9401323e 3367\frandom
8f85c0c6
NJ
3368@deffn {Scheme Procedure} random n [state]
3369@deffnx {C Function} scm_random (n, state)
9401323e 3370Return a number in [0,N).
780ee65e 3371
9401323e
NJ
3372Accepts a positive integer or real n and returns a
3373number of the same type between zero (inclusive) and
3374N (exclusive). The values returned have a uniform
3375distribution.
780ee65e 3376
9401323e
NJ
3377The optional argument @var{state} must be of the type produced
3378by @code{seed->random-state}. It defaults to the value of the
3379variable @var{*random-state*}. This object is used to maintain
3380the state of the pseudo-random-number generator and is altered
3381as a side effect of the random operation.
780ee65e
NJ
3382@end deffn
3383
9401323e 3384\fcopy-random-state
8f85c0c6
NJ
3385@deffn {Scheme Procedure} copy-random-state [state]
3386@deffnx {C Function} scm_copy_random_state (state)
9401323e 3387Return a copy of the random state @var{state}.
780ee65e
NJ
3388@end deffn
3389
9401323e 3390\fseed->random-state
8f85c0c6
NJ
3391@deffn {Scheme Procedure} seed->random-state seed
3392@deffnx {C Function} scm_seed_to_random_state (seed)
9401323e 3393Return a new random state using @var{seed}.
780ee65e
NJ
3394@end deffn
3395
9401323e 3396\frandom:uniform
8f85c0c6
NJ
3397@deffn {Scheme Procedure} random:uniform [state]
3398@deffnx {C Function} scm_random_uniform (state)
9401323e
NJ
3399Return a uniformly distributed inexact real random number in
3400[0,1).
780ee65e
NJ
3401@end deffn
3402
9401323e 3403\frandom:normal
8f85c0c6
NJ
3404@deffn {Scheme Procedure} random:normal [state]
3405@deffnx {C Function} scm_random_normal (state)
9401323e
NJ
3406Return an inexact real in a normal distribution. The
3407distribution used has mean 0 and standard deviation 1. For a
3408normal distribution with mean m and standard deviation d use
3409@code{(+ m (* d (random:normal)))}.
780ee65e
NJ
3410@end deffn
3411
9401323e 3412\frandom:solid-sphere!
8f85c0c6
NJ
3413@deffn {Scheme Procedure} random:solid-sphere! v [state]
3414@deffnx {C Function} scm_random_solid_sphere_x (v, state)
9401323e
NJ
3415Fills vect with inexact real random numbers
3416the sum of whose squares is less than 1.0.
3417Thinking of vect as coordinates in space of
3418dimension n = (vector-length vect), the coordinates
72dd0a03 3419are uniformly distributed within the unit n-sphere.
9401323e 3420The sum of the squares of the numbers is returned.
780ee65e
NJ
3421@end deffn
3422
9401323e 3423\frandom:hollow-sphere!
8f85c0c6
NJ
3424@deffn {Scheme Procedure} random:hollow-sphere! v [state]
3425@deffnx {C Function} scm_random_hollow_sphere_x (v, state)
9401323e
NJ
3426Fills vect with inexact real random numbers
3427the sum of whose squares is equal to 1.0.
3428Thinking of vect as coordinates in space of
3429dimension n = (vector-length vect), the coordinates
3430are uniformly distributed over the surface of the
72dd0a03 3431unit n-sphere.
780ee65e
NJ
3432@end deffn
3433
9401323e 3434\frandom:normal-vector!
8f85c0c6
NJ
3435@deffn {Scheme Procedure} random:normal-vector! v [state]
3436@deffnx {C Function} scm_random_normal_vector_x (v, state)
9401323e
NJ
3437Fills vect with inexact real random numbers that are
3438independent and standard normally distributed
3439(i.e., with mean 0 and variance 1).
780ee65e
NJ
3440@end deffn
3441
9401323e 3442\frandom:exp
8f85c0c6
NJ
3443@deffn {Scheme Procedure} random:exp [state]
3444@deffnx {C Function} scm_random_exp (state)
9401323e
NJ
3445Return an inexact real in an exponential distribution with mean
34461. For an exponential distribution with mean u use (* u
3447(random:exp)).
780ee65e
NJ
3448@end deffn
3449
9401323e 3450\f%read-delimited!
8f85c0c6
NJ
3451@deffn {Scheme Procedure} %read-delimited! delims str gobble [port [start [end]]]
3452@deffnx {C Function} scm_read_delimited_x (delims, str, gobble, port, start, end)
9401323e
NJ
3453Read characters from @var{port} into @var{str} until one of the
3454characters in the @var{delims} string is encountered. If
3455@var{gobble} is true, discard the delimiter character;
3456otherwise, leave it in the input stream for the next read. If
3457@var{port} is not specified, use the value of
3458@code{(current-input-port)}. If @var{start} or @var{end} are
3459specified, store data only into the substring of @var{str}
3460bounded by @var{start} and @var{end} (which default to the
3461beginning and end of the string, respectively).
780ee65e 3462
9401323e
NJ
3463 Return a pair consisting of the delimiter that terminated the
3464string and the number of characters read. If reading stopped
3465at the end of file, the delimiter returned is the
3466@var{eof-object}; if the string was filled without encountering
3467a delimiter, this value is @code{#f}.
780ee65e
NJ
3468@end deffn
3469
9401323e 3470\f%read-line
8f85c0c6
NJ
3471@deffn {Scheme Procedure} %read-line [port]
3472@deffnx {C Function} scm_read_line (port)
9401323e
NJ
3473Read a newline-terminated line from @var{port}, allocating storage as
3474necessary. The newline terminator (if any) is removed from the string,
3475and a pair consisting of the line and its delimiter is returned. The
3476delimiter may be either a newline or the @var{eof-object}; if
3477@code{%read-line} is called at the end of file, it returns the pair
3478@code{(#<eof> . #<eof>)}.
780ee65e
NJ
3479@end deffn
3480
9401323e 3481\fwrite-line
8f85c0c6
NJ
3482@deffn {Scheme Procedure} write-line obj [port]
3483@deffnx {C Function} scm_write_line (obj, port)
9401323e
NJ
3484Display @var{obj} and a newline character to @var{port}. If
3485@var{port} is not specified, @code{(current-output-port)} is
3486used. This function is equivalent to:
3487@lisp
3488(display obj [port])
3489(newline [port])
3490@end lisp
780ee65e
NJ
3491@end deffn
3492
9401323e 3493\fread-options-interface
8f85c0c6
NJ
3494@deffn {Scheme Procedure} read-options-interface [setting]
3495@deffnx {C Function} scm_read_options (setting)
9401323e
NJ
3496Option interface for the read options. Instead of using
3497this procedure directly, use the procedures @code{read-enable},
3498@code{read-disable}, @code{read-set!} and @var{read-options}.
780ee65e
NJ
3499@end deffn
3500
9401323e 3501\fread
8f85c0c6
NJ
3502@deffn {Scheme Procedure} read [port]
3503@deffnx {C Function} scm_read (port)
9401323e
NJ
3504Read an s-expression from the input port @var{port}, or from
3505the current input port if @var{port} is not specified.
3506Any whitespace before the next token is discarded.
780ee65e
NJ
3507@end deffn
3508
9401323e 3509\fread-hash-extend
8f85c0c6
NJ
3510@deffn {Scheme Procedure} read-hash-extend chr proc
3511@deffnx {C Function} scm_read_hash_extend (chr, proc)
9401323e
NJ
3512Install the procedure @var{proc} for reading expressions
3513starting with the character sequence @code{#} and @var{chr}.
3514@var{proc} will be called with two arguments: the character
3515@var{chr} and the port to read further data from. The object
3516returned will be the return value of @code{read}.
780ee65e
NJ
3517@end deffn
3518
9401323e 3519\fcall-with-dynamic-root
8f85c0c6
NJ
3520@deffn {Scheme Procedure} call-with-dynamic-root thunk handler
3521@deffnx {C Function} scm_call_with_dynamic_root (thunk, handler)
9401323e 3522Evaluate @code{(thunk)} in a new dynamic context, returning its value.
780ee65e 3523
9401323e
NJ
3524If an error occurs during evaluation, apply @var{handler} to the
3525arguments to the throw, just as @code{throw} would. If this happens,
3526@var{handler} is called outside the scope of the new root -- it is
3527called in the same dynamic context in which
3528@code{call-with-dynamic-root} was evaluated.
780ee65e 3529
9401323e
NJ
3530If @var{thunk} captures a continuation, the continuation is rooted at
3531the call to @var{thunk}. In particular, the call to
3532@code{call-with-dynamic-root} is not captured. Therefore,
3533@code{call-with-dynamic-root} always returns at most one time.
780ee65e 3534
9401323e
NJ
3535Before calling @var{thunk}, the dynamic-wind chain is un-wound back to
3536the root and a new chain started for @var{thunk}. Therefore, this call
3537may not do what you expect:
780ee65e 3538
9401323e
NJ
3539@lisp
3540;; Almost certainly a bug:
3541(with-output-to-port
3542 some-port
780ee65e 3543
9401323e
NJ
3544 (lambda ()
3545 (call-with-dynamic-root
3546 (lambda ()
3547 (display 'fnord)
3548 (newline))
3549 (lambda (errcode) errcode))))
3550@end lisp
780ee65e 3551
9401323e
NJ
3552The problem is, on what port will @samp{fnord} be displayed? You
3553might expect that because of the @code{with-output-to-port} that
3554it will be displayed on the port bound to @code{some-port}. But it
3555probably won't -- before evaluating the thunk, dynamic winds are
3556unwound, including those created by @code{with-output-to-port}.
3557So, the standard output port will have been re-set to its default value
3558before @code{display} is evaluated.
780ee65e 3559
9401323e
NJ
3560(This function was added to Guile mostly to help calls to functions in C
3561libraries that can not tolerate non-local exits or calls that return
3562multiple times. If such functions call back to the interpreter, it should
3563be under a new dynamic root.)
780ee65e
NJ
3564@end deffn
3565
9401323e 3566\fdynamic-root
8f85c0c6
NJ
3567@deffn {Scheme Procedure} dynamic-root
3568@deffnx {C Function} scm_dynamic_root ()
9401323e
NJ
3569Return an object representing the current dynamic root.
3570
3571These objects are only useful for comparison using @code{eq?}.
3572They are currently represented as numbers, but your code should
3573in no way depend on this.
780ee65e
NJ
3574@end deffn
3575
9401323e 3576\fread-string!/partial
8f85c0c6
NJ
3577@deffn {Scheme Procedure} read-string!/partial str [port_or_fdes [start [end]]]
3578@deffnx {C Function} scm_read_string_x_partial (str, port_or_fdes, start, end)
9401323e
NJ
3579Read characters from a port or file descriptor into a
3580string @var{str}. A port must have an underlying file
3581descriptor --- a so-called fport. This procedure is
3582scsh-compatible and can efficiently read large strings.
3583It will:
3584
3585@itemize
3586@item
3587attempt to fill the entire string, unless the @var{start}
3588and/or @var{end} arguments are supplied. i.e., @var{start}
3589defaults to 0 and @var{end} defaults to
3590@code{(string-length str)}
3591@item
3592use the current input port if @var{port_or_fdes} is not
3593supplied.
3594@item
3595return fewer than the requested number of characters in some
3596cases, e.g., on end of file, if interrupted by a signal, or if
3597not all the characters are immediately available.
3598@item
3599wait indefinitely for some input if no characters are
3600currently available,
3601unless the port is in non-blocking mode.
3602@item
3603read characters from the port's input buffers if available,
3604instead from the underlying file descriptor.
3605@item
3606return @code{#f} if end-of-file is encountered before reading
3607any characters, otherwise return the number of characters
3608read.
3609@item
3610return 0 if the port is in non-blocking mode and no characters
3611are immediately available.
3612@item
3613return 0 if the request is for 0 bytes, with no
3614end-of-file check.
3615@end itemize
780ee65e
NJ
3616@end deffn
3617
9401323e 3618\fwrite-string/partial
8f85c0c6
NJ
3619@deffn {Scheme Procedure} write-string/partial str [port_or_fdes [start [end]]]
3620@deffnx {C Function} scm_write_string_partial (str, port_or_fdes, start, end)
9401323e
NJ
3621Write characters from a string @var{str} to a port or file
3622descriptor. A port must have an underlying file descriptor
3623--- a so-called fport. This procedure is
3624scsh-compatible and can efficiently write large strings.
3625It will:
3626
3627@itemize
3628@item
3629attempt to write the entire string, unless the @var{start}
3630and/or @var{end} arguments are supplied. i.e., @var{start}
3631defaults to 0 and @var{end} defaults to
3632@code{(string-length str)}
3633@item
3634use the current output port if @var{port_of_fdes} is not
3635supplied.
3636@item
3637in the case of a buffered port, store the characters in the
3638port's output buffer, if all will fit. If they will not fit
3639then any existing buffered characters will be flushed
3640before attempting
3641to write the new characters directly to the underlying file
3642descriptor. If the port is in non-blocking mode and
3643buffered characters can not be flushed immediately, then an
3644@code{EAGAIN} system-error exception will be raised (Note:
3645scsh does not support the use of non-blocking buffered ports.)
3646@item
3647write fewer than the requested number of
3648characters in some cases, e.g., if interrupted by a signal or
3649if not all of the output can be accepted immediately.
3650@item
3651wait indefinitely for at least one character
3652from @var{str} to be accepted by the port, unless the port is
3653in non-blocking mode.
3654@item
3655return the number of characters accepted by the port.
3656@item
3657return 0 if the port is in non-blocking mode and can not accept
3658at least one character from @var{str} immediately
3659@item
3660return 0 immediately if the request size is 0 bytes.
3661@end itemize
780ee65e
NJ
3662@end deffn
3663
9401323e 3664\fsigaction
8f85c0c6
NJ
3665@deffn {Scheme Procedure} sigaction signum [handler [flags]]
3666@deffnx {C Function} scm_sigaction (signum, handler, flags)
9401323e 3667Install or report the signal handler for a specified signal.
7a095584 3668
9401323e
NJ
3669@var{signum} is the signal number, which can be specified using the value
3670of variables such as @code{SIGINT}.
7a095584 3671
9401323e
NJ
3672If @var{action} is omitted, @code{sigaction} returns a pair: the
3673CAR is the current
3674signal hander, which will be either an integer with the value @code{SIG_DFL}
3675(default action) or @code{SIG_IGN} (ignore), or the Scheme procedure which
3676handles the signal, or @code{#f} if a non-Scheme procedure handles the
3677signal. The CDR contains the current @code{sigaction} flags for the handler.
780ee65e 3678
9401323e
NJ
3679If @var{action} is provided, it is installed as the new handler for
3680@var{signum}. @var{action} can be a Scheme procedure taking one
3681argument, or the value of @code{SIG_DFL} (default action) or
3682@code{SIG_IGN} (ignore), or @code{#f} to restore whatever signal handler
3683was installed before @code{sigaction} was first used. Flags can
3684optionally be specified for the new handler (@code{SA_RESTART} will
3685always be added if it's available and the system is using restartable
3686system calls.) The return value is a pair with information about the
3687old handler as described above.
3688
3689This interface does not provide access to the "signal blocking"
3690facility. Maybe this is not needed, since the thread support may
3691provide solutions to the problem of consistent access to data
3692structures.
780ee65e
NJ
3693@end deffn
3694
9401323e 3695\frestore-signals
8f85c0c6
NJ
3696@deffn {Scheme Procedure} restore-signals
3697@deffnx {C Function} scm_restore_signals ()
9401323e
NJ
3698Return all signal handlers to the values they had before any call to
3699@code{sigaction} was made. The return value is unspecified.
3700@end deffn
780ee65e 3701
9401323e 3702\falarm
8f85c0c6
NJ
3703@deffn {Scheme Procedure} alarm i
3704@deffnx {C Function} scm_alarm (i)
9401323e
NJ
3705Set a timer to raise a @code{SIGALRM} signal after the specified
3706number of seconds (an integer). It's advisable to install a signal
3707handler for
3708@code{SIGALRM} beforehand, since the default action is to terminate
3709the process.
780ee65e 3710
9401323e
NJ
3711The return value indicates the time remaining for the previous alarm,
3712if any. The new value replaces the previous alarm. If there was
3713no previous alarm, the return value is zero.
780ee65e
NJ
3714@end deffn
3715
9401323e 3716\fsetitimer
8f85c0c6
NJ
3717@deffn {Scheme Procedure} setitimer which_timer interval_seconds interval_microseconds value_seconds value_microseconds
3718@deffnx {C Function} scm_setitimer (which_timer, interval_seconds, interval_microseconds, value_seconds, value_microseconds)
9401323e
NJ
3719Set the timer specified by @var{which_timer} according to the given
3720@var{interval_seconds}, @var{interval_microseconds},
3721@var{value_seconds}, and @var{value_microseconds} values.
7a095584 3722
9401323e
NJ
3723Return information about the timer's previous setting.
3724Errors are handled as described in the guile info pages under ``POSIX
3725Interface Conventions''.
3726
3727The timers available are: @code{ITIMER_REAL}, @code{ITIMER_VIRTUAL},
3728and @code{ITIMER_PROF}.
3729
3730The return value will be a list of two cons pairs representing the
3731current state of the given timer. The first pair is the seconds and
3732microseconds of the timer @code{it_interval}, and the second pair is
3733the seconds and microseconds of the timer @code{it_value}.
780ee65e
NJ
3734@end deffn
3735
9401323e 3736\fgetitimer
8f85c0c6
NJ
3737@deffn {Scheme Procedure} getitimer which_timer
3738@deffnx {C Function} scm_getitimer (which_timer)
9401323e
NJ
3739Return information about the timer specified by @var{which_timer}
3740Errors are handled as described in the guile info pages under ``POSIX
3741Interface Conventions''.
780ee65e 3742
9401323e
NJ
3743The timers available are: @code{ITIMER_REAL}, @code{ITIMER_VIRTUAL},
3744and @code{ITIMER_PROF}.
780ee65e 3745
9401323e
NJ
3746The return value will be a list of two cons pairs representing the
3747current state of the given timer. The first pair is the seconds and
3748microseconds of the timer @code{it_interval}, and the second pair is
3749the seconds and microseconds of the timer @code{it_value}.
780ee65e
NJ
3750@end deffn
3751
9401323e 3752\fpause
8f85c0c6
NJ
3753@deffn {Scheme Procedure} pause
3754@deffnx {C Function} scm_pause ()
9401323e
NJ
3755Pause the current process (thread?) until a signal arrives whose
3756action is to either terminate the current process or invoke a
3757handler procedure. The return value is unspecified.
780ee65e
NJ
3758@end deffn
3759
9401323e 3760\fsleep
8f85c0c6
NJ
3761@deffn {Scheme Procedure} sleep i
3762@deffnx {C Function} scm_sleep (i)
9401323e
NJ
3763Wait for the given number of seconds (an integer) or until a signal
3764arrives. The return value is zero if the time elapses or the number
3765of seconds remaining otherwise.
780ee65e
NJ
3766@end deffn
3767
9401323e 3768\fusleep
8f85c0c6
NJ
3769@deffn {Scheme Procedure} usleep i
3770@deffnx {C Function} scm_usleep (i)
9401323e
NJ
3771Sleep for I microseconds. @code{usleep} is not available on
3772all platforms.
780ee65e
NJ
3773@end deffn
3774
9401323e 3775\fraise
8f85c0c6
NJ
3776@deffn {Scheme Procedure} raise sig
3777@deffnx {C Function} scm_raise (sig)
9401323e
NJ
3778Sends a specified signal @var{sig} to the current process, where
3779@var{sig} is as described for the kill procedure.
780ee65e
NJ
3780@end deffn
3781
9401323e 3782\fsystem
8f85c0c6
NJ
3783@deffn {Scheme Procedure} system [cmd]
3784@deffnx {C Function} scm_system (cmd)
9401323e
NJ
3785Execute @var{cmd} using the operating system's "command
3786processor". Under Unix this is usually the default shell
3787@code{sh}. The value returned is @var{cmd}'s exit status as
3788returned by @code{waitpid}, which can be interpreted using the
3789functions above.
780ee65e 3790
9401323e
NJ
3791If @code{system} is called without arguments, return a boolean
3792indicating whether the command processor is available.
780ee65e
NJ
3793@end deffn
3794
9401323e 3795\fgetenv
8f85c0c6
NJ
3796@deffn {Scheme Procedure} getenv nam
3797@deffnx {C Function} scm_getenv (nam)
9401323e
NJ
3798Looks up the string @var{name} in the current environment. The return
3799value is @code{#f} unless a string of the form @code{NAME=VALUE} is
3800found, in which case the string @code{VALUE} is returned.
780ee65e
NJ
3801@end deffn
3802
9401323e 3803\fprimitive-exit
8f85c0c6
NJ
3804@deffn {Scheme Procedure} primitive-exit [status]
3805@deffnx {C Function} scm_primitive_exit (status)
9401323e
NJ
3806Terminate the current process without unwinding the Scheme stack.
3807This is would typically be useful after a fork. The exit status
3808is @var{status} if supplied, otherwise zero.
780ee65e
NJ
3809@end deffn
3810
9401323e 3811\frestricted-vector-sort!
8f85c0c6
NJ
3812@deffn {Scheme Procedure} restricted-vector-sort! vec less startpos endpos
3813@deffnx {C Function} scm_restricted_vector_sort_x (vec, less, startpos, endpos)
9401323e
NJ
3814Sort the vector @var{vec}, using @var{less} for comparing
3815the vector elements. @var{startpos} and @var{endpos} delimit
3816the range of the vector which gets sorted. The return value
3817is not specified.
780ee65e
NJ
3818@end deffn
3819
9401323e 3820\fsorted?
8f85c0c6
NJ
3821@deffn {Scheme Procedure} sorted? items less
3822@deffnx {C Function} scm_sorted_p (items, less)
9401323e
NJ
3823Return @code{#t} iff @var{items} is a list or a vector such that
3824for all 1 <= i <= m, the predicate @var{less} returns true when
3825applied to all elements i - 1 and i
780ee65e
NJ
3826@end deffn
3827
9401323e 3828\fmerge
8f85c0c6
NJ
3829@deffn {Scheme Procedure} merge alist blist less
3830@deffnx {C Function} scm_merge (alist, blist, less)
3831Merge two already sorted lists into one.
3832Given two lists @var{alist} and @var{blist}, such that
3833@code{(sorted? alist less?)} and @code{(sorted? blist less?)},
3834return a new list in which the elements of @var{alist} and
9401323e
NJ
3835@var{blist} have been stably interleaved so that
3836@code{(sorted? (merge alist blist less?) less?)}.
3837Note: this does _not_ accept vectors.
780ee65e
NJ
3838@end deffn
3839
9401323e 3840\fmerge!
8f85c0c6
NJ
3841@deffn {Scheme Procedure} merge! alist blist less
3842@deffnx {C Function} scm_merge_x (alist, blist, less)
9401323e
NJ
3843Takes two lists @var{alist} and @var{blist} such that
3844@code{(sorted? alist less?)} and @code{(sorted? blist less?)} and
3845returns a new list in which the elements of @var{alist} and
3846@var{blist} have been stably interleaved so that
3847 @code{(sorted? (merge alist blist less?) less?)}.
3848This is the destructive variant of @code{merge}
3849Note: this does _not_ accept vectors.
780ee65e
NJ
3850@end deffn
3851
9401323e 3852\fsort!
8f85c0c6
NJ
3853@deffn {Scheme Procedure} sort! items less
3854@deffnx {C Function} scm_sort_x (items, less)
9401323e
NJ
3855Sort the sequence @var{items}, which may be a list or a
3856vector. @var{less} is used for comparing the sequence
3857elements. The sorting is destructive, that means that the
3858input sequence is modified to produce the sorted result.
3859This is not a stable sort.
780ee65e
NJ
3860@end deffn
3861
9401323e 3862\fsort
8f85c0c6
NJ
3863@deffn {Scheme Procedure} sort items less
3864@deffnx {C Function} scm_sort (items, less)
9401323e
NJ
3865Sort the sequence @var{items}, which may be a list or a
3866vector. @var{less} is used for comparing the sequence
3867elements. This is not a stable sort.
780ee65e
NJ
3868@end deffn
3869
9401323e 3870\fstable-sort!
8f85c0c6
NJ
3871@deffn {Scheme Procedure} stable-sort! items less
3872@deffnx {C Function} scm_stable_sort_x (items, less)
9401323e
NJ
3873Sort the sequence @var{items}, which may be a list or a
3874vector. @var{less} is used for comparing the sequence elements.
3875The sorting is destructive, that means that the input sequence
3876is modified to produce the sorted result.
3877This is a stable sort.
780ee65e
NJ
3878@end deffn
3879
9401323e 3880\fstable-sort
8f85c0c6
NJ
3881@deffn {Scheme Procedure} stable-sort items less
3882@deffnx {C Function} scm_stable_sort (items, less)
9401323e
NJ
3883Sort the sequence @var{items}, which may be a list or a
3884vector. @var{less} is used for comparing the sequence elements.
3885This is a stable sort.
780ee65e
NJ
3886@end deffn
3887
9401323e 3888\fsort-list!
8f85c0c6
NJ
3889@deffn {Scheme Procedure} sort-list! items less
3890@deffnx {C Function} scm_sort_list_x (items, less)
9401323e
NJ
3891Sort the list @var{items}, using @var{less} for comparing the
3892list elements. The sorting is destructive, that means that the
3893input list is modified to produce the sorted result.
3894This is a stable sort.
780ee65e
NJ
3895@end deffn
3896
9401323e 3897\fsort-list
8f85c0c6
NJ
3898@deffn {Scheme Procedure} sort-list items less
3899@deffnx {C Function} scm_sort_list (items, less)
9401323e
NJ
3900Sort the list @var{items}, using @var{less} for comparing the
3901list elements. This is a stable sort.
780ee65e
NJ
3902@end deffn
3903
9401323e 3904\fsource-properties
8f85c0c6
NJ
3905@deffn {Scheme Procedure} source-properties obj
3906@deffnx {C Function} scm_source_properties (obj)
9401323e 3907Return the source property association list of @var{obj}.
780ee65e
NJ
3908@end deffn
3909
9401323e 3910\fset-source-properties!
8f85c0c6
NJ
3911@deffn {Scheme Procedure} set-source-properties! obj plist
3912@deffnx {C Function} scm_set_source_properties_x (obj, plist)
9401323e
NJ
3913Install the association list @var{plist} as the source property
3914list for @var{obj}.
780ee65e
NJ
3915@end deffn
3916
9401323e 3917\fsource-property
8f85c0c6
NJ
3918@deffn {Scheme Procedure} source-property obj key
3919@deffnx {C Function} scm_source_property (obj, key)
9401323e
NJ
3920Return the source property specified by @var{key} from
3921@var{obj}'s source property list.
780ee65e
NJ
3922@end deffn
3923
9401323e 3924\fset-source-property!
8f85c0c6
NJ
3925@deffn {Scheme Procedure} set-source-property! obj key datum
3926@deffnx {C Function} scm_set_source_property_x (obj, key, datum)
9401323e
NJ
3927Set the source property of object @var{obj}, which is specified by
3928@var{key} to @var{datum}. Normally, the key will be a symbol.
780ee65e
NJ
3929@end deffn
3930
9401323e 3931\fstack?
8f85c0c6
NJ
3932@deffn {Scheme Procedure} stack? obj
3933@deffnx {C Function} scm_stack_p (obj)
9401323e 3934Return @code{#t} if @var{obj} is a calling stack.
780ee65e
NJ
3935@end deffn
3936
9401323e 3937\fmake-stack
8f85c0c6
NJ
3938@deffn {Scheme Procedure} make-stack obj . args
3939@deffnx {C Function} scm_make_stack (obj, args)
9401323e
NJ
3940Create a new stack. If @var{obj} is @code{#t}, the current
3941evaluation stack is used for creating the stack frames,
3942otherwise the frames are taken from @var{obj} (which must be
3943either a debug object or a continuation).
780ee65e 3944
9401323e
NJ
3945@var{args} should be a list containing any combination of
3946integer, procedure and @code{#t} values.
3947
3948These values specify various ways of cutting away uninteresting
3949stack frames from the top and bottom of the stack that
3950@code{make-stack} returns. They come in pairs like this:
3951@code{(@var{inner_cut_1} @var{outer_cut_1} @var{inner_cut_2}
3952@var{outer_cut_2} @dots{})}.
3953
3954Each @var{inner_cut_N} can be @code{#t}, an integer, or a
3955procedure. @code{#t} means to cut away all frames up to but
3956excluding the first user module frame. An integer means to cut
3957away exactly that number of frames. A procedure means to cut
3958away all frames up to but excluding the application frame whose
3959procedure matches the specified one.
3960
3961Each @var{outer_cut_N} can be an integer or a procedure. An
3962integer means to cut away that number of frames. A procedure
3963means to cut away frames down to but excluding the application
3964frame whose procedure matches the specified one.
3965
3966If the @var{outer_cut_N} of the last pair is missing, it is
3967taken as 0.
780ee65e
NJ
3968@end deffn
3969
9401323e 3970\fstack-id
8f85c0c6
NJ
3971@deffn {Scheme Procedure} stack-id stack
3972@deffnx {C Function} scm_stack_id (stack)
9401323e 3973Return the identifier given to @var{stack} by @code{start-stack}.
780ee65e
NJ
3974@end deffn
3975
9401323e 3976\fstack-ref
8f85c0c6
NJ
3977@deffn {Scheme Procedure} stack-ref stack index
3978@deffnx {C Function} scm_stack_ref (stack, index)
9401323e 3979Return the @var{index}'th frame from @var{stack}.
780ee65e
NJ
3980@end deffn
3981
9401323e 3982\fstack-length
8f85c0c6
NJ
3983@deffn {Scheme Procedure} stack-length stack
3984@deffnx {C Function} scm_stack_length (stack)
9401323e 3985Return the length of @var{stack}.
780ee65e
NJ
3986@end deffn
3987
9401323e 3988\fframe?
8f85c0c6
NJ
3989@deffn {Scheme Procedure} frame? obj
3990@deffnx {C Function} scm_frame_p (obj)
9401323e 3991Return @code{#t} if @var{obj} is a stack frame.
780ee65e
NJ
3992@end deffn
3993
9401323e 3994\flast-stack-frame
8f85c0c6
NJ
3995@deffn {Scheme Procedure} last-stack-frame obj
3996@deffnx {C Function} scm_last_stack_frame (obj)
9401323e
NJ
3997Return a stack which consists of a single frame, which is the
3998last stack frame for @var{obj}. @var{obj} must be either a
3999debug object or a continuation.
780ee65e
NJ
4000@end deffn
4001
9401323e 4002\fframe-number
8f85c0c6
NJ
4003@deffn {Scheme Procedure} frame-number frame
4004@deffnx {C Function} scm_frame_number (frame)
9401323e 4005Return the frame number of @var{frame}.
780ee65e
NJ
4006@end deffn
4007
9401323e 4008\fframe-source
8f85c0c6
NJ
4009@deffn {Scheme Procedure} frame-source frame
4010@deffnx {C Function} scm_frame_source (frame)
9401323e 4011Return the source of @var{frame}.
780ee65e
NJ
4012@end deffn
4013
9401323e 4014\fframe-procedure
8f85c0c6
NJ
4015@deffn {Scheme Procedure} frame-procedure frame
4016@deffnx {C Function} scm_frame_procedure (frame)
9401323e
NJ
4017Return the procedure for @var{frame}, or @code{#f} if no
4018procedure is associated with @var{frame}.
780ee65e
NJ
4019@end deffn
4020
9401323e 4021\fframe-arguments
8f85c0c6
NJ
4022@deffn {Scheme Procedure} frame-arguments frame
4023@deffnx {C Function} scm_frame_arguments (frame)
9401323e 4024Return the arguments of @var{frame}.
780ee65e
NJ
4025@end deffn
4026
9401323e 4027\fframe-previous
8f85c0c6
NJ
4028@deffn {Scheme Procedure} frame-previous frame
4029@deffnx {C Function} scm_frame_previous (frame)
9401323e
NJ
4030Return the previous frame of @var{frame}, or @code{#f} if
4031@var{frame} is the first frame in its stack.
780ee65e
NJ
4032@end deffn
4033
9401323e 4034\fframe-next
8f85c0c6
NJ
4035@deffn {Scheme Procedure} frame-next frame
4036@deffnx {C Function} scm_frame_next (frame)
9401323e
NJ
4037Return the next frame of @var{frame}, or @code{#f} if
4038@var{frame} is the last frame in its stack.
780ee65e
NJ
4039@end deffn
4040
9401323e 4041\fframe-real?
8f85c0c6
NJ
4042@deffn {Scheme Procedure} frame-real? frame
4043@deffnx {C Function} scm_frame_real_p (frame)
9401323e 4044Return @code{#t} if @var{frame} is a real frame.
780ee65e
NJ
4045@end deffn
4046
9401323e 4047\fframe-procedure?
8f85c0c6
NJ
4048@deffn {Scheme Procedure} frame-procedure? frame
4049@deffnx {C Function} scm_frame_procedure_p (frame)
9401323e 4050Return @code{#t} if a procedure is associated with @var{frame}.
780ee65e
NJ
4051@end deffn
4052
9401323e 4053\fframe-evaluating-args?
8f85c0c6
NJ
4054@deffn {Scheme Procedure} frame-evaluating-args? frame
4055@deffnx {C Function} scm_frame_evaluating_args_p (frame)
9401323e 4056Return @code{#t} if @var{frame} contains evaluated arguments.
780ee65e
NJ
4057@end deffn
4058
9401323e 4059\fframe-overflow?
8f85c0c6
NJ
4060@deffn {Scheme Procedure} frame-overflow? frame
4061@deffnx {C Function} scm_frame_overflow_p (frame)
9401323e
NJ
4062Return @code{#t} if @var{frame} is an overflow frame.
4063@end deffn
780ee65e 4064
9401323e 4065\fget-internal-real-time
8f85c0c6
NJ
4066@deffn {Scheme Procedure} get-internal-real-time
4067@deffnx {C Function} scm_get_internal_real_time ()
9401323e
NJ
4068Return the number of time units since the interpreter was
4069started.
780ee65e
NJ
4070@end deffn
4071
9401323e 4072\ftimes
8f85c0c6
NJ
4073@deffn {Scheme Procedure} times
4074@deffnx {C Function} scm_times ()
9401323e
NJ
4075Return an object with information about real and processor
4076time. The following procedures accept such an object as an
4077argument and return a selected component:
7a095584 4078
9401323e
NJ
4079@table @code
4080@item tms:clock
4081The current real time, expressed as time units relative to an
4082arbitrary base.
4083@item tms:utime
4084The CPU time units used by the calling process.
4085@item tms:stime
4086The CPU time units used by the system on behalf of the calling
4087process.
4088@item tms:cutime
4089The CPU time units used by terminated child processes of the
4090calling process, whose status has been collected (e.g., using
4091@code{waitpid}).
4092@item tms:cstime
4093Similarly, the CPU times units used by the system on behalf of
4094terminated child processes.
4095@end table
4096@end deffn
7a095584 4097
9401323e 4098\fget-internal-run-time
8f85c0c6
NJ
4099@deffn {Scheme Procedure} get-internal-run-time
4100@deffnx {C Function} scm_get_internal_run_time ()
9401323e
NJ
4101Return the number of time units of processor time used by the
4102interpreter. Both @emph{system} and @emph{user} time are
4103included but subprocesses are not.
780ee65e
NJ
4104@end deffn
4105
9401323e 4106\fcurrent-time
8f85c0c6
NJ
4107@deffn {Scheme Procedure} current-time
4108@deffnx {C Function} scm_current_time ()
9401323e
NJ
4109Return the number of seconds since 1970-01-01 00:00:00 UTC,
4110excluding leap seconds.
780ee65e
NJ
4111@end deffn
4112
9401323e 4113\fgettimeofday
8f85c0c6
NJ
4114@deffn {Scheme Procedure} gettimeofday
4115@deffnx {C Function} scm_gettimeofday ()
9401323e
NJ
4116Return a pair containing the number of seconds and microseconds
4117since 1970-01-01 00:00:00 UTC, excluding leap seconds. Note:
4118whether true microsecond resolution is available depends on the
4119operating system.
780ee65e
NJ
4120@end deffn
4121
9401323e 4122\flocaltime
8f85c0c6
NJ
4123@deffn {Scheme Procedure} localtime time [zone]
4124@deffnx {C Function} scm_localtime (time, zone)
9401323e
NJ
4125Return an object representing the broken down components of
4126@var{time}, an integer like the one returned by
4127@code{current-time}. The time zone for the calculation is
4128optionally specified by @var{zone} (a string), otherwise the
4129@code{TZ} environment variable or the system default is used.
780ee65e
NJ
4130@end deffn
4131
9401323e 4132\fgmtime
8f85c0c6
NJ
4133@deffn {Scheme Procedure} gmtime time
4134@deffnx {C Function} scm_gmtime (time)
9401323e
NJ
4135Return an object representing the broken down components of
4136@var{time}, an integer like the one returned by
4137@code{current-time}. The values are calculated for UTC.
780ee65e
NJ
4138@end deffn
4139
9401323e 4140\fmktime
8f85c0c6
NJ
4141@deffn {Scheme Procedure} mktime sbd_time [zone]
4142@deffnx {C Function} scm_mktime (sbd_time, zone)
9401323e
NJ
4143@var{bd-time} is an object representing broken down time and @code{zone}
4144is an optional time zone specifier (otherwise the TZ environment variable
4145or the system default is used).
4146
4147Returns a pair: the car is a corresponding
4148integer time value like that returned
4149by @code{current-time}; the cdr is a broken down time object, similar to
4150as @var{bd-time} but with normalized values.
780ee65e
NJ
4151@end deffn
4152
9401323e 4153\ftzset
8f85c0c6
NJ
4154@deffn {Scheme Procedure} tzset
4155@deffnx {C Function} scm_tzset ()
9401323e
NJ
4156Initialize the timezone from the TZ environment variable
4157or the system default. It's not usually necessary to call this procedure
4158since it's done automatically by other procedures that depend on the
4159timezone.
780ee65e
NJ
4160@end deffn
4161
9401323e 4162\fstrftime
8f85c0c6
NJ
4163@deffn {Scheme Procedure} strftime format stime
4164@deffnx {C Function} scm_strftime (format, stime)
9401323e
NJ
4165Formats a time specification @var{time} using @var{template}. @var{time}
4166is an object with time components in the form returned by @code{localtime}
4167or @code{gmtime}. @var{template} is a string which can include formatting
4168specifications introduced by a @code{%} character. The formatting of
4169month and day names is dependent on the current locale. The value returned
4170is the formatted string.
4171@xref{Formatting Date and Time, , , libc, The GNU C Library Reference Manual}.)
780ee65e
NJ
4172@end deffn
4173
9401323e 4174\fstrptime
8f85c0c6
NJ
4175@deffn {Scheme Procedure} strptime format string
4176@deffnx {C Function} scm_strptime (format, string)
9401323e
NJ
4177Performs the reverse action to @code{strftime}, parsing
4178@var{string} according to the specification supplied in
4179@var{template}. The interpretation of month and day names is
4180dependent on the current locale. The value returned is a pair.
4181The car has an object with time components
4182in the form returned by @code{localtime} or @code{gmtime},
4183but the time zone components
4184are not usefully set.
4185The cdr reports the number of characters from @var{string}
4186which were used for the conversion.
780ee65e
NJ
4187@end deffn
4188
9401323e 4189\fstring?
8f85c0c6
NJ
4190@deffn {Scheme Procedure} string? obj
4191@deffnx {C Function} scm_string_p (obj)
4192Return @code{#t} iff @var{obj} is a string, else @code{#f}.
780ee65e
NJ
4193@end deffn
4194
9401323e 4195\flist->string
8f85c0c6 4196@deffn {Scheme Procedure} list->string
9401323e 4197implemented by the C function "scm_string"
780ee65e
NJ
4198@end deffn
4199
9401323e 4200\fstring
8f85c0c6
NJ
4201@deffn {Scheme Procedure} string . chrs
4202@deffnx {Scheme Procedure} list->string chrs
4203@deffnx {C Function} scm_string (chrs)
9401323e
NJ
4204Return a newly allocated string composed of the arguments,
4205@var{chrs}.
780ee65e
NJ
4206@end deffn
4207
9401323e 4208\fmake-string
8f85c0c6
NJ
4209@deffn {Scheme Procedure} make-string k [chr]
4210@deffnx {C Function} scm_make_string (k, chr)
9401323e
NJ
4211Return a newly allocated string of
4212length @var{k}. If @var{chr} is given, then all elements of
4213the string are initialized to @var{chr}, otherwise the contents
4214of the @var{string} are unspecified.
780ee65e
NJ
4215@end deffn
4216
9401323e 4217\fstring-length
8f85c0c6
NJ
4218@deffn {Scheme Procedure} string-length string
4219@deffnx {C Function} scm_string_length (string)
9401323e 4220Return the number of characters in @var{string}.
780ee65e
NJ
4221@end deffn
4222
9401323e 4223\fstring-ref
8f85c0c6
NJ
4224@deffn {Scheme Procedure} string-ref str k
4225@deffnx {C Function} scm_string_ref (str, k)
9401323e
NJ
4226Return character @var{k} of @var{str} using zero-origin
4227indexing. @var{k} must be a valid index of @var{str}.
780ee65e
NJ
4228@end deffn
4229
9401323e 4230\fstring-set!
8f85c0c6
NJ
4231@deffn {Scheme Procedure} string-set! str k chr
4232@deffnx {C Function} scm_string_set_x (str, k, chr)
9401323e
NJ
4233Store @var{chr} in element @var{k} of @var{str} and return
4234an unspecified value. @var{k} must be a valid index of
4235@var{str}.
780ee65e
NJ
4236@end deffn
4237
9401323e 4238\fsubstring
8f85c0c6
NJ
4239@deffn {Scheme Procedure} substring str start [end]
4240@deffnx {C Function} scm_substring (str, start, end)
9401323e
NJ
4241Return a newly allocated string formed from the characters
4242of @var{str} beginning with index @var{start} (inclusive) and
4243ending with index @var{end} (exclusive).
4244@var{str} must be a string, @var{start} and @var{end} must be
4245exact integers satisfying:
7a095584 4246
9401323e 42470 <= @var{start} <= @var{end} <= (string-length @var{str}).
780ee65e
NJ
4248@end deffn
4249
9401323e 4250\fstring-append
8f85c0c6
NJ
4251@deffn {Scheme Procedure} string-append . args
4252@deffnx {C Function} scm_string_append (args)
9401323e
NJ
4253Return a newly allocated string whose characters form the
4254concatenation of the given strings, @var{args}.
780ee65e
NJ
4255@end deffn
4256
9401323e 4257\fstring-index
8f85c0c6
NJ
4258@deffn {Scheme Procedure} string-index str chr [frm [to]]
4259@deffnx {C Function} scm_string_index (str, chr, frm, to)
9401323e
NJ
4260Return the index of the first occurrence of @var{chr} in
4261@var{str}. The optional integer arguments @var{frm} and
4262@var{to} limit the search to a portion of the string. This
4263procedure essentially implements the @code{index} or
4264@code{strchr} functions from the C library.
780ee65e 4265
9401323e
NJ
4266@lisp
4267(string-index "weiner" #\e)
4268@result{} 1
780ee65e 4269
9401323e
NJ
4270(string-index "weiner" #\e 2)
4271@result{} 4
780ee65e 4272
9401323e
NJ
4273(string-index "weiner" #\e 2 4)
4274@result{} #f
4275@end lisp
4276@end deffn
4277
4278\fstring-rindex
8f85c0c6
NJ
4279@deffn {Scheme Procedure} string-rindex str chr [frm [to]]
4280@deffnx {C Function} scm_string_rindex (str, chr, frm, to)
9401323e
NJ
4281Like @code{string-index}, but search from the right of the
4282string rather than from the left. This procedure essentially
4283implements the @code{rindex} or @code{strrchr} functions from
4284the C library.
780ee65e 4285
ae9f3a15 4286@lisp
9401323e
NJ
4287(string-rindex "weiner" #\e)
4288@result{} 4
780ee65e 4289
9401323e
NJ
4290(string-rindex "weiner" #\e 2 4)
4291@result{} #f
780ee65e 4292
9401323e
NJ
4293(string-rindex "weiner" #\e 2 5)
4294@result{} 4
4295@end lisp
4296@end deffn
780ee65e 4297
9401323e 4298\fsubstring-move!
8f85c0c6
NJ
4299@deffn {Scheme Procedure} substring-move! str1 start1 end1 str2 start2
4300@deffnx {C Function} scm_substring_move_x (str1, start1, end1, str2, start2)
9401323e
NJ
4301Copy the substring of @var{str1} bounded by @var{start1} and @var{end1}
4302into @var{str2} beginning at position @var{start2}.
8f85c0c6 4303@var{str1} and @var{str2} can be the same string.
780ee65e
NJ
4304@end deffn
4305
9401323e 4306\fsubstring-fill!
8f85c0c6
NJ
4307@deffn {Scheme Procedure} substring-fill! str start end fill
4308@deffnx {C Function} scm_substring_fill_x (str, start, end, fill)
9401323e
NJ
4309Change every character in @var{str} between @var{start} and
4310@var{end} to @var{fill}.
780ee65e 4311
9401323e
NJ
4312@lisp
4313(define y "abcdefg")
4314(substring-fill! y 1 3 #\r)
4315y
4316@result{} "arrdefg"
4317@end lisp
780ee65e
NJ
4318@end deffn
4319
9401323e 4320\fstring-null?
8f85c0c6
NJ
4321@deffn {Scheme Procedure} string-null? str
4322@deffnx {C Function} scm_string_null_p (str)
28206d04 4323Return @code{#t} if @var{str}'s length is zero, and
9401323e
NJ
4324@code{#f} otherwise.
4325@lisp
4326(string-null? "") @result{} #t
4327y @result{} "foo"
4328(string-null? y) @result{} #f
4329@end lisp
780ee65e
NJ
4330@end deffn
4331
9401323e 4332\fstring->list
8f85c0c6
NJ
4333@deffn {Scheme Procedure} string->list str
4334@deffnx {C Function} scm_string_to_list (str)
9401323e
NJ
4335Return a newly allocated list of the characters that make up
4336the given string @var{str}. @code{string->list} and
4337@code{list->string} are inverses as far as @samp{equal?} is
4338concerned.
780ee65e
NJ
4339@end deffn
4340
9401323e 4341\fstring-copy
8f85c0c6
NJ
4342@deffn {Scheme Procedure} string-copy str
4343@deffnx {C Function} scm_string_copy (str)
9401323e 4344Return a newly allocated copy of the given @var{string}.
780ee65e
NJ
4345@end deffn
4346
9401323e 4347\fstring-fill!
8f85c0c6
NJ
4348@deffn {Scheme Procedure} string-fill! str chr
4349@deffnx {C Function} scm_string_fill_x (str, chr)
9401323e
NJ
4350Store @var{char} in every element of the given @var{string} and
4351return an unspecified value.
780ee65e
NJ
4352@end deffn
4353
9401323e 4354\fstring-upcase!
8f85c0c6
NJ
4355@deffn {Scheme Procedure} string-upcase! str
4356@deffnx {C Function} scm_string_upcase_x (str)
9401323e
NJ
4357Destructively upcase every character in @var{str} and return
4358@var{str}.
4359@lisp
4360y @result{} "arrdefg"
4361(string-upcase! y) @result{} "ARRDEFG"
4362y @result{} "ARRDEFG"
4363@end lisp
780ee65e
NJ
4364@end deffn
4365
9401323e 4366\fstring-upcase
8f85c0c6
NJ
4367@deffn {Scheme Procedure} string-upcase str
4368@deffnx {C Function} scm_string_upcase (str)
9401323e
NJ
4369Return a freshly allocated string containing the characters of
4370@var{str} in upper case.
780ee65e
NJ
4371@end deffn
4372
9401323e 4373\fstring-downcase!
8f85c0c6
NJ
4374@deffn {Scheme Procedure} string-downcase! str
4375@deffnx {C Function} scm_string_downcase_x (str)
9401323e
NJ
4376Destructively downcase every character in @var{str} and return
4377@var{str}.
4378@lisp
4379y @result{} "ARRDEFG"
4380(string-downcase! y) @result{} "arrdefg"
4381y @result{} "arrdefg"
4382@end lisp
780ee65e
NJ
4383@end deffn
4384
9401323e 4385\fstring-downcase
8f85c0c6
NJ
4386@deffn {Scheme Procedure} string-downcase str
4387@deffnx {C Function} scm_string_downcase (str)
9401323e
NJ
4388Return a freshly allocation string containing the characters in
4389@var{str} in lower case.
780ee65e
NJ
4390@end deffn
4391
9401323e 4392\fstring-capitalize!
8f85c0c6
NJ
4393@deffn {Scheme Procedure} string-capitalize! str
4394@deffnx {C Function} scm_string_capitalize_x (str)
9401323e
NJ
4395Upcase the first character of every word in @var{str}
4396destructively and return @var{str}.
780ee65e 4397
9401323e
NJ
4398@lisp
4399y @result{} "hello world"
4400(string-capitalize! y) @result{} "Hello World"
4401y @result{} "Hello World"
4402@end lisp
780ee65e
NJ
4403@end deffn
4404
9401323e 4405\fstring-capitalize
8f85c0c6
NJ
4406@deffn {Scheme Procedure} string-capitalize str
4407@deffnx {C Function} scm_string_capitalize (str)
9401323e
NJ
4408Return a freshly allocated string with the characters in
4409@var{str}, where the first character of every word is
4410capitalized.
7a095584
NJ
4411@end deffn
4412
9401323e 4413\fstring-split
8f85c0c6
NJ
4414@deffn {Scheme Procedure} string-split str chr
4415@deffnx {C Function} scm_string_split (str, chr)
9401323e
NJ
4416Split the string @var{str} into the a list of the substrings delimited
4417by appearances of the character @var{chr}. Note that an empty substring
4418between separator characters will result in an empty string in the
4419result list.
7a095584
NJ
4420
4421@lisp
8f85c0c6 4422(string-split "root:x:0:0:root:/root:/bin/bash" #\:)
9401323e
NJ
4423@result{}
4424("root" "x" "0" "0" "root" "/root" "/bin/bash")
7a095584 4425
8f85c0c6 4426(string-split "::" #\:)
9401323e
NJ
4427@result{}
4428("" "" "")
7a095584 4429
8f85c0c6 4430(string-split "" #\:)
9401323e
NJ
4431@result{}
4432("")
7a095584
NJ
4433@end lisp
4434@end deffn
4435
9401323e 4436\fstring-ci->symbol
8f85c0c6
NJ
4437@deffn {Scheme Procedure} string-ci->symbol str
4438@deffnx {C Function} scm_string_ci_to_symbol (str)
9401323e
NJ
4439Return the symbol whose name is @var{str}. @var{str} is
4440converted to lowercase before the conversion is done, if Guile
8f85c0c6 4441is currently reading symbols case-insensitively.
9401323e 4442@end deffn
7a095584 4443
9401323e 4444\fstring=?
8f85c0c6 4445@deffn {Scheme Procedure} string=? s1 s2
9401323e
NJ
4446Lexicographic equality predicate; return @code{#t} if the two
4447strings are the same length and contain the same characters in
4448the same positions, otherwise return @code{#f}.
4449
4450The procedure @code{string-ci=?} treats upper and lower case
4451letters as though they were the same character, but
4452@code{string=?} treats upper and lower case as distinct
4453characters.
7a095584
NJ
4454@end deffn
4455
9401323e 4456\fstring-ci=?
8f85c0c6 4457@deffn {Scheme Procedure} string-ci=? s1 s2
9401323e
NJ
4458Case-insensitive string equality predicate; return @code{#t} if
4459the two strings are the same length and their component
4460characters match (ignoring case) at each position; otherwise
4461return @code{#f}.
4462@end deffn
7a095584 4463
9401323e 4464\fstring<?
8f85c0c6 4465@deffn {Scheme Procedure} string<? s1 s2
9401323e
NJ
4466Lexicographic ordering predicate; return @code{#t} if @var{s1}
4467is lexicographically less than @var{s2}.
7a095584
NJ
4468@end deffn
4469
9401323e 4470\fstring<=?
8f85c0c6 4471@deffn {Scheme Procedure} string<=? s1 s2
9401323e
NJ
4472Lexicographic ordering predicate; return @code{#t} if @var{s1}
4473is lexicographically less than or equal to @var{s2}.
4474@end deffn
7a095584 4475
9401323e 4476\fstring>?
8f85c0c6 4477@deffn {Scheme Procedure} string>? s1 s2
9401323e
NJ
4478Lexicographic ordering predicate; return @code{#t} if @var{s1}
4479is lexicographically greater than @var{s2}.
7a095584
NJ
4480@end deffn
4481
9401323e 4482\fstring>=?
8f85c0c6 4483@deffn {Scheme Procedure} string>=? s1 s2
9401323e
NJ
4484Lexicographic ordering predicate; return @code{#t} if @var{s1}
4485is lexicographically greater than or equal to @var{s2}.
4486@end deffn
7a095584 4487
9401323e 4488\fstring-ci<?
8f85c0c6 4489@deffn {Scheme Procedure} string-ci<? s1 s2
9401323e
NJ
4490Case insensitive lexicographic ordering predicate; return
4491@code{#t} if @var{s1} is lexicographically less than @var{s2}
4492regardless of case.
7a095584
NJ
4493@end deffn
4494
9401323e 4495\fstring-ci<=?
8f85c0c6 4496@deffn {Scheme Procedure} string-ci<=? s1 s2
9401323e
NJ
4497Case insensitive lexicographic ordering predicate; return
4498@code{#t} if @var{s1} is lexicographically less than or equal
4499to @var{s2} regardless of case.
4500@end deffn
7a095584 4501
9401323e 4502\fstring-ci>?
8f85c0c6 4503@deffn {Scheme Procedure} string-ci>? s1 s2
9401323e
NJ
4504Case insensitive lexicographic ordering predicate; return
4505@code{#t} if @var{s1} is lexicographically greater than
4506@var{s2} regardless of case.
780ee65e
NJ
4507@end deffn
4508
9401323e 4509\fstring-ci>=?
8f85c0c6 4510@deffn {Scheme Procedure} string-ci>=? s1 s2
9401323e
NJ
4511Case insensitive lexicographic ordering predicate; return
4512@code{#t} if @var{s1} is lexicographically greater than or
4513equal to @var{s2} regardless of case.
4514@end deffn
7a095584 4515
9401323e 4516\fobject->string
8f85c0c6
NJ
4517@deffn {Scheme Procedure} object->string obj [printer]
4518@deffnx {C Function} scm_object_to_string (obj, printer)
9401323e
NJ
4519Return a Scheme string obtained by printing @var{obj}.
4520Printing function can be specified by the optional second
4521argument @var{printer} (default: @code{write}).
4522@end deffn
7a095584 4523
9401323e 4524\fcall-with-output-string
8f85c0c6
NJ
4525@deffn {Scheme Procedure} call-with-output-string proc
4526@deffnx {C Function} scm_call_with_output_string (proc)
9401323e
NJ
4527Calls the one-argument procedure @var{proc} with a newly created output
4528port. When the function returns, the string composed of the characters
4529written into the port is returned.
780ee65e
NJ
4530@end deffn
4531
9401323e 4532\fcall-with-input-string
8f85c0c6
NJ
4533@deffn {Scheme Procedure} call-with-input-string string proc
4534@deffnx {C Function} scm_call_with_input_string (string, proc)
9401323e
NJ
4535Calls the one-argument procedure @var{proc} with a newly
4536created input port from which @var{string}'s contents may be
4537read. The value yielded by the @var{proc} is returned.
780ee65e
NJ
4538@end deffn
4539
9401323e 4540\fopen-input-string
8f85c0c6
NJ
4541@deffn {Scheme Procedure} open-input-string str
4542@deffnx {C Function} scm_open_input_string (str)
9401323e
NJ
4543Take a string and return an input port that delivers characters
4544from the string. The port can be closed by
4545@code{close-input-port}, though its storage will be reclaimed
4546by the garbage collector if it becomes inaccessible.
4547@end deffn
7a095584 4548
9401323e 4549\fopen-output-string
8f85c0c6
NJ
4550@deffn {Scheme Procedure} open-output-string
4551@deffnx {C Function} scm_open_output_string ()
9401323e
NJ
4552Return an output port that will accumulate characters for
4553retrieval by @code{get-output-string}. The port can be closed
4554by the procedure @code{close-output-port}, though its storage
4555will be reclaimed by the garbage collector if it becomes
4556inaccessible.
780ee65e
NJ
4557@end deffn
4558
9401323e 4559\fget-output-string
8f85c0c6
NJ
4560@deffn {Scheme Procedure} get-output-string port
4561@deffnx {C Function} scm_get_output_string (port)
9401323e
NJ
4562Given an output port created by @code{open-output-string},
4563return a string consisting of the characters that have been
4564output to the port so far.
4565@end deffn
780ee65e 4566
9401323e 4567\feval-string
8f85c0c6
NJ
4568@deffn {Scheme Procedure} eval-string string
4569@deffnx {C Function} scm_eval_string (string)
9401323e
NJ
4570Evaluate @var{string} as the text representation of a Scheme
4571form or forms, and return whatever value they produce.
4572Evaluation takes place in the environment returned by the
4573procedure @code{interaction-environment}.
780ee65e
NJ
4574@end deffn
4575
9401323e 4576\fmake-struct-layout
8f85c0c6
NJ
4577@deffn {Scheme Procedure} make-struct-layout fields
4578@deffnx {C Function} scm_make_struct_layout (fields)
9401323e 4579Return a new structure layout object.
780ee65e 4580
9401323e
NJ
4581@var{fields} must be a string made up of pairs of characters
4582strung together. The first character of each pair describes a field
4583type, the second a field protection. Allowed types are 'p' for
4584GC-protected Scheme data, 'u' for unprotected binary data, and 's' for
4585a field that points to the structure itself. Allowed protections
4586are 'w' for mutable fields, 'r' for read-only fields, and 'o' for opaque
4587fields. The last field protection specification may be capitalized to
4588indicate that the field is a tail-array.
4589@end deffn
780ee65e 4590
9401323e 4591\fstruct?
8f85c0c6
NJ
4592@deffn {Scheme Procedure} struct? x
4593@deffnx {C Function} scm_struct_p (x)
28206d04 4594Return @code{#t} iff @var{x} is a structure object, else
9401323e 4595@code{#f}.
780ee65e
NJ
4596@end deffn
4597
9401323e 4598\fstruct-vtable?
8f85c0c6
NJ
4599@deffn {Scheme Procedure} struct-vtable? x
4600@deffnx {C Function} scm_struct_vtable_p (x)
28206d04 4601Return @code{#t} iff @var{x} is a vtable structure.
9401323e 4602@end deffn
780ee65e 4603
9401323e 4604\fmake-struct
8f85c0c6
NJ
4605@deffn {Scheme Procedure} make-struct vtable tail_array_size . init
4606@deffnx {C Function} scm_make_struct (vtable, tail_array_size, init)
9401323e 4607Create a new structure.
780ee65e 4608
9401323e 4609@var{type} must be a vtable structure (@pxref{Vtables}).
72ad43dc 4610
9401323e
NJ
4611@var{tail-elts} must be a non-negative integer. If the layout
4612specification indicated by @var{type} includes a tail-array,
4613this is the number of elements allocated to that array.
780ee65e 4614
9401323e
NJ
4615The @var{init1}, @dots{} are optional arguments describing how
4616successive fields of the structure should be initialized. Only fields
4617with protection 'r' or 'w' can be initialized, except for fields of
4618type 's', which are automatically initialized to point to the new
4619structure itself; fields with protection 'o' can not be initialized by
4620Scheme programs.
780ee65e 4621
9401323e
NJ
4622If fewer optional arguments than initializable fields are supplied,
4623fields of type 'p' get default value #f while fields of type 'u' are
4624initialized to 0.
780ee65e 4625
9401323e
NJ
4626Structs are currently the basic representation for record-like data
4627structures in Guile. The plan is to eventually replace them with a
4628new representation which will at the same time be easier to use and
4629more powerful.
780ee65e 4630
9401323e
NJ
4631For more information, see the documentation for @code{make-vtable-vtable}.
4632@end deffn
780ee65e 4633
9401323e 4634\fmake-vtable-vtable
8f85c0c6
NJ
4635@deffn {Scheme Procedure} make-vtable-vtable user_fields tail_array_size . init
4636@deffnx {C Function} scm_make_vtable_vtable (user_fields, tail_array_size, init)
9401323e 4637Return a new, self-describing vtable structure.
780ee65e 4638
9401323e
NJ
4639@var{user-fields} is a string describing user defined fields of the
4640vtable beginning at index @code{vtable-offset-user}
4641(see @code{make-struct-layout}).
780ee65e 4642
9401323e
NJ
4643@var{tail-size} specifies the size of the tail-array (if any) of
4644this vtable.
780ee65e 4645
9401323e
NJ
4646@var{init1}, @dots{} are the optional initializers for the fields of
4647the vtable.
780ee65e 4648
9401323e
NJ
4649Vtables have one initializable system field---the struct printer.
4650This field comes before the user fields in the initializers passed
4651to @code{make-vtable-vtable} and @code{make-struct}, and thus works as
4652a third optional argument to @code{make-vtable-vtable} and a fourth to
4653@code{make-struct} when creating vtables:
780ee65e 4654
9401323e
NJ
4655If the value is a procedure, it will be called instead of the standard
4656printer whenever a struct described by this vtable is printed.
4657The procedure will be called with arguments STRUCT and PORT.
780ee65e 4658
9401323e
NJ
4659The structure of a struct is described by a vtable, so the vtable is
4660in essence the type of the struct. The vtable is itself a struct with
4661a vtable. This could go on forever if it weren't for the
4662vtable-vtables which are self-describing vtables, and thus terminate
4663the chain.
7a095584 4664
9401323e
NJ
4665There are several potential ways of using structs, but the standard
4666one is to use three kinds of structs, together building up a type
4667sub-system: one vtable-vtable working as the root and one or several
4668"types", each with a set of "instances". (The vtable-vtable should be
4669compared to the class <class> which is the class of itself.)
780ee65e 4670
9401323e
NJ
4671@lisp
4672(define ball-root (make-vtable-vtable "pr" 0))
780ee65e 4673
9401323e
NJ
4674(define (make-ball-type ball-color)
4675 (make-struct ball-root 0
4676 (make-struct-layout "pw")
4677 (lambda (ball port)
4678 (format port "#<a ~A ball owned by ~A>"
4679 (color ball)
4680 (owner ball)))
4681 ball-color))
4682(define (color ball) (struct-ref (struct-vtable ball) vtable-offset-user))
4683(define (owner ball) (struct-ref ball 0))
780ee65e 4684
9401323e
NJ
4685(define red (make-ball-type 'red))
4686(define green (make-ball-type 'green))
780ee65e 4687
9401323e 4688(define (make-ball type owner) (make-struct type 0 owner))
780ee65e 4689
9401323e
NJ
4690(define ball (make-ball green 'Nisse))
4691ball @result{} #<a green ball owned by Nisse>
4692@end lisp
780ee65e
NJ
4693@end deffn
4694
9401323e 4695\fstruct-ref
8f85c0c6
NJ
4696@deffn {Scheme Procedure} struct-ref handle pos
4697@deffnx {Scheme Procedure} struct-set! struct n value
4698@deffnx {C Function} scm_struct_ref (handle, pos)
9401323e 4699Access (or modify) the @var{n}th field of @var{struct}.
780ee65e 4700
9401323e
NJ
4701If the field is of type 'p', then it can be set to an arbitrary value.
4702
4703If the field is of type 'u', then it can only be set to a non-negative
4704integer value small enough to fit in one machine word.
780ee65e
NJ
4705@end deffn
4706
9401323e 4707\fstruct-set!
8f85c0c6
NJ
4708@deffn {Scheme Procedure} struct-set! handle pos val
4709@deffnx {C Function} scm_struct_set_x (handle, pos, val)
9401323e
NJ
4710Set the slot of the structure @var{handle} with index @var{pos}
4711to @var{val}. Signal an error if the slot can not be written
4712to.
4713@end deffn
780ee65e 4714
9401323e 4715\fstruct-vtable
8f85c0c6
NJ
4716@deffn {Scheme Procedure} struct-vtable handle
4717@deffnx {C Function} scm_struct_vtable (handle)
9401323e
NJ
4718Return the vtable structure that describes the type of @var{struct}.
4719@end deffn
780ee65e 4720
9401323e 4721\fstruct-vtable-tag
8f85c0c6
NJ
4722@deffn {Scheme Procedure} struct-vtable-tag handle
4723@deffnx {C Function} scm_struct_vtable_tag (handle)
9401323e
NJ
4724Return the vtable tag of the structure @var{handle}.
4725@end deffn
780ee65e 4726
9401323e 4727\fstruct-vtable-name
8f85c0c6
NJ
4728@deffn {Scheme Procedure} struct-vtable-name vtable
4729@deffnx {C Function} scm_struct_vtable_name (vtable)
9401323e 4730Return the name of the vtable @var{vtable}.
780ee65e
NJ
4731@end deffn
4732
9401323e 4733\fset-struct-vtable-name!
8f85c0c6
NJ
4734@deffn {Scheme Procedure} set-struct-vtable-name! vtable name
4735@deffnx {C Function} scm_set_struct_vtable_name_x (vtable, name)
9401323e
NJ
4736Set the name of the vtable @var{vtable} to @var{name}.
4737@end deffn
780ee65e 4738
9401323e 4739\fsymbol?
8f85c0c6
NJ
4740@deffn {Scheme Procedure} symbol? obj
4741@deffnx {C Function} scm_symbol_p (obj)
9401323e
NJ
4742Return @code{#t} if @var{obj} is a symbol, otherwise return
4743@code{#f}.
780ee65e
NJ
4744@end deffn
4745
9401323e 4746\fsymbol->string
8f85c0c6
NJ
4747@deffn {Scheme Procedure} symbol->string s
4748@deffnx {C Function} scm_symbol_to_string (s)
9401323e
NJ
4749Return the name of @var{symbol} as a string. If the symbol was
4750part of an object returned as the value of a literal expression
4751(section @pxref{Literal expressions,,,r5rs, The Revised^5
4752Report on Scheme}) or by a call to the @code{read} procedure,
4753and its name contains alphabetic characters, then the string
4754returned will contain characters in the implementation's
4755preferred standard case---some implementations will prefer
4756upper case, others lower case. If the symbol was returned by
4757@code{string->symbol}, the case of characters in the string
4758returned will be the same as the case in the string that was
4759passed to @code{string->symbol}. It is an error to apply
4760mutation procedures like @code{string-set!} to strings returned
4761by this procedure.
7a095584 4762
9401323e
NJ
4763The following examples assume that the implementation's
4764standard case is lower case:
7a095584 4765
9401323e
NJ
4766@lisp
4767(symbol->string 'flying-fish) @result{} "flying-fish"
4768(symbol->string 'Martin) @result{} "martin"
4769(symbol->string
4770 (string->symbol "Malvina")) @result{} "Malvina"
4771@end lisp
4772@end deffn
7a095584 4773
9401323e 4774\fstring->symbol
8f85c0c6
NJ
4775@deffn {Scheme Procedure} string->symbol string
4776@deffnx {C Function} scm_string_to_symbol (string)
9401323e
NJ
4777Return the symbol whose name is @var{string}. This procedure
4778can create symbols with names containing special characters or
4779letters in the non-standard case, but it is usually a bad idea
4780to create such symbols because in some implementations of
4781Scheme they cannot be read as themselves. See
4782@code{symbol->string}.
7a095584 4783
9401323e
NJ
4784The following examples assume that the implementation's
4785standard case is lower case:
4786
4787@lisp
4788(eq? 'mISSISSIppi 'mississippi) @result{} #t
4789(string->symbol "mISSISSIppi") @result{} @r{the symbol with name "mISSISSIppi"}
4790(eq? 'bitBlt (string->symbol "bitBlt")) @result{} #f
4791(eq? 'JollyWog
4792 (string->symbol (symbol->string 'JollyWog))) @result{} #t
4793(string=? "K. Harper, M.D."
4794 (symbol->string
4795 (string->symbol "K. Harper, M.D."))) @result{}#t
4796@end lisp
780ee65e
NJ
4797@end deffn
4798
9401323e 4799\fgensym
8f85c0c6
NJ
4800@deffn {Scheme Procedure} gensym [prefix]
4801@deffnx {C Function} scm_gensym (prefix)
9401323e
NJ
4802Create a new symbol with a name constructed from a prefix and
4803a counter value. The string @var{prefix} can be specified as
4804an optional argument. Default prefix is @code{g}. The counter
4805is increased by 1 at each call. There is no provision for
4806resetting the counter.
780ee65e
NJ
4807@end deffn
4808
9401323e 4809\fsymbol-hash
8f85c0c6
NJ
4810@deffn {Scheme Procedure} symbol-hash symbol
4811@deffnx {C Function} scm_symbol_hash (symbol)
9401323e 4812Return a hash value for @var{symbol}.
780ee65e
NJ
4813@end deffn
4814
9401323e 4815\fsymbol-fref
8f85c0c6
NJ
4816@deffn {Scheme Procedure} symbol-fref s
4817@deffnx {C Function} scm_symbol_fref (s)
9401323e 4818Return the contents of @var{symbol}'s @dfn{function slot}.
780ee65e
NJ
4819@end deffn
4820
9401323e 4821\fsymbol-pref
8f85c0c6
NJ
4822@deffn {Scheme Procedure} symbol-pref s
4823@deffnx {C Function} scm_symbol_pref (s)
9401323e 4824Return the @dfn{property list} currently associated with @var{symbol}.
780ee65e
NJ
4825@end deffn
4826
9401323e 4827\fsymbol-fset!
8f85c0c6
NJ
4828@deffn {Scheme Procedure} symbol-fset! s val
4829@deffnx {C Function} scm_symbol_fset_x (s, val)
9401323e 4830Change the binding of @var{symbol}'s function slot.
780ee65e
NJ
4831@end deffn
4832
9401323e 4833\fsymbol-pset!
8f85c0c6
NJ
4834@deffn {Scheme Procedure} symbol-pset! s val
4835@deffnx {C Function} scm_symbol_pset_x (s, val)
9401323e 4836Change the binding of @var{symbol}'s property slot.
780ee65e
NJ
4837@end deffn
4838
9401323e 4839\fcatch
8f85c0c6
NJ
4840@deffn {Scheme Procedure} catch key thunk handler
4841@deffnx {C Function} scm_catch (key, thunk, handler)
9401323e
NJ
4842Invoke @var{thunk} in the dynamic context of @var{handler} for
4843exceptions matching @var{key}. If thunk throws to the symbol
4844@var{key}, then @var{handler} is invoked this way:
4845@lisp
4846(handler key args ...)
4847@end lisp
780ee65e 4848
9401323e 4849@var{key} is a symbol or @code{#t}.
780ee65e 4850
9401323e
NJ
4851@var{thunk} takes no arguments. If @var{thunk} returns
4852normally, that is the return value of @code{catch}.
4853
4854Handler is invoked outside the scope of its own @code{catch}.
4855If @var{handler} again throws to the same key, a new handler
4856from further up the call chain is invoked.
4857
4858If the key is @code{#t}, then a throw to @emph{any} symbol will
4859match this call to @code{catch}.
780ee65e
NJ
4860@end deffn
4861
9401323e 4862\flazy-catch
8f85c0c6
NJ
4863@deffn {Scheme Procedure} lazy-catch key thunk handler
4864@deffnx {C Function} scm_lazy_catch (key, thunk, handler)
9401323e
NJ
4865This behaves exactly like @code{catch}, except that it does
4866not unwind the stack before invoking @var{handler}.
4867The @var{handler} procedure is not allowed to return:
4868it must throw to another catch, or otherwise exit non-locally.
780ee65e
NJ
4869@end deffn
4870
9401323e 4871\fthrow
8f85c0c6
NJ
4872@deffn {Scheme Procedure} throw key . args
4873@deffnx {C Function} scm_throw (key, args)
9401323e
NJ
4874Invoke the catch form matching @var{key}, passing @var{args} to the
4875@var{handler}.
4876
4877@var{key} is a symbol. It will match catches of the same symbol or of
4878@code{#t}.
4879
4880If there is no handler at all, Guile prints an error and then exits.
780ee65e
NJ
4881@end deffn
4882
9401323e 4883\fvalues
8f85c0c6
NJ
4884@deffn {Scheme Procedure} values . args
4885@deffnx {C Function} scm_values (args)
9401323e
NJ
4886Delivers all of its arguments to its continuation. Except for
4887continuations created by the @code{call-with-values} procedure,
4888all continuations take exactly one value. The effect of
4889passing no value or more than one value to continuations that
4890were not created by @code{call-with-values} is unspecified.
780ee65e
NJ
4891@end deffn
4892
9401323e 4893\fmake-variable
8f85c0c6
NJ
4894@deffn {Scheme Procedure} make-variable init
4895@deffnx {C Function} scm_make_variable (init)
9401323e 4896Return a variable initialized to value @var{init}.
780ee65e
NJ
4897@end deffn
4898
9401323e 4899\fmake-undefined-variable
8f85c0c6
NJ
4900@deffn {Scheme Procedure} make-undefined-variable
4901@deffnx {C Function} scm_make_undefined_variable ()
9401323e 4902Return a variable that is initially unbound.
780ee65e
NJ
4903@end deffn
4904
9401323e 4905\fvariable?
8f85c0c6
NJ
4906@deffn {Scheme Procedure} variable? obj
4907@deffnx {C Function} scm_variable_p (obj)
9401323e
NJ
4908Return @code{#t} iff @var{obj} is a variable object, else
4909return @code{#f}.
780ee65e
NJ
4910@end deffn
4911
9401323e 4912\fvariable-ref
8f85c0c6
NJ
4913@deffn {Scheme Procedure} variable-ref var
4914@deffnx {C Function} scm_variable_ref (var)
9401323e
NJ
4915Dereference @var{var} and return its value.
4916@var{var} must be a variable object; see @code{make-variable}
4917and @code{make-undefined-variable}.
780ee65e
NJ
4918@end deffn
4919
9401323e 4920\fvariable-set!
8f85c0c6
NJ
4921@deffn {Scheme Procedure} variable-set! var val
4922@deffnx {C Function} scm_variable_set_x (var, val)
9401323e
NJ
4923Set the value of the variable @var{var} to @var{val}.
4924@var{var} must be a variable object, @var{val} can be any
4925value. Return an unspecified value.
780ee65e
NJ
4926@end deffn
4927
9401323e 4928\fvariable-bound?
8f85c0c6
NJ
4929@deffn {Scheme Procedure} variable-bound? var
4930@deffnx {C Function} scm_variable_bound_p (var)
9401323e
NJ
4931Return @code{#t} iff @var{var} is bound to a value.
4932Throws an error if @var{var} is not a variable object.
780ee65e
NJ
4933@end deffn
4934
9401323e 4935\fvector?
8f85c0c6
NJ
4936@deffn {Scheme Procedure} vector? obj
4937@deffnx {C Function} scm_vector_p (obj)
9401323e
NJ
4938Return @code{#t} if @var{obj} is a vector, otherwise return
4939@code{#f}.
780ee65e
NJ
4940@end deffn
4941
9401323e 4942\flist->vector
8f85c0c6 4943@deffn {Scheme Procedure} list->vector
9401323e 4944implemented by the C function "scm_vector"
780ee65e
NJ
4945@end deffn
4946
9401323e 4947\fvector
8f85c0c6
NJ
4948@deffn {Scheme Procedure} vector . l
4949@deffnx {Scheme Procedure} list->vector l
4950@deffnx {C Function} scm_vector (l)
4951Return a newly allocated vector composed of the
9401323e
NJ
4952given arguments. Analogous to @code{list}.
4953
4954@lisp
4955(vector 'a 'b 'c) @result{} #(a b c)
4956@end lisp
780ee65e
NJ
4957@end deffn
4958
9401323e 4959\fmake-vector
8f85c0c6
NJ
4960@deffn {Scheme Procedure} make-vector k [fill]
4961@deffnx {C Function} scm_make_vector (k, fill)
9401323e 4962Return a newly allocated vector of @var{k} elements. If a
8f85c0c6
NJ
4963second argument is given, then each position is initialized to
4964@var{fill}. Otherwise the initial contents of each position is
9401323e 4965unspecified.
780ee65e
NJ
4966@end deffn
4967
9401323e 4968\fvector->list
8f85c0c6
NJ
4969@deffn {Scheme Procedure} vector->list v
4970@deffnx {C Function} scm_vector_to_list (v)
4971Return a newly allocated list composed of the elements of @var{v}.
9401323e
NJ
4972
4973@lisp
4974(vector->list '#(dah dah didah)) @result{} (dah dah didah)
4975(list->vector '(dididit dah)) @result{} #(dididit dah)
4976@end lisp
780ee65e
NJ
4977@end deffn
4978
9401323e 4979\fvector-fill!
8f85c0c6
NJ
4980@deffn {Scheme Procedure} vector-fill! v fill
4981@deffnx {C Function} scm_vector_fill_x (v, fill)
4982Store @var{fill} in every position of @var{vector}. The value
9401323e 4983returned by @code{vector-fill!} is unspecified.
780ee65e
NJ
4984@end deffn
4985
9401323e 4986\fvector-move-left!
8f85c0c6
NJ
4987@deffn {Scheme Procedure} vector-move-left! vec1 start1 end1 vec2 start2
4988@deffnx {C Function} scm_vector_move_left_x (vec1, start1, end1, vec2, start2)
694a9bb3
NJ
4989Copy elements from @var{vec1}, positions @var{start1} to @var{end1},
4990to @var{vec2} starting at position @var{start2}. @var{start1} and
4991@var{start2} are inclusive indices; @var{end1} is exclusive.
4992
4993@code{vector-move-left!} copies elements in leftmost order.
4994Therefore, in the case where @var{vec1} and @var{vec2} refer to the
4995same vector, @code{vector-move-left!} is usually appropriate when
4996@var{start1} is greater than @var{start2}.
780ee65e
NJ
4997@end deffn
4998
9401323e 4999\fvector-move-right!
8f85c0c6
NJ
5000@deffn {Scheme Procedure} vector-move-right! vec1 start1 end1 vec2 start2
5001@deffnx {C Function} scm_vector_move_right_x (vec1, start1, end1, vec2, start2)
694a9bb3
NJ
5002Copy elements from @var{vec1}, positions @var{start1} to @var{end1},
5003to @var{vec2} starting at position @var{start2}. @var{start1} and
5004@var{start2} are inclusive indices; @var{end1} is exclusive.
5005
5006@code{vector-move-right!} copies elements in rightmost order.
5007Therefore, in the case where @var{vec1} and @var{vec2} refer to the
5008same vector, @code{vector-move-right!} is usually appropriate when
5009@var{start1} is less than @var{start2}.
780ee65e
NJ
5010@end deffn
5011
9401323e 5012\fmajor-version
8f85c0c6
NJ
5013@deffn {Scheme Procedure} major-version
5014@deffnx {C Function} scm_major_version ()
9401323e
NJ
5015Return a string containing Guile's major version number.
5016E.g., the 1 in "1.6.5".
780ee65e
NJ
5017@end deffn
5018
9401323e 5019\fminor-version
8f85c0c6
NJ
5020@deffn {Scheme Procedure} minor-version
5021@deffnx {C Function} scm_minor_version ()
9401323e
NJ
5022Return a string containing Guile's minor version number.
5023E.g., the 6 in "1.6.5".
780ee65e
NJ
5024@end deffn
5025
9401323e 5026\fmicro-version
8f85c0c6
NJ
5027@deffn {Scheme Procedure} micro-version
5028@deffnx {C Function} scm_micro_version ()
9401323e
NJ
5029Return a string containing Guile's micro version number.
5030E.g., the 5 in "1.6.5".
780ee65e
NJ
5031@end deffn
5032
9401323e 5033\fversion
8f85c0c6
NJ
5034@deffn {Scheme Procedure} version
5035@deffnx {Scheme Procedure} major-version
5036@deffnx {Scheme Procedure} minor-version
5037@deffnx {Scheme Procedure} micro-version
5038@deffnx {C Function} scm_version ()
72dd0a03
NJ
5039Return a string describing Guile's version number, or its major, minor
5040or micro version number, respectively.
780ee65e 5041
9401323e 5042@lisp
72dd0a03 5043(version) @result{} "1.6.0"
9401323e 5044(major-version) @result{} "1"
72dd0a03
NJ
5045(minor-version) @result{} "6"
5046(micro-version) @result{} "0"
9401323e 5047@end lisp
780ee65e
NJ
5048@end deffn
5049
9401323e 5050\fmake-soft-port
8f85c0c6
NJ
5051@deffn {Scheme Procedure} make-soft-port pv modes
5052@deffnx {C Function} scm_make_soft_port (pv, modes)
9401323e
NJ
5053Return a port capable of receiving or delivering characters as
5054specified by the @var{modes} string (@pxref{File Ports,
5055open-file}). @var{pv} must be a vector of length 5. Its
5056components are as follows:
780ee65e 5057
9401323e
NJ
5058@enumerate 0
5059@item
5060procedure accepting one character for output
5061@item
5062procedure accepting a string for output
5063@item
5064thunk for flushing output
5065@item
5066thunk for getting one character
5067@item
5068thunk for closing port (not by garbage collection)
5069@end enumerate
780ee65e 5070
9401323e
NJ
5071For an output-only port only elements 0, 1, 2, and 4 need be
5072procedures. For an input-only port only elements 3 and 4 need
5073be procedures. Thunks 2 and 4 can instead be @code{#f} if
5074there is no useful operation for them to perform.
7a095584 5075
9401323e
NJ
5076If thunk 3 returns @code{#f} or an @code{eof-object}
5077(@pxref{Input, eof-object?, ,r5rs, The Revised^5 Report on
5078Scheme}) it indicates that the port has reached end-of-file.
5079For example:
780ee65e 5080
9401323e
NJ
5081@lisp
5082(define stdout (current-output-port))
5083(define p (make-soft-port
5084 (vector
5085 (lambda (c) (write c stdout))
5086 (lambda (s) (display s stdout))
5087 (lambda () (display "." stdout))
5088 (lambda () (char-upcase (read-char)))
5089 (lambda () (display "@@" stdout)))
5090 "rw"))
5091
5092(write p p) @result{} #<input-output: soft 8081e20>
5093@end lisp
780ee65e
NJ
5094@end deffn
5095
9401323e 5096\fmake-weak-vector
8f85c0c6
NJ
5097@deffn {Scheme Procedure} make-weak-vector size [fill]
5098@deffnx {C Function} scm_make_weak_vector (size, fill)
9401323e
NJ
5099Return a weak vector with @var{size} elements. If the optional
5100argument @var{fill} is given, all entries in the vector will be
5101set to @var{fill}. The default value for @var{fill} is the
5102empty list.
780ee65e
NJ
5103@end deffn
5104
9401323e 5105\flist->weak-vector
8f85c0c6 5106@deffn {Scheme Procedure} list->weak-vector
9401323e 5107implemented by the C function "scm_weak_vector"
780ee65e
NJ
5108@end deffn
5109
9401323e 5110\fweak-vector
8f85c0c6
NJ
5111@deffn {Scheme Procedure} weak-vector . l
5112@deffnx {Scheme Procedure} list->weak-vector l
5113@deffnx {C Function} scm_weak_vector (l)
9401323e
NJ
5114Construct a weak vector from a list: @code{weak-vector} uses
5115the list of its arguments while @code{list->weak-vector} uses
5116its only argument @var{l} (a list) to construct a weak vector
5117the same way @code{list->vector} would.
780ee65e
NJ
5118@end deffn
5119
9401323e 5120\fweak-vector?
8f85c0c6
NJ
5121@deffn {Scheme Procedure} weak-vector? obj
5122@deffnx {C Function} scm_weak_vector_p (obj)
9401323e
NJ
5123Return @code{#t} if @var{obj} is a weak vector. Note that all
5124weak hashes are also weak vectors.
780ee65e
NJ
5125@end deffn
5126
9401323e 5127\fmake-weak-key-hash-table
8f85c0c6
NJ
5128@deffn {Scheme Procedure} make-weak-key-hash-table size
5129@deffnx {Scheme Procedure} make-weak-value-hash-table size
5130@deffnx {Scheme Procedure} make-doubly-weak-hash-table size
5131@deffnx {C Function} scm_make_weak_key_hash_table (size)
9401323e
NJ
5132Return a weak hash table with @var{size} buckets. As with any
5133hash table, choosing a good size for the table requires some
5134caution.
780ee65e 5135
9401323e
NJ
5136You can modify weak hash tables in exactly the same way you
5137would modify regular hash tables. (@pxref{Hash Tables})
780ee65e
NJ
5138@end deffn
5139
9401323e 5140\fmake-weak-value-hash-table
8f85c0c6
NJ
5141@deffn {Scheme Procedure} make-weak-value-hash-table size
5142@deffnx {C Function} scm_make_weak_value_hash_table (size)
9401323e
NJ
5143Return a hash table with weak values with @var{size} buckets.
5144(@pxref{Hash Tables})
780ee65e
NJ
5145@end deffn
5146
9401323e 5147\fmake-doubly-weak-hash-table
8f85c0c6
NJ
5148@deffn {Scheme Procedure} make-doubly-weak-hash-table size
5149@deffnx {C Function} scm_make_doubly_weak_hash_table (size)
9401323e
NJ
5150Return a hash table with weak keys and values with @var{size}
5151buckets. (@pxref{Hash Tables})
780ee65e
NJ
5152@end deffn
5153
9401323e 5154\fweak-key-hash-table?
8f85c0c6
NJ
5155@deffn {Scheme Procedure} weak-key-hash-table? obj
5156@deffnx {Scheme Procedure} weak-value-hash-table? obj
5157@deffnx {Scheme Procedure} doubly-weak-hash-table? obj
5158@deffnx {C Function} scm_weak_key_hash_table_p (obj)
9401323e
NJ
5159Return @code{#t} if @var{obj} is the specified weak hash
5160table. Note that a doubly weak hash table is neither a weak key
5161nor a weak value hash table.
780ee65e
NJ
5162@end deffn
5163
9401323e 5164\fweak-value-hash-table?
8f85c0c6
NJ
5165@deffn {Scheme Procedure} weak-value-hash-table? obj
5166@deffnx {C Function} scm_weak_value_hash_table_p (obj)
9401323e 5167Return @code{#t} if @var{obj} is a weak value hash table.
780ee65e
NJ
5168@end deffn
5169
9401323e 5170\fdoubly-weak-hash-table?
8f85c0c6
NJ
5171@deffn {Scheme Procedure} doubly-weak-hash-table? obj
5172@deffnx {C Function} scm_doubly_weak_hash_table_p (obj)
9401323e 5173Return @code{#t} if @var{obj} is a doubly weak hash table.
780ee65e
NJ
5174@end deffn
5175
9401323e 5176\fregexp?
8f85c0c6
NJ
5177@deffn {Scheme Procedure} regexp? obj
5178@deffnx {C Function} scm_regexp_p (obj)
9401323e
NJ
5179Return @code{#t} if @var{obj} is a compiled regular expression,
5180or @code{#f} otherwise.
780ee65e
NJ
5181@end deffn
5182
9401323e 5183\fmake-regexp
8f85c0c6
NJ
5184@deffn {Scheme Procedure} make-regexp pat . flags
5185@deffnx {C Function} scm_make_regexp (pat, flags)
9401323e
NJ
5186Compile the regular expression described by @var{pat}, and
5187return the compiled regexp structure. If @var{pat} does not
5188describe a legal regular expression, @code{make-regexp} throws
5189a @code{regular-expression-syntax} error.
780ee65e 5190
9401323e
NJ
5191The @var{flags} arguments change the behavior of the compiled
5192regular expression. The following flags may be supplied:
780ee65e 5193
9401323e
NJ
5194@table @code
5195@item regexp/icase
5196Consider uppercase and lowercase letters to be the same when
5197matching.
5198@item regexp/newline
5199If a newline appears in the target string, then permit the
5200@samp{^} and @samp{$} operators to match immediately after or
5201immediately before the newline, respectively. Also, the
5202@samp{.} and @samp{[^...]} operators will never match a newline
5203character. The intent of this flag is to treat the target
5204string as a buffer containing many lines of text, and the
5205regular expression as a pattern that may match a single one of
5206those lines.
5207@item regexp/basic
5208Compile a basic (``obsolete'') regexp instead of the extended
5209(``modern'') regexps that are the default. Basic regexps do
5210not consider @samp{|}, @samp{+} or @samp{?} to be special
5211characters, and require the @samp{@{...@}} and @samp{(...)}
5212metacharacters to be backslash-escaped (@pxref{Backslash
5213Escapes}). There are several other differences between basic
5214and extended regular expressions, but these are the most
5215significant.
5216@item regexp/extended
5217Compile an extended regular expression rather than a basic
5218regexp. This is the default behavior; this flag will not
5219usually be needed. If a call to @code{make-regexp} includes
5220both @code{regexp/basic} and @code{regexp/extended} flags, the
5221one which comes last will override the earlier one.
5222@end table
780ee65e
NJ
5223@end deffn
5224
9401323e 5225\fregexp-exec
8f85c0c6
NJ
5226@deffn {Scheme Procedure} regexp-exec rx str [start [flags]]
5227@deffnx {C Function} scm_regexp_exec (rx, str, start, flags)
9401323e
NJ
5228Match the compiled regular expression @var{rx} against
5229@code{str}. If the optional integer @var{start} argument is
5230provided, begin matching from that position in the string.
5231Return a match structure describing the results of the match,
5232or @code{#f} if no match could be found.
780ee65e 5233
9401323e
NJ
5234The @var{flags} arguments change the matching behavior.
5235The following flags may be supplied:
780ee65e 5236
9401323e
NJ
5237@table @code
5238@item regexp/notbol
5239Operator @samp{^} always fails (unless @code{regexp/newline}
5240is used). Use this when the beginning of the string should
5241not be considered the beginning of a line.
5242@item regexp/noteol
5243Operator @samp{$} always fails (unless @code{regexp/newline}
5244is used). Use this when the end of the string should not be
5245considered the end of a line.
5246@end table
780ee65e
NJ
5247@end deffn
5248
9401323e 5249\farray-fill!
8f85c0c6
NJ
5250@deffn {Scheme Procedure} array-fill! ra fill
5251@deffnx {C Function} scm_array_fill_x (ra, fill)
5252Store @var{fill} in every element of @var{array}. The value returned
9401323e 5253is unspecified.
780ee65e
NJ
5254@end deffn
5255
9401323e 5256\farray-copy-in-order!
8f85c0c6 5257@deffn {Scheme Procedure} array-copy-in-order!
9401323e 5258implemented by the C function "scm_array_copy_x"
780ee65e
NJ
5259@end deffn
5260
9401323e 5261\farray-copy!
8f85c0c6
NJ
5262@deffn {Scheme Procedure} array-copy! src dst
5263@deffnx {Scheme Procedure} array-copy-in-order! src dst
5264@deffnx {C Function} scm_array_copy_x (src, dst)
5265Copy every element from vector or array @var{source} to the
9401323e
NJ
5266corresponding element of @var{destination}. @var{destination} must have
5267the same rank as @var{source}, and be at least as large in each
5268dimension. The order is unspecified.
5269@end deffn
7a095584 5270
9401323e 5271\farray-map-in-order!
8f85c0c6 5272@deffn {Scheme Procedure} array-map-in-order!
9401323e
NJ
5273implemented by the C function "scm_array_map_x"
5274@end deffn
780ee65e 5275
9401323e 5276\farray-map!
8f85c0c6
NJ
5277@deffn {Scheme Procedure} array-map! ra0 proc . lra
5278@deffnx {Scheme Procedure} array-map-in-order! ra0 proc . lra
5279@deffnx {C Function} scm_array_map_x (ra0, proc, lra)
9401323e
NJ
5280@var{array1}, @dots{} must have the same number of dimensions as
5281@var{array0} and have a range for each index which includes the range
5282for the corresponding index in @var{array0}. @var{proc} is applied to
5283each tuple of elements of @var{array1} @dots{} and the result is stored
5284as the corresponding element in @var{array0}. The value returned is
5285unspecified. The order of application is unspecified.
5286@end deffn
780ee65e 5287
9401323e 5288\farray-for-each
8f85c0c6
NJ
5289@deffn {Scheme Procedure} array-for-each proc ra0 . lra
5290@deffnx {C Function} scm_array_for_each (proc, ra0, lra)
5291Apply @var{proc} to each tuple of elements of @var{array0} @dots{}
9401323e 5292in row-major order. The value returned is unspecified.
780ee65e
NJ
5293@end deffn
5294
9401323e 5295\farray-index-map!
8f85c0c6
NJ
5296@deffn {Scheme Procedure} array-index-map! ra proc
5297@deffnx {C Function} scm_array_index_map_x (ra, proc)
5298Apply @var{proc} to the indices of each element of @var{array} in
9401323e
NJ
5299turn, storing the result in the corresponding element. The value
5300returned and the order of application are unspecified.
7a095584 5301
9401323e 5302One can implement @var{array-indexes} as
ae9f3a15 5303@lisp
9401323e
NJ
5304(define (array-indexes array)
5305 (let ((ra (apply make-array #f (array-shape array))))
5306 (array-index-map! ra (lambda x x))
5307 ra))
5308@end lisp
5309Another example:
5310@lisp
5311(define (apl:index-generator n)
5312 (let ((v (make-uniform-vector n 1)))
5313 (array-index-map! v (lambda (i) i))
5314 v))
ae9f3a15 5315@end lisp
780ee65e
NJ
5316@end deffn
5317
9401323e 5318\funiform-vector-length
8f85c0c6
NJ
5319@deffn {Scheme Procedure} uniform-vector-length v
5320@deffnx {C Function} scm_uniform_vector_length (v)
9401323e 5321Return the number of elements in @var{uve}.
780ee65e
NJ
5322@end deffn
5323
9401323e 5324\farray?
8f85c0c6
NJ
5325@deffn {Scheme Procedure} array? v [prot]
5326@deffnx {C Function} scm_array_p (v, prot)
9401323e
NJ
5327Return @code{#t} if the @var{obj} is an array, and @code{#f} if
5328not. The @var{prototype} argument is used with uniform arrays
5329and is described elsewhere.
780ee65e
NJ
5330@end deffn
5331
9401323e 5332\farray-rank
8f85c0c6
NJ
5333@deffn {Scheme Procedure} array-rank ra
5334@deffnx {C Function} scm_array_rank (ra)
9401323e
NJ
5335Return the number of dimensions of @var{obj}. If @var{obj} is
5336not an array, @code{0} is returned.
780ee65e
NJ
5337@end deffn
5338
9401323e 5339\farray-dimensions
8f85c0c6
NJ
5340@deffn {Scheme Procedure} array-dimensions ra
5341@deffnx {C Function} scm_array_dimensions (ra)
9401323e
NJ
5342@code{Array-dimensions} is similar to @code{array-shape} but replaces
5343elements with a @code{0} minimum with one greater than the maximum. So:
ae9f3a15 5344@lisp
9401323e 5345(array-dimensions (make-array 'foo '(-1 3) 5)) @result{} ((-1 3) 5)
ae9f3a15 5346@end lisp
780ee65e
NJ
5347@end deffn
5348
9401323e 5349\fshared-array-root
8f85c0c6
NJ
5350@deffn {Scheme Procedure} shared-array-root ra
5351@deffnx {C Function} scm_shared_array_root (ra)
9401323e 5352Return the root vector of a shared array.
780ee65e
NJ
5353@end deffn
5354
9401323e 5355\fshared-array-offset
8f85c0c6
NJ
5356@deffn {Scheme Procedure} shared-array-offset ra
5357@deffnx {C Function} scm_shared_array_offset (ra)
9401323e 5358Return the root vector index of the first element in the array.
780ee65e
NJ
5359@end deffn
5360
9401323e 5361\fshared-array-increments
8f85c0c6
NJ
5362@deffn {Scheme Procedure} shared-array-increments ra
5363@deffnx {C Function} scm_shared_array_increments (ra)
9401323e 5364For each dimension, return the distance between elements in the root vector.
780ee65e
NJ
5365@end deffn
5366
9401323e 5367\fdimensions->uniform-array
8f85c0c6
NJ
5368@deffn {Scheme Procedure} dimensions->uniform-array dims prot [fill]
5369@deffnx {Scheme Procedure} make-uniform-vector length prototype [fill]
5370@deffnx {C Function} scm_dimensions_to_uniform_array (dims, prot, fill)
9401323e
NJ
5371Create and return a uniform array or vector of type
5372corresponding to @var{prototype} with dimensions @var{dims} or
5373length @var{length}. If @var{fill} is supplied, it's used to
5374fill the array, otherwise @var{prototype} is used.
780ee65e
NJ
5375@end deffn
5376
9401323e 5377\fmake-shared-array
8f85c0c6
NJ
5378@deffn {Scheme Procedure} make-shared-array oldra mapfunc . dims
5379@deffnx {C Function} scm_make_shared_array (oldra, mapfunc, dims)
9401323e
NJ
5380@code{make-shared-array} can be used to create shared subarrays of other
5381arrays. The @var{mapper} is a function that translates coordinates in
5382the new array into coordinates in the old array. A @var{mapper} must be
5383linear, and its range must stay within the bounds of the old array, but
5384it can be otherwise arbitrary. A simple example:
ae9f3a15 5385@lisp
9401323e
NJ
5386(define fred (make-array #f 8 8))
5387(define freds-diagonal
5388 (make-shared-array fred (lambda (i) (list i i)) 8))
5389(array-set! freds-diagonal 'foo 3)
5390(array-ref fred 3 3) @result{} foo
5391(define freds-center
5392 (make-shared-array fred (lambda (i j) (list (+ 3 i) (+ 3 j))) 2 2))
5393(array-ref freds-center 0 0) @result{} foo
ae9f3a15 5394@end lisp
780ee65e
NJ
5395@end deffn
5396
9401323e 5397\ftranspose-array
8f85c0c6
NJ
5398@deffn {Scheme Procedure} transpose-array ra . args
5399@deffnx {C Function} scm_transpose_array (ra, args)
9401323e
NJ
5400Return an array sharing contents with @var{array}, but with
5401dimensions arranged in a different order. There must be one
5402@var{dim} argument for each dimension of @var{array}.
5403@var{dim0}, @var{dim1}, @dots{} should be integers between 0
5404and the rank of the array to be returned. Each integer in that
5405range must appear at least once in the argument list.
5406
5407The values of @var{dim0}, @var{dim1}, @dots{} correspond to
5408dimensions in the array to be returned, their positions in the
5409argument list to dimensions of @var{array}. Several @var{dim}s
5410may have the same value, in which case the returned array will
5411have smaller rank than @var{array}.
780ee65e 5412
ae9f3a15 5413@lisp
9401323e
NJ
5414(transpose-array '#2((a b) (c d)) 1 0) @result{} #2((a c) (b d))
5415(transpose-array '#2((a b) (c d)) 0 0) @result{} #1(a d)
5416(transpose-array '#3(((a b c) (d e f)) ((1 2 3) (4 5 6))) 1 1 0) @result{}
5417 #2((a 4) (b 5) (c 6))
ae9f3a15 5418@end lisp
780ee65e
NJ
5419@end deffn
5420
9401323e 5421\fenclose-array
8f85c0c6
NJ
5422@deffn {Scheme Procedure} enclose-array ra . axes
5423@deffnx {C Function} scm_enclose_array (ra, axes)
9401323e
NJ
5424@var{dim0}, @var{dim1} @dots{} should be nonnegative integers less than
5425the rank of @var{array}. @var{enclose-array} returns an array
5426resembling an array of shared arrays. The dimensions of each shared
5427array are the same as the @var{dim}th dimensions of the original array,
5428the dimensions of the outer array are the same as those of the original
5429array that did not match a @var{dim}.
780ee65e 5430
9401323e
NJ
5431An enclosed array is not a general Scheme array. Its elements may not
5432be set using @code{array-set!}. Two references to the same element of
5433an enclosed array will be @code{equal?} but will not in general be
5434@code{eq?}. The value returned by @var{array-prototype} when given an
5435enclosed array is unspecified.
7a095584 5436
9401323e 5437examples:
ae9f3a15 5438@lisp
9401323e
NJ
5439(enclose-array '#3(((a b c) (d e f)) ((1 2 3) (4 5 6))) 1) @result{}
5440 #<enclosed-array (#1(a d) #1(b e) #1(c f)) (#1(1 4) #1(2 5) #1(3 6))>
5441
5442(enclose-array '#3(((a b c) (d e f)) ((1 2 3) (4 5 6))) 1 0) @result{}
5443 #<enclosed-array #2((a 1) (d 4)) #2((b 2) (e 5)) #2((c 3) (f 6))>
ae9f3a15 5444@end lisp
780ee65e
NJ
5445@end deffn
5446
9401323e 5447\farray-in-bounds?
8f85c0c6
NJ
5448@deffn {Scheme Procedure} array-in-bounds? v . args
5449@deffnx {C Function} scm_array_in_bounds_p (v, args)
9401323e
NJ
5450Return @code{#t} if its arguments would be acceptable to
5451@code{array-ref}.
780ee65e
NJ
5452@end deffn
5453
9401323e 5454\farray-ref
8f85c0c6 5455@deffn {Scheme Procedure} array-ref
9401323e 5456implemented by the C function "scm_uniform_vector_ref"
780ee65e
NJ
5457@end deffn
5458
9401323e 5459\funiform-vector-ref
8f85c0c6
NJ
5460@deffn {Scheme Procedure} uniform-vector-ref v args
5461@deffnx {Scheme Procedure} array-ref v . args
5462@deffnx {C Function} scm_uniform_vector_ref (v, args)
9401323e
NJ
5463Return the element at the @code{(index1, index2)} element in
5464@var{array}.
780ee65e
NJ
5465@end deffn
5466
9401323e 5467\funiform-array-set1!
8f85c0c6 5468@deffn {Scheme Procedure} uniform-array-set1!
9401323e 5469implemented by the C function "scm_array_set_x"
780ee65e
NJ
5470@end deffn
5471
9401323e 5472\farray-set!
8f85c0c6
NJ
5473@deffn {Scheme Procedure} array-set! v obj . args
5474@deffnx {Scheme Procedure} uniform-array-set1! v obj args
5475@deffnx {C Function} scm_array_set_x (v, obj, args)
5476Set the element at the @code{(index1, index2)} element in @var{array} to
9401323e 5477@var{new-value}. The value returned by array-set! is unspecified.
780ee65e
NJ
5478@end deffn
5479
9401323e 5480\farray-contents
8f85c0c6
NJ
5481@deffn {Scheme Procedure} array-contents ra [strict]
5482@deffnx {C Function} scm_array_contents (ra, strict)
9401323e
NJ
5483If @var{array} may be @dfn{unrolled} into a one dimensional shared array
5484without changing their order (last subscript changing fastest), then
5485@code{array-contents} returns that shared array, otherwise it returns
5486@code{#f}. All arrays made by @var{make-array} and
5487@var{make-uniform-array} may be unrolled, some arrays made by
5488@var{make-shared-array} may not be.
780ee65e 5489
9401323e
NJ
5490If the optional argument @var{strict} is provided, a shared array will
5491be returned only if its elements are stored internally contiguous in
5492memory.
780ee65e
NJ
5493@end deffn
5494
9401323e 5495\funiform-array-read!
8f85c0c6
NJ
5496@deffn {Scheme Procedure} uniform-array-read! ra [port_or_fd [start [end]]]
5497@deffnx {Scheme Procedure} uniform-vector-read! uve [port-or-fdes] [start] [end]
5498@deffnx {C Function} scm_uniform_array_read_x (ra, port_or_fd, start, end)
5499Attempt to read all elements of @var{ura}, in lexicographic order, as
9401323e 5500binary objects from @var{port-or-fdes}.
8f85c0c6
NJ
5501If an end of file is encountered,
5502the objects up to that point are put into @var{ura}
9401323e
NJ
5503(starting at the beginning) and the remainder of the array is
5504unchanged.
780ee65e 5505
9401323e
NJ
5506The optional arguments @var{start} and @var{end} allow
5507a specified region of a vector (or linearized array) to be read,
5508leaving the remainder of the vector unchanged.
780ee65e 5509
9401323e
NJ
5510@code{uniform-array-read!} returns the number of objects read.
5511@var{port-or-fdes} may be omitted, in which case it defaults to the value
5512returned by @code{(current-input-port)}.
780ee65e
NJ
5513@end deffn
5514
9401323e 5515\funiform-array-write
8f85c0c6
NJ
5516@deffn {Scheme Procedure} uniform-array-write v [port_or_fd [start [end]]]
5517@deffnx {Scheme Procedure} uniform-vector-write uve [port-or-fdes] [start] [end]
5518@deffnx {C Function} scm_uniform_array_write (v, port_or_fd, start, end)
9401323e
NJ
5519Writes all elements of @var{ura} as binary objects to
5520@var{port-or-fdes}.
780ee65e 5521
9401323e
NJ
5522The optional arguments @var{start}
5523and @var{end} allow
5524a specified region of a vector (or linearized array) to be written.
780ee65e 5525
9401323e
NJ
5526The number of objects actually written is returned.
5527@var{port-or-fdes} may be
5528omitted, in which case it defaults to the value returned by
5529@code{(current-output-port)}.
780ee65e
NJ
5530@end deffn
5531
9401323e 5532\fbit-count
8f85c0c6
NJ
5533@deffn {Scheme Procedure} bit-count b bitvector
5534@deffnx {C Function} scm_bit_count (b, bitvector)
9401323e
NJ
5535Return the number of occurrences of the boolean @var{b} in
5536@var{bitvector}.
780ee65e
NJ
5537@end deffn
5538
9401323e 5539\fbit-position
8f85c0c6
NJ
5540@deffn {Scheme Procedure} bit-position item v k
5541@deffnx {C Function} scm_bit_position (item, v, k)
9401323e
NJ
5542Return the minimum index of an occurrence of @var{bool} in
5543@var{bv} which is at least @var{k}. If no @var{bool} occurs
5544within the specified range @code{#f} is returned.
780ee65e
NJ
5545@end deffn
5546
9401323e 5547\fbit-set*!
8f85c0c6
NJ
5548@deffn {Scheme Procedure} bit-set*! v kv obj
5549@deffnx {C Function} scm_bit_set_star_x (v, kv, obj)
9401323e
NJ
5550If uve is a bit-vector @var{bv} and uve must be of the same
5551length. If @var{bool} is @code{#t}, uve is OR'ed into
5552@var{bv}; If @var{bool} is @code{#f}, the inversion of uve is
5553AND'ed into @var{bv}.
5554
8f85c0c6 5555If uve is a unsigned long integer vector all the elements of uve
9401323e
NJ
5556must be between 0 and the @code{length} of @var{bv}. The bits
5557of @var{bv} corresponding to the indexes in uve are set to
5558@var{bool}. The return value is unspecified.
780ee65e
NJ
5559@end deffn
5560
9401323e 5561\fbit-count*
8f85c0c6
NJ
5562@deffn {Scheme Procedure} bit-count* v kv obj
5563@deffnx {C Function} scm_bit_count_star (v, kv, obj)
9401323e
NJ
5564Return
5565@lisp
5566(bit-count (bit-set*! (if bool bv (bit-invert! bv)) uve #t) #t).
5567@end lisp
5568@var{bv} is not modified.
780ee65e
NJ
5569@end deffn
5570
9401323e 5571\fbit-invert!
8f85c0c6
NJ
5572@deffn {Scheme Procedure} bit-invert! v
5573@deffnx {C Function} scm_bit_invert_x (v)
5574Modify @var{bv} by replacing each element with its negation.
780ee65e
NJ
5575@end deffn
5576
9401323e 5577\farray->list
8f85c0c6
NJ
5578@deffn {Scheme Procedure} array->list v
5579@deffnx {C Function} scm_t_arrayo_list (v)
9401323e
NJ
5580Return a list consisting of all the elements, in order, of
5581@var{array}.
780ee65e
NJ
5582@end deffn
5583
9401323e 5584\flist->uniform-array
8f85c0c6
NJ
5585@deffn {Scheme Procedure} list->uniform-array ndim prot lst
5586@deffnx {Scheme Procedure} list->uniform-vector prot lst
5587@deffnx {C Function} scm_list_to_uniform_array (ndim, prot, lst)
9401323e
NJ
5588Return a uniform array of the type indicated by prototype
5589@var{prot} with elements the same as those of @var{lst}.
5590Elements must be of the appropriate type, no coercions are
5591done.
5592@end deffn
780ee65e 5593
9401323e 5594\farray-prototype
8f85c0c6
NJ
5595@deffn {Scheme Procedure} array-prototype ra
5596@deffnx {C Function} scm_array_prototype (ra)
9401323e
NJ
5597Return an object that would produce an array of the same type
5598as @var{array}, if used as the @var{prototype} for
5599@code{make-uniform-array}.
780ee65e
NJ
5600@end deffn
5601
9401323e 5602\fchown
8f85c0c6
NJ
5603@deffn {Scheme Procedure} chown object owner group
5604@deffnx {C Function} scm_chown (object, owner, group)
9401323e
NJ
5605Change the ownership and group of the file referred to by @var{object} to
5606the integer values @var{owner} and @var{group}. @var{object} can be
5607a string containing a file name or, if the platform
5608supports fchown, a port or integer file descriptor
5609which is open on the file. The return value
5610is unspecified.
5611
5612If @var{object} is a symbolic link, either the
5613ownership of the link or the ownership of the referenced file will be
5614changed depending on the operating system (lchown is
5615unsupported at present). If @var{owner} or @var{group} is specified
5616as @code{-1}, then that ID is not changed.
780ee65e
NJ
5617@end deffn
5618
9401323e 5619\fchmod
8f85c0c6
NJ
5620@deffn {Scheme Procedure} chmod object mode
5621@deffnx {C Function} scm_chmod (object, mode)
9401323e
NJ
5622Changes the permissions of the file referred to by @var{obj}.
5623@var{obj} can be a string containing a file name or a port or integer file
5624descriptor which is open on a file (in which case @code{fchmod} is used
5625as the underlying system call).
5626@var{mode} specifies
5627the new permissions as a decimal number, e.g., @code{(chmod "foo" #o755)}.
5628The return value is unspecified.
780ee65e
NJ
5629@end deffn
5630
9401323e 5631\fumask
8f85c0c6
NJ
5632@deffn {Scheme Procedure} umask [mode]
5633@deffnx {C Function} scm_umask (mode)
9401323e
NJ
5634If @var{mode} is omitted, retuns a decimal number representing the current
5635file creation mask. Otherwise the file creation mask is set to
5636@var{mode} and the previous value is returned.
780ee65e 5637
9401323e
NJ
5638E.g., @code{(umask #o022)} sets the mask to octal 22, decimal 18.
5639@end deffn
780ee65e 5640
9401323e 5641\fopen-fdes
8f85c0c6
NJ
5642@deffn {Scheme Procedure} open-fdes path flags [mode]
5643@deffnx {C Function} scm_open_fdes (path, flags, mode)
9401323e
NJ
5644Similar to @code{open} but return a file descriptor instead of
5645a port.
5646@end deffn
780ee65e 5647
9401323e 5648\fopen
8f85c0c6
NJ
5649@deffn {Scheme Procedure} open path flags [mode]
5650@deffnx {C Function} scm_open (path, flags, mode)
9401323e
NJ
5651Open the file named by @var{path} for reading and/or writing.
5652@var{flags} is an integer specifying how the file should be opened.
5653@var{mode} is an integer specifying the permission bits of the file, if
5654it needs to be created, before the umask is applied. The default is 666
5655(Unix itself has no default).
780ee65e 5656
9401323e
NJ
5657@var{flags} can be constructed by combining variables using @code{logior}.
5658Basic flags are:
780ee65e 5659
9401323e
NJ
5660@defvar O_RDONLY
5661Open the file read-only.
5662@end defvar
5663@defvar O_WRONLY
5664Open the file write-only.
5665@end defvar
5666@defvar O_RDWR
5667Open the file read/write.
5668@end defvar
5669@defvar O_APPEND
5670Append to the file instead of truncating.
5671@end defvar
5672@defvar O_CREAT
5673Create the file if it does not already exist.
5674@end defvar
780ee65e 5675
9401323e
NJ
5676See the Unix documentation of the @code{open} system call
5677for additional flags.
780ee65e
NJ
5678@end deffn
5679
9401323e 5680\fclose
8f85c0c6
NJ
5681@deffn {Scheme Procedure} close fd_or_port
5682@deffnx {C Function} scm_close (fd_or_port)
5683Similar to close-port (@pxref{Closing, close-port}),
9401323e
NJ
5684but also works on file descriptors. A side
5685effect of closing a file descriptor is that any ports using that file
5686descriptor are moved to a different file descriptor and have
5687their revealed counts set to zero.
5688@end deffn
5689
5690\fclose-fdes
8f85c0c6
NJ
5691@deffn {Scheme Procedure} close-fdes fd
5692@deffnx {C Function} scm_close_fdes (fd)
9401323e
NJ
5693A simple wrapper for the @code{close} system call.
5694Close file descriptor @var{fd}, which must be an integer.
5695Unlike close (@pxref{Ports and File Descriptors, close}),
5696the file descriptor will be closed even if a port is using it.
5697The return value is unspecified.
5698@end deffn
5699
5700\fstat
8f85c0c6
NJ
5701@deffn {Scheme Procedure} stat object
5702@deffnx {C Function} scm_stat (object)
9401323e
NJ
5703Return an object containing various information about the file
5704determined by @var{obj}. @var{obj} can be a string containing
5705a file name or a port or integer file descriptor which is open
5706on a file (in which case @code{fstat} is used as the underlying
5707system call).
5708
5709The object returned by @code{stat} can be passed as a single
5710parameter to the following procedures, all of which return
5711integers:
5712
5713@table @code
5714@item stat:dev
5715The device containing the file.
5716@item stat:ino
5717The file serial number, which distinguishes this file from all
5718other files on the same device.
5719@item stat:mode
5720The mode of the file. This includes file type information and
5721the file permission bits. See @code{stat:type} and
5722@code{stat:perms} below.
5723@item stat:nlink
5724The number of hard links to the file.
5725@item stat:uid
5726The user ID of the file's owner.
5727@item stat:gid
5728The group ID of the file.
5729@item stat:rdev
5730Device ID; this entry is defined only for character or block
5731special files.
5732@item stat:size
5733The size of a regular file in bytes.
5734@item stat:atime
5735The last access time for the file.
5736@item stat:mtime
5737The last modification time for the file.
5738@item stat:ctime
5739The last modification time for the attributes of the file.
5740@item stat:blksize
5741The optimal block size for reading or writing the file, in
5742bytes.
5743@item stat:blocks
5744The amount of disk space that the file occupies measured in
5745units of 512 byte blocks.
5746@end table
5747
5748In addition, the following procedures return the information
5749from stat:mode in a more convenient form:
5750
5751@table @code
5752@item stat:type
5753A symbol representing the type of file. Possible values are
5754regular, directory, symlink, block-special, char-special, fifo,
5755socket and unknown
5756@item stat:perms
5757An integer representing the access permission bits.
5758@end table
5759@end deffn
5760
5761\flink
8f85c0c6
NJ
5762@deffn {Scheme Procedure} link oldpath newpath
5763@deffnx {C Function} scm_link (oldpath, newpath)
9401323e
NJ
5764Creates a new name @var{newpath} in the file system for the
5765file named by @var{oldpath}. If @var{oldpath} is a symbolic
5766link, the link may or may not be followed depending on the
5767system.
5768@end deffn
5769
5770\frename-file
8f85c0c6
NJ
5771@deffn {Scheme Procedure} rename-file oldname newname
5772@deffnx {C Function} scm_rename (oldname, newname)
9401323e
NJ
5773Renames the file specified by @var{oldname} to @var{newname}.
5774The return value is unspecified.
5775@end deffn
5776
5777\fdelete-file
8f85c0c6
NJ
5778@deffn {Scheme Procedure} delete-file str
5779@deffnx {C Function} scm_delete_file (str)
9401323e
NJ
5780Deletes (or "unlinks") the file specified by @var{path}.
5781@end deffn
5782
5783\fmkdir
8f85c0c6
NJ
5784@deffn {Scheme Procedure} mkdir path [mode]
5785@deffnx {C Function} scm_mkdir (path, mode)
9401323e
NJ
5786Create a new directory named by @var{path}. If @var{mode} is omitted
5787then the permissions of the directory file are set using the current
5788umask. Otherwise they are set to the decimal value specified with
5789@var{mode}. The return value is unspecified.
5790@end deffn
5791
5792\frmdir
8f85c0c6
NJ
5793@deffn {Scheme Procedure} rmdir path
5794@deffnx {C Function} scm_rmdir (path)
9401323e
NJ
5795Remove the existing directory named by @var{path}. The directory must
5796be empty for this to succeed. The return value is unspecified.
5797@end deffn
5798
5799\fdirectory-stream?
8f85c0c6
NJ
5800@deffn {Scheme Procedure} directory-stream? obj
5801@deffnx {C Function} scm_directory_stream_p (obj)
9401323e
NJ
5802Return a boolean indicating whether @var{object} is a directory
5803stream as returned by @code{opendir}.
5804@end deffn
5805
5806\fopendir
8f85c0c6
NJ
5807@deffn {Scheme Procedure} opendir dirname
5808@deffnx {C Function} scm_opendir (dirname)
9401323e
NJ
5809Open the directory specified by @var{path} and return a directory
5810stream.
5811@end deffn
5812
5813\freaddir
8f85c0c6
NJ
5814@deffn {Scheme Procedure} readdir port
5815@deffnx {C Function} scm_readdir (port)
9401323e
NJ
5816Return (as a string) the next directory entry from the directory stream
5817@var{stream}. If there is no remaining entry to be read then the
5818end of file object is returned.
5819@end deffn
5820
5821\frewinddir
8f85c0c6
NJ
5822@deffn {Scheme Procedure} rewinddir port
5823@deffnx {C Function} scm_rewinddir (port)
9401323e
NJ
5824Reset the directory port @var{stream} so that the next call to
5825@code{readdir} will return the first directory entry.
5826@end deffn
5827
5828\fclosedir
8f85c0c6
NJ
5829@deffn {Scheme Procedure} closedir port
5830@deffnx {C Function} scm_closedir (port)
9401323e
NJ
5831Close the directory stream @var{stream}.
5832The return value is unspecified.
5833@end deffn
5834
5835\fchdir
8f85c0c6
NJ
5836@deffn {Scheme Procedure} chdir str
5837@deffnx {C Function} scm_chdir (str)
9401323e
NJ
5838Change the current working directory to @var{path}.
5839The return value is unspecified.
5840@end deffn
5841
5842\fgetcwd
8f85c0c6
NJ
5843@deffn {Scheme Procedure} getcwd
5844@deffnx {C Function} scm_getcwd ()
9401323e
NJ
5845Return the name of the current working directory.
5846@end deffn
5847
5848\fselect
8f85c0c6
NJ
5849@deffn {Scheme Procedure} select reads writes excepts [secs [usecs]]
5850@deffnx {C Function} scm_select (reads, writes, excepts, secs, usecs)
9401323e
NJ
5851This procedure has a variety of uses: waiting for the ability
5852to provide input, accept output, or the existance of
5853exceptional conditions on a collection of ports or file
5854descriptors, or waiting for a timeout to occur.
5855It also returns if interrupted by a signal.
5856
5857@var{reads}, @var{writes} and @var{excepts} can be lists or
5858vectors, with each member a port or a file descriptor.
5859The value returned is a list of three corresponding
5860lists or vectors containing only the members which meet the
5861specified requirement. The ability of port buffers to
5862provide input or accept output is taken into account.
5863Ordering of the input lists or vectors is not preserved.
5864
5865The optional arguments @var{secs} and @var{usecs} specify the
5866timeout. Either @var{secs} can be specified alone, as
5867either an integer or a real number, or both @var{secs} and
5868@var{usecs} can be specified as integers, in which case
5869@var{usecs} is an additional timeout expressed in
5870microseconds. If @var{secs} is omitted or is @code{#f} then
5871select will wait for as long as it takes for one of the other
5872conditions to be satisfied.
5873
5874The scsh version of @code{select} differs as follows:
5875Only vectors are accepted for the first three arguments.
5876The @var{usecs} argument is not supported.
5877Multiple values are returned instead of a list.
5878Duplicates in the input vectors appear only once in output.
5879An additional @code{select!} interface is provided.
5880@end deffn
5881
5882\ffcntl
8f85c0c6
NJ
5883@deffn {Scheme Procedure} fcntl object cmd [value]
5884@deffnx {C Function} scm_fcntl (object, cmd, value)
9401323e
NJ
5885Apply @var{command} to the specified file descriptor or the underlying
5886file descriptor of the specified port. @var{value} is an optional
5887integer argument.
5888
5889Values for @var{command} are:
5890
5891@table @code
5892@item F_DUPFD
5893Duplicate a file descriptor
5894@item F_GETFD
5895Get flags associated with the file descriptor.
5896@item F_SETFD
5897Set flags associated with the file descriptor to @var{value}.
5898@item F_GETFL
5899Get flags associated with the open file.
5900@item F_SETFL
5901Set flags associated with the open file to @var{value}
5902@item F_GETOWN
5903Get the process ID of a socket's owner, for @code{SIGIO} signals.
5904@item F_SETOWN
5905Set the process that owns a socket to @var{value}, for @code{SIGIO} signals.
5906@item FD_CLOEXEC
5907The value used to indicate the "close on exec" flag with @code{F_GETFL} or
5908@code{F_SETFL}.
5909@end table
5910@end deffn
5911
5912\ffsync
8f85c0c6
NJ
5913@deffn {Scheme Procedure} fsync object
5914@deffnx {C Function} scm_fsync (object)
9401323e
NJ
5915Copies any unwritten data for the specified output file descriptor to disk.
5916If @var{port/fd} is a port, its buffer is flushed before the underlying
5917file descriptor is fsync'd.
5918The return value is unspecified.
5919@end deffn
5920
5921\fsymlink
8f85c0c6
NJ
5922@deffn {Scheme Procedure} symlink oldpath newpath
5923@deffnx {C Function} scm_symlink (oldpath, newpath)
9401323e
NJ
5924Create a symbolic link named @var{path-to} with the value (i.e., pointing to)
5925@var{path-from}. The return value is unspecified.
5926@end deffn
5927
5928\freadlink
8f85c0c6
NJ
5929@deffn {Scheme Procedure} readlink path
5930@deffnx {C Function} scm_readlink (path)
9401323e
NJ
5931Return the value of the symbolic link named by @var{path} (a
5932string), i.e., the file that the link points to.
5933@end deffn
5934
5935\flstat
8f85c0c6
NJ
5936@deffn {Scheme Procedure} lstat str
5937@deffnx {C Function} scm_lstat (str)
9401323e
NJ
5938Similar to @code{stat}, but does not follow symbolic links, i.e.,
5939it will return information about a symbolic link itself, not the
5940file it points to. @var{path} must be a string.
5941@end deffn
5942
5943\fcopy-file
8f85c0c6
NJ
5944@deffn {Scheme Procedure} copy-file oldfile newfile
5945@deffnx {C Function} scm_copy_file (oldfile, newfile)
9401323e
NJ
5946Copy the file specified by @var{path-from} to @var{path-to}.
5947The return value is unspecified.
5948@end deffn
5949
5950\fdirname
8f85c0c6
NJ
5951@deffn {Scheme Procedure} dirname filename
5952@deffnx {C Function} scm_dirname (filename)
9401323e
NJ
5953Return the directory name component of the file name
5954@var{filename}. If @var{filename} does not contain a directory
5955component, @code{.} is returned.
5956@end deffn
5957
5958\fbasename
8f85c0c6
NJ
5959@deffn {Scheme Procedure} basename filename [suffix]
5960@deffnx {C Function} scm_basename (filename, suffix)
9401323e
NJ
5961Return the base name of the file name @var{filename}. The
5962base name is the file name without any directory components.
5963If @var{suffix} is privided, and is equal to the end of
5964@var{basename}, it is removed also.
5965@end deffn
5966
5967\fpipe
8f85c0c6
NJ
5968@deffn {Scheme Procedure} pipe
5969@deffnx {C Function} scm_pipe ()
9401323e
NJ
5970Return a newly created pipe: a pair of ports which are linked
5971together on the local machine. The @emph{car} is the input
5972port and the @emph{cdr} is the output port. Data written (and
5973flushed) to the output port can be read from the input port.
5974Pipes are commonly used for communication with a newly forked
5975child process. The need to flush the output port can be
5976avoided by making it unbuffered using @code{setvbuf}.
5977
5978Writes occur atomically provided the size of the data in bytes
5979is not greater than the value of @code{PIPE_BUF}. Note that
5980the output port is likely to block if too much data (typically
5981equal to @code{PIPE_BUF}) has been written but not yet read
5982from the input port.
5983@end deffn
5984
5985\fgetgroups
8f85c0c6
NJ
5986@deffn {Scheme Procedure} getgroups
5987@deffnx {C Function} scm_getgroups ()
9401323e
NJ
5988Return a vector of integers representing the current
5989supplimentary group IDs.
5990@end deffn
5991
5992\fgetpw
8f85c0c6
NJ
5993@deffn {Scheme Procedure} getpw [user]
5994@deffnx {C Function} scm_getpwuid (user)
9401323e
NJ
5995Look up an entry in the user database. @var{obj} can be an integer,
5996a string, or omitted, giving the behaviour of getpwuid, getpwnam
5997or getpwent respectively.
5998@end deffn
5999
6000\fsetpw
8f85c0c6
NJ
6001@deffn {Scheme Procedure} setpw [arg]
6002@deffnx {C Function} scm_setpwent (arg)
9401323e
NJ
6003If called with a true argument, initialize or reset the password data
6004stream. Otherwise, close the stream. The @code{setpwent} and
6005@code{endpwent} procedures are implemented on top of this.
6006@end deffn
6007
6008\fgetgr
8f85c0c6
NJ
6009@deffn {Scheme Procedure} getgr [name]
6010@deffnx {C Function} scm_getgrgid (name)
9401323e
NJ
6011Look up an entry in the group database. @var{obj} can be an integer,
6012a string, or omitted, giving the behaviour of getgrgid, getgrnam
6013or getgrent respectively.
6014@end deffn
6015
6016\fsetgr
8f85c0c6
NJ
6017@deffn {Scheme Procedure} setgr [arg]
6018@deffnx {C Function} scm_setgrent (arg)
9401323e
NJ
6019If called with a true argument, initialize or reset the group data
6020stream. Otherwise, close the stream. The @code{setgrent} and
6021@code{endgrent} procedures are implemented on top of this.
6022@end deffn
6023
6024\fkill
8f85c0c6
NJ
6025@deffn {Scheme Procedure} kill pid sig
6026@deffnx {C Function} scm_kill (pid, sig)
9401323e
NJ
6027Sends a signal to the specified process or group of processes.
6028
6029@var{pid} specifies the processes to which the signal is sent:
6030
6031@table @r
6032@item @var{pid} greater than 0
6033The process whose identifier is @var{pid}.
6034@item @var{pid} equal to 0
6035All processes in the current process group.
6036@item @var{pid} less than -1
6037The process group whose identifier is -@var{pid}
6038@item @var{pid} equal to -1
6039If the process is privileged, all processes except for some special
6040system processes. Otherwise, all processes with the current effective
6041user ID.
6042@end table
6043
6044@var{sig} should be specified using a variable corresponding to
6045the Unix symbolic name, e.g.,
6046
6047@defvar SIGHUP
6048Hang-up signal.
6049@end defvar
6050
6051@defvar SIGINT
6052Interrupt signal.
6053@end defvar
6054@end deffn
6055
6056\fwaitpid
8f85c0c6
NJ
6057@deffn {Scheme Procedure} waitpid pid [options]
6058@deffnx {C Function} scm_waitpid (pid, options)
9401323e
NJ
6059This procedure collects status information from a child process which
6060has terminated or (optionally) stopped. Normally it will
6061suspend the calling process until this can be done. If more than one
6062child process is eligible then one will be chosen by the operating system.
6063
6064The value of @var{pid} determines the behaviour:
6065
6066@table @r
6067@item @var{pid} greater than 0
6068Request status information from the specified child process.
6069@item @var{pid} equal to -1 or WAIT_ANY
6070Request status information for any child process.
6071@item @var{pid} equal to 0 or WAIT_MYPGRP
6072Request status information for any child process in the current process
6073group.
6074@item @var{pid} less than -1
6075Request status information for any child process whose process group ID
6076is -@var{PID}.
6077@end table
6078
6079The @var{options} argument, if supplied, should be the bitwise OR of the
6080values of zero or more of the following variables:
780ee65e 6081
9401323e
NJ
6082@defvar WNOHANG
6083Return immediately even if there are no child processes to be collected.
6084@end defvar
780ee65e 6085
9401323e
NJ
6086@defvar WUNTRACED
6087Report status information for stopped processes as well as terminated
6088processes.
6089@end defvar
780ee65e 6090
9401323e 6091The return value is a pair containing:
780ee65e 6092
9401323e
NJ
6093@enumerate
6094@item
6095The process ID of the child process, or 0 if @code{WNOHANG} was
6096specified and no process was collected.
6097@item
6098The integer status value.
6099@end enumerate
6100@end deffn
780ee65e 6101
9401323e 6102\fstatus:exit-val
8f85c0c6
NJ
6103@deffn {Scheme Procedure} status:exit-val status
6104@deffnx {C Function} scm_status_exit_val (status)
9401323e
NJ
6105Return the exit status value, as would be set if a process
6106ended normally through a call to @code{exit} or @code{_exit},
6107if any, otherwise @code{#f}.
6108@end deffn
780ee65e 6109
9401323e 6110\fstatus:term-sig
8f85c0c6
NJ
6111@deffn {Scheme Procedure} status:term-sig status
6112@deffnx {C Function} scm_status_term_sig (status)
9401323e
NJ
6113Return the signal number which terminated the process, if any,
6114otherwise @code{#f}.
6115@end deffn
780ee65e 6116
9401323e 6117\fstatus:stop-sig
8f85c0c6
NJ
6118@deffn {Scheme Procedure} status:stop-sig status
6119@deffnx {C Function} scm_status_stop_sig (status)
9401323e
NJ
6120Return the signal number which stopped the process, if any,
6121otherwise @code{#f}.
6122@end deffn
780ee65e 6123
9401323e 6124\fgetppid
8f85c0c6
NJ
6125@deffn {Scheme Procedure} getppid
6126@deffnx {C Function} scm_getppid ()
9401323e
NJ
6127Return an integer representing the process ID of the parent
6128process.
6129@end deffn
780ee65e 6130
9401323e 6131\fgetuid
8f85c0c6
NJ
6132@deffn {Scheme Procedure} getuid
6133@deffnx {C Function} scm_getuid ()
9401323e
NJ
6134Return an integer representing the current real user ID.
6135@end deffn
780ee65e 6136
9401323e 6137\fgetgid
8f85c0c6
NJ
6138@deffn {Scheme Procedure} getgid
6139@deffnx {C Function} scm_getgid ()
9401323e
NJ
6140Return an integer representing the current real group ID.
6141@end deffn
780ee65e 6142
9401323e 6143\fgeteuid
8f85c0c6
NJ
6144@deffn {Scheme Procedure} geteuid
6145@deffnx {C Function} scm_geteuid ()
9401323e
NJ
6146Return an integer representing the current effective user ID.
6147If the system does not support effective IDs, then the real ID
6148is returned. @code{(feature? 'EIDs)} reports whether the
6149system supports effective IDs.
6150@end deffn
780ee65e 6151
9401323e 6152\fgetegid
8f85c0c6
NJ
6153@deffn {Scheme Procedure} getegid
6154@deffnx {C Function} scm_getegid ()
9401323e
NJ
6155Return an integer representing the current effective group ID.
6156If the system does not support effective IDs, then the real ID
6157is returned. @code{(feature? 'EIDs)} reports whether the
6158system supports effective IDs.
780ee65e
NJ
6159@end deffn
6160
9401323e 6161\fsetuid
8f85c0c6
NJ
6162@deffn {Scheme Procedure} setuid id
6163@deffnx {C Function} scm_setuid (id)
9401323e
NJ
6164Sets both the real and effective user IDs to the integer @var{id}, provided
6165the process has appropriate privileges.
6166The return value is unspecified.
6167@end deffn
780ee65e 6168
9401323e 6169\fsetgid
8f85c0c6
NJ
6170@deffn {Scheme Procedure} setgid id
6171@deffnx {C Function} scm_setgid (id)
9401323e
NJ
6172Sets both the real and effective group IDs to the integer @var{id}, provided
6173the process has appropriate privileges.
6174The return value is unspecified.
6175@end deffn
780ee65e 6176
9401323e 6177\fseteuid
8f85c0c6
NJ
6178@deffn {Scheme Procedure} seteuid id
6179@deffnx {C Function} scm_seteuid (id)
9401323e
NJ
6180Sets the effective user ID to the integer @var{id}, provided the process
6181has appropriate privileges. If effective IDs are not supported, the
6182real ID is set instead -- @code{(feature? 'EIDs)} reports whether the
6183system supports effective IDs.
6184The return value is unspecified.
780ee65e
NJ
6185@end deffn
6186
9401323e 6187\fsetegid
8f85c0c6
NJ
6188@deffn {Scheme Procedure} setegid id
6189@deffnx {C Function} scm_setegid (id)
9401323e
NJ
6190Sets the effective group ID to the integer @var{id}, provided the process
6191has appropriate privileges. If effective IDs are not supported, the
6192real ID is set instead -- @code{(feature? 'EIDs)} reports whether the
6193system supports effective IDs.
6194The return value is unspecified.
780ee65e
NJ
6195@end deffn
6196
9401323e 6197\fgetpgrp
8f85c0c6
NJ
6198@deffn {Scheme Procedure} getpgrp
6199@deffnx {C Function} scm_getpgrp ()
9401323e
NJ
6200Return an integer representing the current process group ID.
6201This is the POSIX definition, not BSD.
780ee65e
NJ
6202@end deffn
6203
9401323e 6204\fsetpgid
8f85c0c6
NJ
6205@deffn {Scheme Procedure} setpgid pid pgid
6206@deffnx {C Function} scm_setpgid (pid, pgid)
9401323e
NJ
6207Move the process @var{pid} into the process group @var{pgid}. @var{pid} or
6208@var{pgid} must be integers: they can be zero to indicate the ID of the
6209current process.
6210Fails on systems that do not support job control.
6211The return value is unspecified.
780ee65e
NJ
6212@end deffn
6213
9401323e 6214\fsetsid
8f85c0c6
NJ
6215@deffn {Scheme Procedure} setsid
6216@deffnx {C Function} scm_setsid ()
9401323e
NJ
6217Creates a new session. The current process becomes the session leader
6218and is put in a new process group. The process will be detached
6219from its controlling terminal if it has one.
6220The return value is an integer representing the new process group ID.
780ee65e
NJ
6221@end deffn
6222
9401323e 6223\fttyname
8f85c0c6
NJ
6224@deffn {Scheme Procedure} ttyname port
6225@deffnx {C Function} scm_ttyname (port)
9401323e
NJ
6226Return a string with the name of the serial terminal device
6227underlying @var{port}.
780ee65e
NJ
6228@end deffn
6229
9401323e 6230\fctermid
8f85c0c6
NJ
6231@deffn {Scheme Procedure} ctermid
6232@deffnx {C Function} scm_ctermid ()
9401323e
NJ
6233Return a string containing the file name of the controlling
6234terminal for the current process.
780ee65e
NJ
6235@end deffn
6236
9401323e 6237\ftcgetpgrp
8f85c0c6
NJ
6238@deffn {Scheme Procedure} tcgetpgrp port
6239@deffnx {C Function} scm_tcgetpgrp (port)
9401323e
NJ
6240Return the process group ID of the foreground process group
6241associated with the terminal open on the file descriptor
6242underlying @var{port}.
7a095584 6243
9401323e
NJ
6244If there is no foreground process group, the return value is a
6245number greater than 1 that does not match the process group ID
6246of any existing process group. This can happen if all of the
6247processes in the job that was formerly the foreground job have
6248terminated, and no other job has yet been moved into the
6249foreground.
6250@end deffn
7a095584 6251
9401323e 6252\ftcsetpgrp
8f85c0c6
NJ
6253@deffn {Scheme Procedure} tcsetpgrp port pgid
6254@deffnx {C Function} scm_tcsetpgrp (port, pgid)
9401323e
NJ
6255Set the foreground process group ID for the terminal used by the file
6256descriptor underlying @var{port} to the integer @var{pgid}.
6257The calling process
6258must be a member of the same session as @var{pgid} and must have the same
6259controlling terminal. The return value is unspecified.
780ee65e
NJ
6260@end deffn
6261
9401323e 6262\fexecl
8f85c0c6
NJ
6263@deffn {Scheme Procedure} execl filename . args
6264@deffnx {C Function} scm_execl (filename, args)
9401323e
NJ
6265Executes the file named by @var{path} as a new process image.
6266The remaining arguments are supplied to the process; from a C program
6267they are accessable as the @code{argv} argument to @code{main}.
6268Conventionally the first @var{arg} is the same as @var{path}.
8f85c0c6 6269All arguments must be strings.
7a095584 6270
9401323e
NJ
6271If @var{arg} is missing, @var{path} is executed with a null
6272argument list, which may have system-dependent side-effects.
7a095584 6273
9401323e
NJ
6274This procedure is currently implemented using the @code{execv} system
6275call, but we call it @code{execl} because of its Scheme calling interface.
780ee65e
NJ
6276@end deffn
6277
9401323e 6278\fexeclp
8f85c0c6
NJ
6279@deffn {Scheme Procedure} execlp filename . args
6280@deffnx {C Function} scm_execlp (filename, args)
9401323e
NJ
6281Similar to @code{execl}, however if
6282@var{filename} does not contain a slash
6283then the file to execute will be located by searching the
6284directories listed in the @code{PATH} environment variable.
6285
6286This procedure is currently implemented using the @code{execvp} system
6287call, but we call it @code{execlp} because of its Scheme calling interface.
6288@end deffn
780ee65e 6289
9401323e 6290\fexecle
8f85c0c6
NJ
6291@deffn {Scheme Procedure} execle filename env . args
6292@deffnx {C Function} scm_execle (filename, env, args)
9401323e
NJ
6293Similar to @code{execl}, but the environment of the new process is
6294specified by @var{env}, which must be a list of strings as returned by the
6295@code{environ} procedure.
780ee65e 6296
9401323e
NJ
6297This procedure is currently implemented using the @code{execve} system
6298call, but we call it @code{execle} because of its Scheme calling interface.
780ee65e
NJ
6299@end deffn
6300
9401323e 6301\fprimitive-fork
8f85c0c6
NJ
6302@deffn {Scheme Procedure} primitive-fork
6303@deffnx {C Function} scm_fork ()
9401323e
NJ
6304Creates a new "child" process by duplicating the current "parent" process.
6305In the child the return value is 0. In the parent the return value is
6306the integer process ID of the child.
780ee65e 6307
9401323e
NJ
6308This procedure has been renamed from @code{fork} to avoid a naming conflict
6309with the scsh fork.
780ee65e
NJ
6310@end deffn
6311
9401323e 6312\funame
8f85c0c6
NJ
6313@deffn {Scheme Procedure} uname
6314@deffnx {C Function} scm_uname ()
9401323e
NJ
6315Return an object with some information about the computer
6316system the program is running on.
780ee65e
NJ
6317@end deffn
6318
9401323e 6319\fenviron
8f85c0c6
NJ
6320@deffn {Scheme Procedure} environ [env]
6321@deffnx {C Function} scm_environ (env)
9401323e
NJ
6322If @var{env} is omitted, return the current environment (in the
6323Unix sense) as a list of strings. Otherwise set the current
6324environment, which is also the default environment for child
6325processes, to the supplied list of strings. Each member of
6326@var{env} should be of the form @code{NAME=VALUE} and values of
6327@code{NAME} should not be duplicated. If @var{env} is supplied
6328then the return value is unspecified.
780ee65e
NJ
6329@end deffn
6330
9401323e 6331\ftmpnam
8f85c0c6
NJ
6332@deffn {Scheme Procedure} tmpnam
6333@deffnx {C Function} scm_tmpnam ()
9401323e
NJ
6334Return a name in the file system that does not match any
6335existing file. However there is no guarantee that another
6336process will not create the file after @code{tmpnam} is called.
6337Care should be taken if opening the file, e.g., use the
6338@code{O_EXCL} open flag or use @code{mkstemp!} instead.
780ee65e
NJ
6339@end deffn
6340
9401323e 6341\fmkstemp!
8f85c0c6
NJ
6342@deffn {Scheme Procedure} mkstemp! tmpl
6343@deffnx {C Function} scm_mkstemp (tmpl)
9401323e
NJ
6344Create a new unique file in the file system and returns a new
6345buffered port open for reading and writing to the file.
6346@var{tmpl} is a string specifying where the file should be
6347created: it must end with @code{XXXXXX} and will be changed in
6348place to return the name of the temporary file.
780ee65e
NJ
6349@end deffn
6350
9401323e 6351\futime
8f85c0c6
NJ
6352@deffn {Scheme Procedure} utime pathname [actime [modtime]]
6353@deffnx {C Function} scm_utime (pathname, actime, modtime)
9401323e
NJ
6354@code{utime} sets the access and modification times for the
6355file named by @var{path}. If @var{actime} or @var{modtime} is
6356not supplied, then the current time is used. @var{actime} and
6357@var{modtime} must be integer time values as returned by the
6358@code{current-time} procedure.
6359@lisp
6360(utime "foo" (- (current-time) 3600))
6361@end lisp
6362will set the access time to one hour in the past and the
6363modification time to the current time.
780ee65e
NJ
6364@end deffn
6365
9401323e 6366\faccess?
8f85c0c6
NJ
6367@deffn {Scheme Procedure} access? path how
6368@deffnx {C Function} scm_access (path, how)
9401323e
NJ
6369Return @code{#t} if @var{path} corresponds to an existing file
6370and the current process has the type of access specified by
6371@var{how}, otherwise @code{#f}. @var{how} should be specified
6372using the values of the variables listed below. Multiple
6373values can be combined using a bitwise or, in which case
6374@code{#t} will only be returned if all accesses are granted.
780ee65e 6375
9401323e
NJ
6376Permissions are checked using the real id of the current
6377process, not the effective id, although it's the effective id
6378which determines whether the access would actually be granted.
780ee65e 6379
9401323e
NJ
6380@defvar R_OK
6381test for read permission.
6382@end defvar
6383@defvar W_OK
6384test for write permission.
6385@end defvar
6386@defvar X_OK
6387test for execute permission.
6388@end defvar
6389@defvar F_OK
6390test for existence of the file.
6391@end defvar
780ee65e
NJ
6392@end deffn
6393
9401323e 6394\fgetpid
8f85c0c6
NJ
6395@deffn {Scheme Procedure} getpid
6396@deffnx {C Function} scm_getpid ()
9401323e 6397Return an integer representing the current process ID.
780ee65e
NJ
6398@end deffn
6399
9401323e 6400\fputenv
8f85c0c6
NJ
6401@deffn {Scheme Procedure} putenv str
6402@deffnx {C Function} scm_putenv (str)
9401323e
NJ
6403Modifies the environment of the current process, which is
6404also the default environment inherited by child processes.
780ee65e 6405
9401323e
NJ
6406If @var{string} is of the form @code{NAME=VALUE} then it will be written
6407directly into the environment, replacing any existing environment string
6408with
6409name matching @code{NAME}. If @var{string} does not contain an equal
6410sign, then any existing string with name matching @var{string} will
6411be removed.
6412
6413The return value is unspecified.
780ee65e
NJ
6414@end deffn
6415
9401323e 6416\fsetlocale
8f85c0c6
NJ
6417@deffn {Scheme Procedure} setlocale category [locale]
6418@deffnx {C Function} scm_setlocale (category, locale)
9401323e
NJ
6419If @var{locale} is omitted, return the current value of the
6420specified locale category as a system-dependent string.
6421@var{category} should be specified using the values
6422@code{LC_COLLATE}, @code{LC_ALL} etc.
6423
6424Otherwise the specified locale category is set to the string
6425@var{locale} and the new value is returned as a
6426system-dependent string. If @var{locale} is an empty string,
6427the locale will be set using envirionment variables.
780ee65e
NJ
6428@end deffn
6429
9401323e 6430\fmknod
8f85c0c6
NJ
6431@deffn {Scheme Procedure} mknod path type perms dev
6432@deffnx {C Function} scm_mknod (path, type, perms, dev)
9401323e
NJ
6433Creates a new special file, such as a file corresponding to a device.
6434@var{path} specifies the name of the file. @var{type} should
6435be one of the following symbols:
6436regular, directory, symlink, block-special, char-special,
6437fifo, or socket. @var{perms} (an integer) specifies the file permissions.
6438@var{dev} (an integer) specifies which device the special file refers
6439to. Its exact interpretation depends on the kind of special file
6440being created.
6441
6442E.g.,
ae9f3a15 6443@lisp
9401323e 6444(mknod "/dev/fd0" 'block-special #o660 (+ (* 2 256) 2))
ae9f3a15 6445@end lisp
7a095584 6446
9401323e
NJ
6447The return value is unspecified.
6448@end deffn
7a095584 6449
9401323e 6450\fnice
8f85c0c6
NJ
6451@deffn {Scheme Procedure} nice incr
6452@deffnx {C Function} scm_nice (incr)
9401323e
NJ
6453Increment the priority of the current process by @var{incr}. A higher
6454priority value means that the process runs less often.
6455The return value is unspecified.
6456@end deffn
7a095584 6457
9401323e 6458\fsync
8f85c0c6
NJ
6459@deffn {Scheme Procedure} sync
6460@deffnx {C Function} scm_sync ()
9401323e
NJ
6461Flush the operating system disk buffers.
6462The return value is unspecified.
780ee65e
NJ
6463@end deffn
6464
9401323e 6465\fcrypt
8f85c0c6
NJ
6466@deffn {Scheme Procedure} crypt key salt
6467@deffnx {C Function} scm_crypt (key, salt)
9401323e
NJ
6468Encrypt @var{key} using @var{salt} as the salt value to the
6469crypt(3) library call.
780ee65e
NJ
6470@end deffn
6471
9401323e 6472\fchroot
8f85c0c6
NJ
6473@deffn {Scheme Procedure} chroot path
6474@deffnx {C Function} scm_chroot (path)
9401323e
NJ
6475Change the root directory to that specified in @var{path}.
6476This directory will be used for path names beginning with
6477@file{/}. The root directory is inherited by all children
6478of the current process. Only the superuser may change the
6479root directory.
6480@end deffn
780ee65e 6481
9401323e 6482\fgetlogin
8f85c0c6
NJ
6483@deffn {Scheme Procedure} getlogin
6484@deffnx {C Function} scm_getlogin ()
9401323e
NJ
6485Return a string containing the name of the user logged in on
6486the controlling terminal of the process, or @code{#f} if this
6487information cannot be obtained.
6488@end deffn
780ee65e 6489
9401323e 6490\fcuserid
8f85c0c6
NJ
6491@deffn {Scheme Procedure} cuserid
6492@deffnx {C Function} scm_cuserid ()
9401323e
NJ
6493Return a string containing a user name associated with the
6494effective user id of the process. Return @code{#f} if this
6495information cannot be obtained.
780ee65e
NJ
6496@end deffn
6497
9401323e 6498\fgetpriority
8f85c0c6
NJ
6499@deffn {Scheme Procedure} getpriority which who
6500@deffnx {C Function} scm_getpriority (which, who)
9401323e
NJ
6501Return the scheduling priority of the process, process group
6502or user, as indicated by @var{which} and @var{who}. @var{which}
6503is one of the variables @code{PRIO_PROCESS}, @code{PRIO_PGRP}
6504or @code{PRIO_USER}, and @var{who} is interpreted relative to
6505@var{which} (a process identifier for @code{PRIO_PROCESS},
6506process group identifier for @code{PRIO_PGRP}, and a user
6507identifier for @code{PRIO_USER}. A zero value of @var{who}
6508denotes the current process, process group, or user. Return
6509the highest priority (lowest numerical value) of any of the
6510specified processes.
780ee65e
NJ
6511@end deffn
6512
9401323e 6513\fsetpriority
8f85c0c6
NJ
6514@deffn {Scheme Procedure} setpriority which who prio
6515@deffnx {C Function} scm_setpriority (which, who, prio)
9401323e
NJ
6516Set the scheduling priority of the process, process group
6517or user, as indicated by @var{which} and @var{who}. @var{which}
6518is one of the variables @code{PRIO_PROCESS}, @code{PRIO_PGRP}
6519or @code{PRIO_USER}, and @var{who} is interpreted relative to
6520@var{which} (a process identifier for @code{PRIO_PROCESS},
6521process group identifier for @code{PRIO_PGRP}, and a user
6522identifier for @code{PRIO_USER}. A zero value of @var{who}
6523denotes the current process, process group, or user.
6524@var{prio} is a value in the range -20 and 20, the default
6525priority is 0; lower priorities cause more favorable
6526scheduling. Sets the priority of all of the specified
6527processes. Only the super-user may lower priorities.
6528The return value is not specified.
780ee65e
NJ
6529@end deffn
6530
9401323e 6531\fgetpass
8f85c0c6
NJ
6532@deffn {Scheme Procedure} getpass prompt
6533@deffnx {C Function} scm_getpass (prompt)
9401323e
NJ
6534Display @var{prompt} to the standard error output and read
6535a password from @file{/dev/tty}. If this file is not
6536accessible, it reads from standard input. The password may be
6537up to 127 characters in length. Additional characters and the
6538terminating newline character are discarded. While reading
6539the password, echoing and the generation of signals by special
6540characters is disabled.
780ee65e
NJ
6541@end deffn
6542
9401323e 6543\fflock
8f85c0c6
NJ
6544@deffn {Scheme Procedure} flock file operation
6545@deffnx {C Function} scm_flock (file, operation)
9401323e
NJ
6546Apply or remove an advisory lock on an open file.
6547@var{operation} specifies the action to be done:
6548@table @code
6549@item LOCK_SH
6550Shared lock. More than one process may hold a shared lock
6551for a given file at a given time.
6552@item LOCK_EX
6553Exclusive lock. Only one process may hold an exclusive lock
6554for a given file at a given time.
6555@item LOCK_UN
6556Unlock the file.
6557@item LOCK_NB
6558Don't block when locking. May be specified by bitwise OR'ing
6559it to one of the other operations.
6560@end table
6561The return value is not specified. @var{file} may be an open
6562file descriptor or an open file descriptior port.
780ee65e
NJ
6563@end deffn
6564
9401323e 6565\fsethostname
8f85c0c6
NJ
6566@deffn {Scheme Procedure} sethostname name
6567@deffnx {C Function} scm_sethostname (name)
9401323e
NJ
6568Set the host name of the current processor to @var{name}. May
6569only be used by the superuser. The return value is not
6570specified.
780ee65e
NJ
6571@end deffn
6572
9401323e 6573\fgethostname
8f85c0c6
NJ
6574@deffn {Scheme Procedure} gethostname
6575@deffnx {C Function} scm_gethostname ()
9401323e 6576Return the host name of the current processor.
780ee65e
NJ
6577@end deffn
6578
9401323e 6579\fgethost
8f85c0c6
NJ
6580@deffn {Scheme Procedure} gethost [host]
6581@deffnx {Scheme Procedure} gethostbyname hostname
6582@deffnx {Scheme Procedure} gethostbyaddr address
6583@deffnx {C Function} scm_gethost (host)
9401323e
NJ
6584Look up a host by name or address, returning a host object. The
6585@code{gethost} procedure will accept either a string name or an integer
6586address; if given no arguments, it behaves like @code{gethostent} (see
6587below). If a name or address is supplied but the address can not be
6588found, an error will be thrown to one of the keys:
6589@code{host-not-found}, @code{try-again}, @code{no-recovery} or
6590@code{no-data}, corresponding to the equivalent @code{h_error} values.
6591Unusual conditions may result in errors thrown to the
6592@code{system-error} or @code{misc_error} keys.
780ee65e
NJ
6593@end deffn
6594
9401323e 6595\fgetnet
8f85c0c6
NJ
6596@deffn {Scheme Procedure} getnet [net]
6597@deffnx {Scheme Procedure} getnetbyname net-name
6598@deffnx {Scheme Procedure} getnetbyaddr net-number
6599@deffnx {C Function} scm_getnet (net)
9401323e
NJ
6600Look up a network by name or net number in the network database. The
6601@var{net-name} argument must be a string, and the @var{net-number}
6602argument must be an integer. @code{getnet} will accept either type of
6603argument, behaving like @code{getnetent} (see below) if no arguments are
6604given.
780ee65e
NJ
6605@end deffn
6606
9401323e 6607\fgetproto
8f85c0c6
NJ
6608@deffn {Scheme Procedure} getproto [protocol]
6609@deffnx {Scheme Procedure} getprotobyname name
6610@deffnx {Scheme Procedure} getprotobynumber number
6611@deffnx {C Function} scm_getproto (protocol)
9401323e
NJ
6612Look up a network protocol by name or by number. @code{getprotobyname}
6613takes a string argument, and @code{getprotobynumber} takes an integer
6614argument. @code{getproto} will accept either type, behaving like
6615@code{getprotoent} (see below) if no arguments are supplied.
780ee65e
NJ
6616@end deffn
6617
9401323e 6618\fgetserv
8f85c0c6
NJ
6619@deffn {Scheme Procedure} getserv [name [protocol]]
6620@deffnx {Scheme Procedure} getservbyname name protocol
6621@deffnx {Scheme Procedure} getservbyport port protocol
6622@deffnx {C Function} scm_getserv (name, protocol)
9401323e
NJ
6623Look up a network service by name or by service number, and return a
6624network service object. The @var{protocol} argument specifies the name
6625of the desired protocol; if the protocol found in the network service
6626database does not match this name, a system error is signalled.
7a095584 6627
9401323e
NJ
6628The @code{getserv} procedure will take either a service name or number
6629as its first argument; if given no arguments, it behaves like
6630@code{getservent} (see below).
780ee65e
NJ
6631@end deffn
6632
9401323e 6633\fsethost
8f85c0c6
NJ
6634@deffn {Scheme Procedure} sethost [stayopen]
6635@deffnx {C Function} scm_sethost (stayopen)
9401323e
NJ
6636If @var{stayopen} is omitted, this is equivalent to @code{endhostent}.
6637Otherwise it is equivalent to @code{sethostent stayopen}.
6638@end deffn
780ee65e 6639
9401323e 6640\fsetnet
8f85c0c6
NJ
6641@deffn {Scheme Procedure} setnet [stayopen]
6642@deffnx {C Function} scm_setnet (stayopen)
9401323e
NJ
6643If @var{stayopen} is omitted, this is equivalent to @code{endnetent}.
6644Otherwise it is equivalent to @code{setnetent stayopen}.
6645@end deffn
780ee65e 6646
9401323e 6647\fsetproto
8f85c0c6
NJ
6648@deffn {Scheme Procedure} setproto [stayopen]
6649@deffnx {C Function} scm_setproto (stayopen)
9401323e
NJ
6650If @var{stayopen} is omitted, this is equivalent to @code{endprotoent}.
6651Otherwise it is equivalent to @code{setprotoent stayopen}.
780ee65e
NJ
6652@end deffn
6653
9401323e 6654\fsetserv
8f85c0c6
NJ
6655@deffn {Scheme Procedure} setserv [stayopen]
6656@deffnx {C Function} scm_setserv (stayopen)
9401323e
NJ
6657If @var{stayopen} is omitted, this is equivalent to @code{endservent}.
6658Otherwise it is equivalent to @code{setservent stayopen}.
780ee65e
NJ
6659@end deffn
6660
9401323e 6661\fhtons
8f85c0c6
NJ
6662@deffn {Scheme Procedure} htons value
6663@deffnx {C Function} scm_htons (value)
9401323e
NJ
6664Convert a 16 bit quantity from host to network byte ordering.
6665@var{value} is packed into 2 bytes, which are then converted
6666and returned as a new integer.
780ee65e
NJ
6667@end deffn
6668
9401323e 6669\fntohs
8f85c0c6
NJ
6670@deffn {Scheme Procedure} ntohs value
6671@deffnx {C Function} scm_ntohs (value)
9401323e
NJ
6672Convert a 16 bit quantity from network to host byte ordering.
6673@var{value} is packed into 2 bytes, which are then converted
6674and returned as a new integer.
780ee65e
NJ
6675@end deffn
6676
9401323e 6677\fhtonl
8f85c0c6
NJ
6678@deffn {Scheme Procedure} htonl value
6679@deffnx {C Function} scm_htonl (value)
9401323e
NJ
6680Convert a 32 bit quantity from host to network byte ordering.
6681@var{value} is packed into 4 bytes, which are then converted
6682and returned as a new integer.
780ee65e
NJ
6683@end deffn
6684
9401323e 6685\fntohl
8f85c0c6
NJ
6686@deffn {Scheme Procedure} ntohl value
6687@deffnx {C Function} scm_ntohl (value)
9401323e
NJ
6688Convert a 32 bit quantity from network to host byte ordering.
6689@var{value} is packed into 4 bytes, which are then converted
6690and returned as a new integer.
780ee65e
NJ
6691@end deffn
6692
9401323e 6693\finet-aton
8f85c0c6
NJ
6694@deffn {Scheme Procedure} inet-aton address
6695@deffnx {C Function} scm_inet_aton (address)
9401323e
NJ
6696Convert an IPv4 Internet address from printable string
6697(dotted decimal notation) to an integer. E.g.,
780ee65e 6698
9401323e
NJ
6699@lisp
6700(inet-aton "127.0.0.1") @result{} 2130706433
6701@end lisp
780ee65e
NJ
6702@end deffn
6703
9401323e 6704\finet-ntoa
8f85c0c6
NJ
6705@deffn {Scheme Procedure} inet-ntoa inetid
6706@deffnx {C Function} scm_inet_ntoa (inetid)
9401323e
NJ
6707Convert an IPv4 Internet address to a printable
6708(dotted decimal notation) string. E.g.,
780ee65e 6709
9401323e
NJ
6710@lisp
6711(inet-ntoa 2130706433) @result{} "127.0.0.1"
6712@end lisp
780ee65e
NJ
6713@end deffn
6714
9401323e 6715\finet-netof
8f85c0c6
NJ
6716@deffn {Scheme Procedure} inet-netof address
6717@deffnx {C Function} scm_inet_netof (address)
9401323e
NJ
6718Return the network number part of the given IPv4
6719Internet address. E.g.,
780ee65e 6720
9401323e
NJ
6721@lisp
6722(inet-netof 2130706433) @result{} 127
6723@end lisp
780ee65e
NJ
6724@end deffn
6725
9401323e 6726\finet-lnaof
8f85c0c6
NJ
6727@deffn {Scheme Procedure} inet-lnaof address
6728@deffnx {C Function} scm_lnaof (address)
9401323e
NJ
6729Return the local-address-with-network part of the given
6730IPv4 Internet address, using the obsolete class A/B/C system.
6731E.g.,
780ee65e 6732
9401323e
NJ
6733@lisp
6734(inet-lnaof 2130706433) @result{} 1
6735@end lisp
780ee65e
NJ
6736@end deffn
6737
9401323e 6738\finet-makeaddr
8f85c0c6
NJ
6739@deffn {Scheme Procedure} inet-makeaddr net lna
6740@deffnx {C Function} scm_inet_makeaddr (net, lna)
9401323e
NJ
6741Make an IPv4 Internet address by combining the network number
6742@var{net} with the local-address-within-network number
6743@var{lna}. E.g.,
780ee65e 6744
9401323e
NJ
6745@lisp
6746(inet-makeaddr 127 1) @result{} 2130706433
6747@end lisp
780ee65e
NJ
6748@end deffn
6749
9401323e 6750\finet-pton
8f85c0c6
NJ
6751@deffn {Scheme Procedure} inet-pton family address
6752@deffnx {C Function} scm_inet_pton (family, address)
9401323e
NJ
6753Convert a string containing a printable network address to
6754an integer address. Note that unlike the C version of this
6755function,
6756the result is an integer with normal host byte ordering.
6757@var{family} can be @code{AF_INET} or @code{AF_INET6}. E.g.,
6758
ae9f3a15 6759@lisp
9401323e
NJ
6760(inet-pton AF_INET "127.0.0.1") @result{} 2130706433
6761(inet-pton AF_INET6 "::1") @result{} 1
ae9f3a15 6762@end lisp
780ee65e
NJ
6763@end deffn
6764
9401323e 6765\finet-ntop
8f85c0c6
NJ
6766@deffn {Scheme Procedure} inet-ntop family address
6767@deffnx {C Function} scm_inet_ntop (family, address)
9401323e
NJ
6768Convert a network address into a printable string.
6769Note that unlike the C version of this function,
6770the input is an integer with normal host byte ordering.
6771@var{family} can be @code{AF_INET} or @code{AF_INET6}. E.g.,
780ee65e 6772
9401323e
NJ
6773@lisp
6774(inet-ntop AF_INET 2130706433) @result{} "127.0.0.1"
6775(inet-ntop AF_INET6 (- (expt 2 128) 1)) @result{}
6776ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
6777@end lisp
780ee65e
NJ
6778@end deffn
6779
9401323e 6780\fsocket
8f85c0c6
NJ
6781@deffn {Scheme Procedure} socket family style proto
6782@deffnx {C Function} scm_socket (family, style, proto)
9401323e
NJ
6783Return a new socket port of the type specified by @var{family},
6784@var{style} and @var{proto}. All three parameters are
6785integers. Supported values for @var{family} are
6786@code{AF_UNIX}, @code{AF_INET} and @code{AF_INET6}.
6787Typical values for @var{style} are @code{SOCK_STREAM},
6788@code{SOCK_DGRAM} and @code{SOCK_RAW}.
780ee65e 6789
9401323e
NJ
6790@var{proto} can be obtained from a protocol name using
6791@code{getprotobyname}. A value of zero specifies the default
6792protocol, which is usually right.
780ee65e 6793
9401323e
NJ
6794A single socket port cannot by used for communication until it
6795has been connected to another socket.
780ee65e
NJ
6796@end deffn
6797
9401323e 6798\fsocketpair
8f85c0c6
NJ
6799@deffn {Scheme Procedure} socketpair family style proto
6800@deffnx {C Function} scm_socketpair (family, style, proto)
9401323e
NJ
6801Return a pair of connected (but unnamed) socket ports of the
6802type specified by @var{family}, @var{style} and @var{proto}.
6803Many systems support only socket pairs of the @code{AF_UNIX}
6804family. Zero is likely to be the only meaningful value for
6805@var{proto}.
780ee65e
NJ
6806@end deffn
6807
9401323e 6808\fgetsockopt
8f85c0c6
NJ
6809@deffn {Scheme Procedure} getsockopt sock level optname
6810@deffnx {C Function} scm_getsockopt (sock, level, optname)
9401323e
NJ
6811Return the value of a particular socket option for the socket
6812port @var{sock}. @var{level} is an integer code for type of
6813option being requested, e.g., @code{SOL_SOCKET} for
6814socket-level options. @var{optname} is an integer code for the
6815option required and should be specified using one of the
6816symbols @code{SO_DEBUG}, @code{SO_REUSEADDR} etc.
780ee65e 6817
9401323e
NJ
6818The returned value is typically an integer but @code{SO_LINGER}
6819returns a pair of integers.
780ee65e
NJ
6820@end deffn
6821
9401323e 6822\fsetsockopt
8f85c0c6
NJ
6823@deffn {Scheme Procedure} setsockopt sock level optname value
6824@deffnx {C Function} scm_setsockopt (sock, level, optname, value)
9401323e
NJ
6825Set the value of a particular socket option for the socket
6826port @var{sock}. @var{level} is an integer code for type of option
6827being set, e.g., @code{SOL_SOCKET} for socket-level options.
6828@var{optname} is an
6829integer code for the option to set and should be specified using one of
6830the symbols @code{SO_DEBUG}, @code{SO_REUSEADDR} etc.
6831@var{value} is the value to which the option should be set. For
6832most options this must be an integer, but for @code{SO_LINGER} it must
6833be a pair.
780ee65e 6834
9401323e 6835The return value is unspecified.
780ee65e
NJ
6836@end deffn
6837
9401323e 6838\fshutdown
8f85c0c6
NJ
6839@deffn {Scheme Procedure} shutdown sock how
6840@deffnx {C Function} scm_shutdown (sock, how)
9401323e
NJ
6841Sockets can be closed simply by using @code{close-port}. The
6842@code{shutdown} procedure allows reception or tranmission on a
6843connection to be shut down individually, according to the parameter
6844@var{how}:
780ee65e 6845
9401323e
NJ
6846@table @asis
6847@item 0
6848Stop receiving data for this socket. If further data arrives, reject it.
6849@item 1
6850Stop trying to transmit data from this socket. Discard any
6851data waiting to be sent. Stop looking for acknowledgement of
6852data already sent; don't retransmit it if it is lost.
6853@item 2
6854Stop both reception and transmission.
6855@end table
780ee65e 6856
9401323e 6857The return value is unspecified.
780ee65e
NJ
6858@end deffn
6859
9401323e 6860\fconnect
8f85c0c6
NJ
6861@deffn {Scheme Procedure} connect sock fam address . args
6862@deffnx {C Function} scm_connect (sock, fam, address, args)
9401323e
NJ
6863Initiate a connection from a socket using a specified address
6864family to the address
6865specified by @var{address} and possibly @var{args}.
6866The format required for @var{address}
6867and @var{args} depends on the family of the socket.
780ee65e 6868
9401323e
NJ
6869For a socket of family @code{AF_UNIX},
6870only @var{address} is specified and must be a string with the
6871filename where the socket is to be created.
7a095584 6872
9401323e
NJ
6873For a socket of family @code{AF_INET},
6874@var{address} must be an integer IPv4 host address and
6875@var{args} must be a single integer port number.
780ee65e 6876
9401323e
NJ
6877For a socket of family @code{AF_INET6},
6878@var{address} must be an integer IPv6 host address and
6879@var{args} may be up to three integers:
6880port [flowinfo] [scope_id],
6881where flowinfo and scope_id default to zero.
6882
6883The return value is unspecified.
780ee65e
NJ
6884@end deffn
6885
9401323e 6886\fbind
8f85c0c6
NJ
6887@deffn {Scheme Procedure} bind sock fam address . args
6888@deffnx {C Function} scm_bind (sock, fam, address, args)
9401323e
NJ
6889Assign an address to the socket port @var{sock}.
6890Generally this only needs to be done for server sockets,
6891so they know where to look for incoming connections. A socket
6892without an address will be assigned one automatically when it
6893starts communicating.
7a095584 6894
9401323e
NJ
6895The format of @var{address} and @var{args} depends
6896on the family of the socket.
6897
6898For a socket of family @code{AF_UNIX}, only @var{address}
6899is specified and must be a string with the filename where
6900the socket is to be created.
6901
6902For a socket of family @code{AF_INET}, @var{address}
6903must be an integer IPv4 address and @var{args}
6904must be a single integer port number.
780ee65e 6905
9401323e
NJ
6906The values of the following variables can also be used for
6907@var{address}:
780ee65e 6908
9401323e
NJ
6909@defvar INADDR_ANY
6910Allow connections from any address.
6911@end defvar
780ee65e 6912
9401323e
NJ
6913@defvar INADDR_LOOPBACK
6914The address of the local host using the loopback device.
6915@end defvar
780ee65e 6916
9401323e
NJ
6917@defvar INADDR_BROADCAST
6918The broadcast address on the local network.
6919@end defvar
780ee65e 6920
9401323e
NJ
6921@defvar INADDR_NONE
6922No address.
6923@end defvar
780ee65e 6924
9401323e
NJ
6925For a socket of family @code{AF_INET6}, @var{address}
6926must be an integer IPv6 address and @var{args}
6927may be up to three integers:
6928port [flowinfo] [scope_id],
6929where flowinfo and scope_id default to zero.
780ee65e 6930
9401323e 6931The return value is unspecified.
780ee65e
NJ
6932@end deffn
6933
9401323e 6934\flisten
8f85c0c6
NJ
6935@deffn {Scheme Procedure} listen sock backlog
6936@deffnx {C Function} scm_listen (sock, backlog)
9401323e
NJ
6937Enable @var{sock} to accept connection
6938requests. @var{backlog} is an integer specifying
6939the maximum length of the queue for pending connections.
6940If the queue fills, new clients will fail to connect until
6941the server calls @code{accept} to accept a connection from
6942the queue.
7a095584 6943
9401323e
NJ
6944The return value is unspecified.
6945@end deffn
7a095584 6946
9401323e 6947\faccept
8f85c0c6
NJ
6948@deffn {Scheme Procedure} accept sock
6949@deffnx {C Function} scm_accept (sock)
9401323e
NJ
6950Accept a connection on a bound, listening socket.
6951If there
6952are no pending connections in the queue, wait until
6953one is available unless the non-blocking option has been
6954set on the socket.
7a095584 6955
9401323e
NJ
6956The return value is a
6957pair in which the @emph{car} is a new socket port for the
6958connection and
6959the @emph{cdr} is an object with address information about the
6960client which initiated the connection.
7a095584 6961
9401323e
NJ
6962@var{sock} does not become part of the
6963connection and will continue to accept new requests.
780ee65e
NJ
6964@end deffn
6965
9401323e 6966\fgetsockname
8f85c0c6
NJ
6967@deffn {Scheme Procedure} getsockname sock
6968@deffnx {C Function} scm_getsockname (sock)
9401323e
NJ
6969Return the address of @var{sock}, in the same form as the
6970object returned by @code{accept}. On many systems the address
6971of a socket in the @code{AF_FILE} namespace cannot be read.
780ee65e
NJ
6972@end deffn
6973
9401323e 6974\fgetpeername
8f85c0c6
NJ
6975@deffn {Scheme Procedure} getpeername sock
6976@deffnx {C Function} scm_getpeername (sock)
9401323e
NJ
6977Return the address that @var{sock}
6978is connected to, in the same form as the object returned by
6979@code{accept}. On many systems the address of a socket in the
6980@code{AF_FILE} namespace cannot be read.
780ee65e
NJ
6981@end deffn
6982
9401323e 6983\frecv!
8f85c0c6
NJ
6984@deffn {Scheme Procedure} recv! sock buf [flags]
6985@deffnx {C Function} scm_recv (sock, buf, flags)
9401323e
NJ
6986Receive data from a socket port.
6987@var{sock} must already
6988be bound to the address from which data is to be received.
6989@var{buf} is a string into which
6990the data will be written. The size of @var{buf} limits
6991the amount of
6992data which can be received: in the case of packet
6993protocols, if a packet larger than this limit is encountered
6994then some data
6995will be irrevocably lost.
780ee65e 6996
9401323e
NJ
6997The optional @var{flags} argument is a value or
6998bitwise OR of MSG_OOB, MSG_PEEK, MSG_DONTROUTE etc.
780ee65e 6999
9401323e
NJ
7000The value returned is the number of bytes read from the
7001socket.
7a095584 7002
9401323e
NJ
7003Note that the data is read directly from the socket file
7004descriptor:
7005any unread buffered port data is ignored.
780ee65e
NJ
7006@end deffn
7007
9401323e 7008\fsend
8f85c0c6
NJ
7009@deffn {Scheme Procedure} send sock message [flags]
7010@deffnx {C Function} scm_send (sock, message, flags)
9401323e
NJ
7011Transmit the string @var{message} on a socket port @var{sock}.
7012@var{sock} must already be bound to a destination address. The
7013value returned is the number of bytes transmitted --
7014it's possible for
7015this to be less than the length of @var{message}
7016if the socket is
7017set to be non-blocking. The optional @var{flags} argument
7018is a value or
7019bitwise OR of MSG_OOB, MSG_PEEK, MSG_DONTROUTE etc.
780ee65e 7020
9401323e
NJ
7021Note that the data is written directly to the socket
7022file descriptor:
7023any unflushed buffered port data is ignored.
780ee65e
NJ
7024@end deffn
7025
9401323e 7026\frecvfrom!
8f85c0c6
NJ
7027@deffn {Scheme Procedure} recvfrom! sock str [flags [start [end]]]
7028@deffnx {C Function} scm_recvfrom (sock, str, flags, start, end)
9401323e
NJ
7029Return data from the socket port @var{sock} and also
7030information about where the data was received from.
7031@var{sock} must already be bound to the address from which
7032data is to be received. @code{str}, is a string into which the
7033data will be written. The size of @var{str} limits the amount
7034of data which can be received: in the case of packet protocols,
7035if a packet larger than this limit is encountered then some
7036data will be irrevocably lost.
780ee65e 7037
9401323e
NJ
7038The optional @var{flags} argument is a value or bitwise OR of
7039@code{MSG_OOB}, @code{MSG_PEEK}, @code{MSG_DONTROUTE} etc.
7040
7041The value returned is a pair: the @emph{car} is the number of
7042bytes read from the socket and the @emph{cdr} an address object
7043in the same form as returned by @code{accept}. The address
7044will given as @code{#f} if not available, as is usually the
7045case for stream sockets.
7046
7047The @var{start} and @var{end} arguments specify a substring of
7048@var{str} to which the data should be written.
7049
7050Note that the data is read directly from the socket file
7051descriptor: any unread buffered port data is ignored.
780ee65e
NJ
7052@end deffn
7053
9401323e 7054\fsendto
8f85c0c6
NJ
7055@deffn {Scheme Procedure} sendto sock message fam address . args_and_flags
7056@deffnx {C Function} scm_sendto (sock, message, fam, address, args_and_flags)
9401323e
NJ
7057Transmit the string @var{message} on the socket port
7058@var{sock}. The
7059destination address is specified using the @var{fam},
7060@var{address} and
7061@var{args_and_flags} arguments, in a similar way to the
7062@code{connect} procedure. @var{args_and_flags} contains
7063the usual connection arguments optionally followed by
7064a flags argument, which is a value or
7065bitwise OR of MSG_OOB, MSG_PEEK, MSG_DONTROUTE etc.
7066
7067The value returned is the number of bytes transmitted --
7068it's possible for
7069this to be less than the length of @var{message} if the
7070socket is
7071set to be non-blocking.
7072Note that the data is written directly to the socket
7073file descriptor:
7074any unflushed buffered port data is ignored.
780ee65e 7075@end deffn