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