*** empty log message ***
[bpt/guile.git] / doc / ref / api-control.texi
CommitLineData
07d83abe
MV
1@c -*-texinfo-*-
2@c This is part of the GNU Guile Reference Manual.
3@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004
4@c Free Software Foundation, Inc.
5@c See the file guile.texi for copying conditions.
6
7@page
8@node Control Mechanisms
9@section Controlling the Flow of Program Execution
10
11See @ref{Control Flow} for a discussion of how the more general control
12flow of Scheme affects C code.
13
14@menu
15* begin:: Evaluating a sequence of expressions.
16* if cond case:: Simple conditional evaluation.
17* and or:: Conditional evaluation of a sequence.
18* while do:: Iteration mechanisms.
19* Continuations:: Continuations.
20* Multiple Values:: Returning and accepting multiple values.
21* Exceptions:: Throwing and catching exceptions.
22* Error Reporting:: Procedures for signaling errors.
661ae7ab 23* Dynamic Wind:: Dealing with non-local entrance/exit.
07d83abe
MV
24* Handling Errors:: How to handle errors in C code.
25@end menu
26
27@node begin
28@subsection Evaluating a Sequence of Expressions
29
30@cindex begin
31@cindex sequencing
32@cindex expression sequencing
33
34The @code{begin} syntax is used for grouping several expressions
35together so that they are treated as if they were one expression.
36This is particularly important when syntactic expressions are used
37which only allow one expression, but the programmer wants to use more
38than one expression in that place. As an example, consider the
39conditional expression below:
40
41@lisp
42(if (> x 0)
43 (begin (display "greater") (newline)))
44@end lisp
45
46If the two calls to @code{display} and @code{newline} were not embedded
47in a @code{begin}-statement, the call to @code{newline} would get
48misinterpreted as the else-branch of the @code{if}-expression.
49
50@deffn syntax begin expr1 expr2 @dots{}
51The expression(s) are evaluated in left-to-right order and the value
52of the last expression is returned as the value of the
53@code{begin}-expression. This expression type is used when the
54expressions before the last one are evaluated for their side effects.
55
56Guile also allows the expression @code{(begin)}, a @code{begin} with no
57sub-expressions. Such an expression returns the `unspecified' value.
58@end deffn
59
60@node if cond case
61@subsection Simple Conditional Evaluation
62
63@cindex conditional evaluation
64@cindex if
65@cindex case
66@cindex cond
67
68Guile provides three syntactic constructs for conditional evaluation.
69@code{if} is the normal if-then-else expression (with an optional else
70branch), @code{cond} is a conditional expression with multiple branches
71and @code{case} branches if an expression has one of a set of constant
72values.
73
74@deffn syntax if test consequent [alternate]
75All arguments may be arbitrary expressions. First, @var{test} is
76evaluated. If it returns a true value, the expression @var{consequent}
77is evaluated and @var{alternate} is ignored. If @var{test} evaluates to
78@code{#f}, @var{alternate} is evaluated instead. The value of the
79evaluated branch (@var{consequent} or @var{alternate}) is returned as
80the value of the @code{if} expression.
81
82When @var{alternate} is omitted and the @var{test} evaluates to
83@code{#f}, the value of the expression is not specified.
84@end deffn
85
86@deffn syntax cond clause1 clause2 @dots{}
87Each @code{cond}-clause must look like this:
88
89@lisp
90(@var{test} @var{expression} @dots{})
91@end lisp
92
93where @var{test} and @var{expression} are arbitrary expression, or like
94this
95
96@lisp
97(@var{test} => @var{expression})
98@end lisp
99
100where @var{expression} must evaluate to a procedure.
101
102The @var{test}s of the clauses are evaluated in order and as soon as one
103of them evaluates to a true values, the corresponding @var{expression}s
104are evaluated in order and the last value is returned as the value of
105the @code{cond}-expression. For the @code{=>} clause type,
106@var{expression} is evaluated and the resulting procedure is applied to
107the value of @var{test}. The result of this procedure application is
108then the result of the @code{cond}-expression.
109
43ed3b69
MV
110@cindex SRFI-61
111@cindex general cond clause
112@cindex multiple values and cond
113One additional @code{cond}-clause is available as an extension to
114standard Scheme:
115
116@lisp
117(@var{test} @var{guard} => @var{expression})
118@end lisp
119
120where @var{guard} and @var{expression} must evaluate to procedures.
121For this clause type, @var{test} may return multiple values, and
122@code{cond} ignores its boolean state; instead, @code{cond} evaluates
123@var{guard} and applies the resulting procedure to the value(s) of
124@var{test}, as if @var{guard} were the @var{consumer} argument of
125@code{call-with-values}. Iff the result of that procedure call is a
126true value, it evaluates @var{expression} and applies the resulting
127procedure to the value(s) of @var{test}, in the same manner as the
128@var{guard} was called.
129
07d83abe
MV
130The @var{test} of the last @var{clause} may be the symbol @code{else}.
131Then, if none of the preceding @var{test}s is true, the
132@var{expression}s following the @code{else} are evaluated to produce the
133result of the @code{cond}-expression.
134@end deffn
135
136@deffn syntax case key clause1 clause2 @dots{}
137@var{key} may be any expression, the @var{clause}s must have the form
138
139@lisp
140((@var{datum1} @dots{}) @var{expr1} @var{expr2} @dots{})
141@end lisp
142
143and the last @var{clause} may have the form
144
145@lisp
146(else @var{expr1} @var{expr2} @dots{})
147@end lisp
148
149All @var{datum}s must be distinct. First, @var{key} is evaluated. The
150the result of this evaluation is compared against all @var{datum}s using
151@code{eqv?}. When this comparison succeeds, the expression(s) following
152the @var{datum} are evaluated from left to right, returning the value of
153the last expression as the result of the @code{case} expression.
154
155If the @var{key} matches no @var{datum} and there is an
156@code{else}-clause, the expressions following the @code{else} are
157evaluated. If there is no such clause, the result of the expression is
158unspecified.
159@end deffn
160
161
162@node and or
163@subsection Conditional Evaluation of a Sequence of Expressions
164
165@code{and} and @code{or} evaluate all their arguments in order, similar
166to @code{begin}, but evaluation stops as soon as one of the expressions
167evaluates to false or true, respectively.
168
169@deffn syntax and expr @dots{}
170Evaluate the @var{expr}s from left to right and stop evaluation as soon
171as one expression evaluates to @code{#f}; the remaining expressions are
172not evaluated. The value of the last evaluated expression is returned.
173If no expression evaluates to @code{#f}, the value of the last
174expression is returned.
175
176If used without expressions, @code{#t} is returned.
177@end deffn
178
179@deffn syntax or expr @dots{}
180Evaluate the @var{expr}s from left to right and stop evaluation as soon
181as one expression evaluates to a true value (that is, a value different
182from @code{#f}); the remaining expressions are not evaluated. The value
183of the last evaluated expression is returned. If all expressions
184evaluate to @code{#f}, @code{#f} is returned.
185
186If used without expressions, @code{#f} is returned.
187@end deffn
188
189
190@node while do
191@subsection Iteration mechanisms
192
193@cindex iteration
194@cindex looping
195@cindex named let
196
197Scheme has only few iteration mechanisms, mainly because iteration in
198Scheme programs is normally expressed using recursion. Nevertheless,
199R5RS defines a construct for programming loops, calling @code{do}. In
200addition, Guile has an explicit looping syntax called @code{while}.
201
202@deffn syntax do ((variable init [step]) @dots{}) (test [expr @dots{}]) body @dots{}
203Bind @var{variable}s and evaluate @var{body} until @var{test} is true.
204The return value is the last @var{expr} after @var{test}, if given. A
205simple example will illustrate the basic form,
206
207@example
208(do ((i 1 (1+ i)))
209 ((> i 4))
210 (display i))
211@print{} 1234
212@end example
213
214@noindent
215Or with two variables and a final return value,
216
217@example
218(do ((i 1 (1+ i))
219 (p 3 (* 3 p)))
220 ((> i 4)
221 p)
222 (format #t "3**~s is ~s\n" i p))
223@print{}
2243**1 is 3
2253**2 is 9
2263**3 is 27
2273**4 is 81
228@result{}
229789
230@end example
231
232The @var{variable} bindings are established like a @code{let}, in that
233the expressions are all evaluated and then all bindings made. When
234iterating, the optional @var{step} expressions are evaluated with the
235previous bindings in scope, then new bindings all made.
236
237The @var{test} expression is a termination condition. Looping stops
238when the @var{test} is true. It's evaluated before running the
239@var{body} each time, so if it's true the first time then @var{body}
240is not run at all.
241
242The optional @var{expr}s after the @var{test} are evaluated at the end
243of looping, with the final @var{variable} bindings available. The
244last @var{expr} gives the return value, or if there are no @var{expr}s
245the return value is unspecified.
246
247Each iteration establishes bindings to fresh locations for the
248@var{variable}s, like a new @code{let} for each iteration. This is
249done for @var{variable}s without @var{step} expressions too. The
250following illustrates this, showing how a new @code{i} is captured by
251the @code{lambda} in each iteration (@pxref{About Closure,, The
252Concept of Closure}).
253
254@example
255(define lst '())
256(do ((i 1 (1+ i)))
257 ((> i 4))
258 (set! lst (cons (lambda () i) lst)))
259(map (lambda (proc) (proc)) lst)
260@result{}
261(4 3 2 1)
262@end example
263@end deffn
264
265@deffn syntax while cond body @dots{}
266Run a loop executing the @var{body} forms while @var{cond} is true.
267@var{cond} is tested at the start of each iteration, so if it's
268@code{#f} the first time then @var{body} is not executed at all. The
269return value is unspecified.
270
271Within @code{while}, two extra bindings are provided, they can be used
272from both @var{cond} and @var{body}.
273
274@deffn {Scheme Procedure} break
275Break out of the @code{while} form.
276@end deffn
277
278@deffn {Scheme Procedure} continue
279Abandon the current iteration, go back to the start and test
280@var{cond} again, etc.
281@end deffn
282
283Each @code{while} form gets its own @code{break} and @code{continue}
284procedures, operating on that @code{while}. This means when loops are
285nested the outer @code{break} can be used to escape all the way out.
286For example,
287
288@example
289(while (test1)
290 (let ((outer-break break))
291 (while (test2)
292 (if (something)
293 (outer-break #f))
294 ...)))
295@end example
296
297Note that each @code{break} and @code{continue} procedure can only be
298used within the dynamic extent of its @code{while}. Outside the
299@code{while} their behaviour is unspecified.
300@end deffn
301
302@cindex named let
303Another very common way of expressing iteration in Scheme programs is
304the use of the so-called @dfn{named let}.
305
306Named let is a variant of @code{let} which creates a procedure and calls
307it in one step. Because of the newly created procedure, named let is
308more powerful than @code{do}--it can be used for iteration, but also
309for arbitrary recursion.
310
311@deffn syntax let variable bindings body
312For the definition of @var{bindings} see the documentation about
313@code{let} (@pxref{Local Bindings}).
314
315Named @code{let} works as follows:
316
317@itemize @bullet
318@item
319A new procedure which accepts as many arguments as are in @var{bindings}
320is created and bound locally (using @code{let}) to @var{variable}. The
321new procedure's formal argument names are the name of the
322@var{variables}.
323
324@item
325The @var{body} expressions are inserted into the newly created procedure.
326
327@item
328The procedure is called with the @var{init} expressions as the formal
329arguments.
330@end itemize
331
332The next example implements a loop which iterates (by recursion) 1000
333times.
334
335@lisp
336(let lp ((x 1000))
337 (if (positive? x)
338 (lp (- x 1))
339 x))
340@result{}
3410
342@end lisp
343@end deffn
344
345
346@node Continuations
347@subsection Continuations
348@cindex continuations
349
350A ``continuation'' is the code that will execute when a given function
351or expression returns. For example, consider
352
353@example
354(define (foo)
355 (display "hello\n")
356 (display (bar)) (newline)
357 (exit))
358@end example
359
360The continuation from the call to @code{bar} comprises a
361@code{display} of the value returned, a @code{newline} and an
362@code{exit}. This can be expressed as a function of one argument.
363
364@example
365(lambda (r)
366 (display r) (newline)
367 (exit))
368@end example
369
370In Scheme, continuations are represented as special procedures just
371like this. The special property is that when a continuation is called
372it abandons the current program location and jumps directly to that
373represented by the continuation.
374
375A continuation is like a dynamic label, capturing at run-time a point
376in program execution, including all the nested calls that have lead to
377it (or rather the code that will execute when those calls return).
378
379Continuations are created with the following functions.
380
381@deffn {Scheme Procedure} call-with-current-continuation proc
382@deffnx {Scheme Procedure} call/cc proc
383@rnindex call-with-current-continuation
384Capture the current continuation and call @code{(@var{proc}
385@var{cont})} with it. The return value is the value returned by
386@var{proc}, or when @code{(@var{cont} @var{value})} is later invoked,
387the return is the @var{value} passed.
388
389Normally @var{cont} should be called with one argument, but when the
390location resumed is expecting multiple values (@pxref{Multiple
391Values}) then they should be passed as multiple arguments, for
392instance @code{(@var{cont} @var{x} @var{y} @var{z})}.
393
b4fddbbe
MV
394@var{cont} may only be used from the same side of a continuation
395barrier as it was created (@pxref{Continuation Barriers}), and in a
396multi-threaded program only from the thread in which it was created.
07d83abe
MV
397
398The call to @var{proc} is not part of the continuation captured, it runs
399only when the continuation is created. Often a program will want to
400store @var{cont} somewhere for later use; this can be done in
401@var{proc}.
402
403The @code{call} in the name @code{call-with-current-continuation}
404refers to the way a call to @var{proc} gives the newly created
405continuation. It's not related to the way a call is used later to
406invoke that continuation.
407
408@code{call/cc} is an alias for @code{call-with-current-continuation}.
409This is in common use since the latter is rather long.
410@end deffn
411
412@deftypefn {C Function} SCM scm_make_continuation (int *first)
413Capture the current continuation as described above. The return value
414is the new continuation, and @var{*first} is set to 1.
415
416When the continuation is invoked, @code{scm_make_continuation} will
417return again, this time returning the value (or set of multiple
418values) passed in that invocation, and with @var{*first} set to 0.
419@end deftypefn
420
421@sp 1
422@noindent
423Here is a simple example,
424
425@example
426(define kont #f)
427(format #t "the return is ~a\n"
428 (call/cc (lambda (k)
429 (set! kont k)
430 1)))
431@result{} the return is 1
432
433(kont 2)
434@result{} the return is 2
435@end example
436
437@code{call/cc} captures a continuation in which the value returned is
438going to be displayed by @code{format}. The @code{lambda} stores this
439in @code{kont} and gives an initial return @code{1} which is
440displayed. The later invocation of @code{kont} resumes the captured
441point, but this time returning @code{2}, which is displayed.
442
443When Guile is run interactively, a call to @code{format} like this has
444an implicit return back to the read-eval-print loop. @code{call/cc}
445captures that like any other return, which is why interactively
446@code{kont} will come back to read more input.
447
448@sp 1
449C programmers may note that @code{call/cc} is like @code{setjmp} in
450the way it records at runtime a point in program execution. A call to
451a continuation is like a @code{longjmp} in that it abandons the
452present location and goes to the recorded one. Like @code{longjmp},
453the value passed to the continuation is the value returned by
454@code{call/cc} on resuming there. However @code{longjmp} can only go
455up the program stack, but the continuation mechanism can go anywhere.
456
457When a continuation is invoked, @code{call/cc} and subsequent code
458effectively ``returns'' a second time. It can be confusing to imagine
459a function returning more times than it was called. It may help
460instead to think of it being stealthily re-entered and then program
461flow going on as normal.
462
463@code{dynamic-wind} (@pxref{Dynamic Wind}) can be used to ensure setup
464and cleanup code is run when a program locus is resumed or abandoned
661ae7ab 465through the continuation mechanism.
07d83abe
MV
466
467@sp 1
468Continuations are a powerful mechanism, and can be used to implement
469almost any sort of control structure, such as loops, coroutines, or
470exception handlers.
471
472However the implementation of continuations in Guile is not as
473efficient as one might hope, because Guile is designed to cooperate
474with programs written in other languages, such as C, which do not know
475about continuations. Basically continuations are captured by a block
476copy of the stack, and resumed by copying back.
477
478For this reason, generally continuations should be used only when
479there is no other simple way to achieve the desired result, or when
480the elegance of the continuation mechanism outweighs the need for
481performance.
482
483Escapes upwards from loops or nested functions are generally best
484handled with exceptions (@pxref{Exceptions}). Coroutines can be
485efficiently implemented with cooperating threads (a thread holds a
486full program stack but doesn't copy it around the way continuations
487do).
488
489
490@node Multiple Values
491@subsection Returning and Accepting Multiple Values
492
493@cindex multiple values
494@cindex receive
495
496Scheme allows a procedure to return more than one value to its caller.
497This is quite different to other languages which only allow
498single-value returns. Returning multiple values is different from
499returning a list (or pair or vector) of values to the caller, because
500conceptually not @emph{one} compound object is returned, but several
501distinct values.
502
503The primitive procedures for handling multiple values are @code{values}
504and @code{call-with-values}. @code{values} is used for returning
505multiple values from a procedure. This is done by placing a call to
506@code{values} with zero or more arguments in tail position in a
507procedure body. @code{call-with-values} combines a procedure returning
508multiple values with a procedure which accepts these values as
509parameters.
510
511@rnindex values
512@deffn {Scheme Procedure} values arg1 @dots{} argN
513@deffnx {C Function} scm_values (args)
514Delivers all of its arguments to its continuation. Except for
515continuations created by the @code{call-with-values} procedure,
516all continuations take exactly one value. The effect of
517passing no value or more than one value to continuations that
518were not created by @code{call-with-values} is unspecified.
519
520For @code{scm_values}, @var{args} is a list of arguments and the
521return is a multiple-values object which the caller can return. In
522the current implementation that object shares structure with
523@var{args}, so @var{args} should not be modified subsequently.
524@end deffn
525
526@rnindex call-with-values
527@deffn {Scheme Procedure} call-with-values producer consumer
528Calls its @var{producer} argument with no values and a
529continuation that, when passed some values, calls the
530@var{consumer} procedure with those values as arguments. The
531continuation for the call to @var{consumer} is the continuation
532of the call to @code{call-with-values}.
533
534@example
535(call-with-values (lambda () (values 4 5))
536 (lambda (a b) b))
537@result{} 5
538
539@end example
540@example
541(call-with-values * -)
542@result{} -1
543@end example
544@end deffn
545
546In addition to the fundamental procedures described above, Guile has a
547module which exports a syntax called @code{receive}, which is much more
548convenient. If you want to use it in your programs, you have to load
549the module @code{(ice-9 receive)} with the statement
550
551@lisp
552(use-modules (ice-9 receive))
553@end lisp
554
555@deffn {library syntax} receive formals expr body @dots{}
556Evaluate the expression @var{expr}, and bind the result values (zero or
557more) to the formal arguments in the formal argument list @var{formals}.
558@var{formals} must have the same syntax like the formal argument list
559used in @code{lambda} (@pxref{Lambda}). After binding the variables,
560the expressions in @var{body} @dots{} are evaluated in order.
561@end deffn
562
563
564@node Exceptions
565@subsection Exceptions
566@cindex error handling
567@cindex exception handling
568
569A common requirement in applications is to want to jump
570@dfn{non-locally} from the depths of a computation back to, say, the
571application's main processing loop. Usually, the place that is the
572target of the jump is somewhere in the calling stack of procedures that
573called the procedure that wants to jump back. For example, typical
574logic for a key press driven application might look something like this:
575
576@example
577main-loop:
578 read the next key press and call dispatch-key
579
580dispatch-key:
581 lookup the key in a keymap and call an appropriate procedure,
582 say find-file
583
584find-file:
585 interactively read the required file name, then call
586 find-specified-file
587
588find-specified-file:
589 check whether file exists; if not, jump back to main-loop
590 @dots{}
591@end example
592
593The jump back to @code{main-loop} could be achieved by returning through
594the stack one procedure at a time, using the return value of each
595procedure to indicate the error condition, but Guile (like most modern
596programming languages) provides an additional mechanism called
597@dfn{exception handling} that can be used to implement such jumps much
598more conveniently.
599
600@menu
601* Exception Terminology:: Different ways to say the same thing.
602* Catch:: Setting up to catch exceptions.
603* Throw:: Throwing an exception.
604* Lazy Catch:: Catch without unwinding the stack.
605* Exception Implementation:: How Guile implements exceptions.
606@end menu
607
608
609@node Exception Terminology
610@subsubsection Exception Terminology
611
612There are several variations on the terminology for dealing with
613non-local jumps. It is useful to be aware of them, and to realize
614that they all refer to the same basic mechanism.
615
616@itemize @bullet
617@item
618Actually making a non-local jump may be called @dfn{raising an
619exception}, @dfn{raising a signal}, @dfn{throwing an exception} or
620@dfn{doing a long jump}. When the jump indicates an error condition,
621people may talk about @dfn{signalling}, @dfn{raising} or @dfn{throwing}
622@dfn{an error}.
623
624@item
625Handling the jump at its target may be referred to as @dfn{catching} or
626@dfn{handling} the @dfn{exception}, @dfn{signal} or, where an error
627condition is involved, @dfn{error}.
628@end itemize
629
630Where @dfn{signal} and @dfn{signalling} are used, special care is needed
631to avoid the risk of confusion with POSIX signals.
632
633This manual prefers to speak of throwing and catching exceptions, since
634this terminology matches the corresponding Guile primitives.
635
636
637@node Catch
638@subsubsection Catching Exceptions
639
640@code{catch} is used to set up a target for a possible non-local jump.
641The arguments of a @code{catch} expression are a @dfn{key}, which
642restricts the set of exceptions to which this @code{catch} applies, a
643thunk that specifies the code to execute and a @dfn{handler} procedure
644that says what to do if an exception is thrown while executing the code.
645Note that if the execution thunk executes @dfn{normally}, which means
646without throwing any exceptions, the handler procedure is not called at
647all.
648
649When an exception is thrown using the @code{throw} function, the first
650argument of the @code{throw} is a symbol that indicates the type of the
651exception. For example, Guile throws an exception using the symbol
652@code{numerical-overflow} to indicate numerical overflow errors such as
653division by zero:
654
655@lisp
656(/ 1 0)
657@result{}
658ABORT: (numerical-overflow)
659@end lisp
660
661The @var{key} argument in a @code{catch} expression corresponds to this
662symbol. @var{key} may be a specific symbol, such as
663@code{numerical-overflow}, in which case the @code{catch} applies
664specifically to exceptions of that type; or it may be @code{#t}, which
665means that the @code{catch} applies to all exceptions, irrespective of
666their type.
667
668The second argument of a @code{catch} expression should be a thunk
669(i.e. a procedure that accepts no arguments) that specifies the normal
670case code. The @code{catch} is active for the execution of this thunk,
671including any code called directly or indirectly by the thunk's body.
672Evaluation of the @code{catch} expression activates the catch and then
673calls this thunk.
674
675The third argument of a @code{catch} expression is a handler procedure.
676If an exception is thrown, this procedure is called with exactly the
677arguments specified by the @code{throw}. Therefore, the handler
678procedure must be designed to accept a number of arguments that
679corresponds to the number of arguments in all @code{throw} expressions
680that can be caught by this @code{catch}.
681
682@deffn {Scheme Procedure} catch key thunk handler
683@deffnx {C Function} scm_catch (key, thunk, handler)
684Invoke @var{thunk} in the dynamic context of @var{handler} for
685exceptions matching @var{key}. If thunk throws to the symbol
686@var{key}, then @var{handler} is invoked this way:
687@lisp
688(handler key args ...)
689@end lisp
690
691@var{key} is a symbol or @code{#t}.
692
693@var{thunk} takes no arguments. If @var{thunk} returns
694normally, that is the return value of @code{catch}.
695
696Handler is invoked outside the scope of its own @code{catch}.
697If @var{handler} again throws to the same key, a new handler
698from further up the call chain is invoked.
699
700If the key is @code{#t}, then a throw to @emph{any} symbol will
701match this call to @code{catch}.
702@end deffn
703
704If the handler procedure needs to match a variety of @code{throw}
705expressions with varying numbers of arguments, you should write it like
706this:
707
708@lisp
709(lambda (key . args)
710 @dots{})
711@end lisp
712
713@noindent
714The @var{key} argument is guaranteed always to be present, because a
715@code{throw} without a @var{key} is not valid. The number and
716interpretation of the @var{args} varies from one type of exception to
717another, but should be specified by the documentation for each exception
718type.
719
720Note that, once the handler procedure is invoked, the catch that led to
721the handler procedure being called is no longer active. Therefore, if
722the handler procedure itself throws an exception, that exception can
723only be caught by another active catch higher up the call stack, if
724there is one.
725
726@sp 1
727@deftypefn {C Function} SCM scm_internal_catch (SCM tag, scm_t_catch_body body, void *body_data, scm_t_catch_handler handler, void *handler_data)
728The above @code{scm_catch} takes Scheme procedures as body and handler
729arguments. @code{scm_internal_catch} is an equivalent taking C
730functions.
731
732@var{body} is called as @code{@var{body} (@var{body_data})} with a
733catch on exceptions of the given @var{tag} type. If an exception is
734caught, @var{handler} is called @code{@var{handler}
735(@var{handler_data}, @var{key}, @var{args})}. @var{key} and
736@var{args} are the @code{SCM} key and argument list from the
737@code{throw}.
738
739@tpindex scm_t_catch_body
740@tpindex scm_t_catch_handler
741@var{body} and @var{handler} should have the following prototypes.
742@code{scm_t_catch_body} and @code{scm_t_catch_handler} are pointer
743typedefs for these.
744
745@example
746SCM body (void *data);
747SCM handler (void *data, SCM key, SCM args);
748@end example
749
750The @var{body_data} and @var{handler_data} parameters are passed to
751the respective calls so an application can communicate extra
752information to those functions.
753
754If the data consists of an @code{SCM} object, care should be taken
755that it isn't garbage collected while still required. If the
756@code{SCM} is a local C variable, one way to protect it is to pass a
757pointer to that variable as the data parameter, since the C compiler
758will then know the value must be held on the stack. Another way is to
759use @code{scm_remember_upto_here_1} (@pxref{Remembering During
760Operations}).
761@end deftypefn
762
763
764@node Throw
765@subsubsection Throwing Exceptions
766
767The @code{throw} primitive is used to throw an exception. One argument,
768the @var{key}, is mandatory, and must be a symbol; it indicates the type
769of exception that is being thrown. Following the @var{key},
770@code{throw} accepts any number of additional arguments, whose meaning
771depends on the exception type. The documentation for each possible type
772of exception should specify the additional arguments that are expected
773for that kind of exception.
774
775@deffn {Scheme Procedure} throw key . args
776@deffnx {C Function} scm_throw (key, args)
777Invoke the catch form matching @var{key}, passing @var{args} to the
778@var{handler}.
779
780@var{key} is a symbol. It will match catches of the same symbol or of
781@code{#t}.
782
783If there is no handler at all, Guile prints an error and then exits.
784@end deffn
785
786When an exception is thrown, it will be caught by the innermost
787@code{catch} expression that applies to the type of the thrown
788exception; in other words, the innermost @code{catch} whose @var{key} is
789@code{#t} or is the same symbol as that used in the @code{throw}
790expression. Once Guile has identified the appropriate @code{catch}, it
791handles the exception by applying that @code{catch} expression's handler
792procedure to the arguments of the @code{throw}.
793
794If there is no appropriate @code{catch} for a thrown exception, Guile
795prints an error to the current error port indicating an uncaught
796exception, and then exits. In practice, it is quite difficult to
797observe this behaviour, because Guile when used interactively installs a
798top level @code{catch} handler that will catch all exceptions and print
799an appropriate error message @emph{without} exiting. For example, this
800is what happens if you try to throw an unhandled exception in the
801standard Guile REPL; note that Guile's command loop continues after the
802error message:
803
804@lisp
805guile> (throw 'badex)
806<unnamed port>:3:1: In procedure gsubr-apply @dots{}
807<unnamed port>:3:1: unhandled-exception: badex
808ABORT: (misc-error)
809guile>
810@end lisp
811
812The default uncaught exception behaviour can be observed by evaluating a
813@code{throw} expression from the shell command line:
814
815@example
816$ guile -c "(begin (throw 'badex) (display \"here\\n\"))"
817guile: uncaught throw to badex: ()
818$
819@end example
820
821@noindent
822That Guile exits immediately following the uncaught exception
823is shown by the absence of any output from the @code{display}
824expression, because Guile never gets to the point of evaluating that
825expression.
826
827
828@node Lazy Catch
829@subsubsection Catch Without Unwinding
830
831A @dfn{lazy catch} is used in the same way as a normal @code{catch},
832with @var{key}, @var{thunk} and @var{handler} arguments specifying the
833exception type, normal case code and handler procedure, but differs in
834one important respect: the handler procedure is executed without
835unwinding the call stack from the context of the @code{throw} expression
836that caused the handler to be invoked.
837
838@deffn {Scheme Procedure} lazy-catch key thunk handler
839@deffnx {C Function} scm_lazy_catch (key, thunk, handler)
840This behaves exactly like @code{catch}, except that it does
841not unwind the stack before invoking @var{handler}.
842The @var{handler} procedure is not allowed to return:
843it must throw to another catch, or otherwise exit non-locally.
844@end deffn
845
846@deftypefn {C Function} SCM scm_internal_lazy_catch (SCM tag, scm_t_catch_body body, void *body_data, scm_t_catch_handler handler, void *handler_data)
847The above @code{scm_lazy_catch} takes Scheme procedures as body and
848handler arguments. @code{scm_internal_lazy_catch} is an equivalent
849taking C functions. See @code{scm_internal_catch} (@pxref{Catch}) for
850a description of the parameters, the behaviour however of course
851follows @code{lazy-catch}.
852@end deftypefn
853
854Typically, @var{handler} should save any desired state associated with
855the stack at the point where the corresponding @code{throw} occurred,
856and then throw an exception itself --- usually the same exception as the
857one it caught. If @var{handler} is invoked and does @emph{not} throw an
858exception, Guile itself throws an exception with key @code{misc-error}.
859
860Not unwinding the stack means that throwing an exception that is caught
861by a @code{lazy-catch} is @emph{almost} equivalent to calling the
862@code{lazy-catch}'s handler inline instead of each @code{throw}, and
863then omitting the surrounding @code{lazy-catch}. In other words,
864
865@lisp
866(lazy-catch 'key
867 (lambda () @dots{} (throw 'key args @dots{}) @dots{})
868 handler)
869@end lisp
870
871@noindent
872is @emph{almost} equivalent to
873
874@lisp
875((lambda () @dots{} (handler 'key args @dots{}) @dots{}))
876@end lisp
877
878@noindent
879But why only @emph{almost}? The difference is that with
880@code{lazy-catch} (as with normal @code{catch}), the dynamic context is
881unwound back to just outside the @code{lazy-catch} expression before
882invoking the handler. (For an introduction to what is meant by dynamic
883context, @xref{Dynamic Wind}.)
884
885Then, when the handler @emph{itself} throws an exception, that exception
886must be caught by some kind of @code{catch} (including perhaps another
887@code{lazy-catch}) higher up the call stack.
888
9ef07f6f
KR
889The dynamic context also includes @code{with-fluids} blocks
890(@pxref{Fluids and Dynamic States}),
07d83abe
MV
891so the effect of unwinding the dynamic context can also be seen in fluid
892variable values. This is illustrated by the following code, in which
893the normal case thunk uses @code{with-fluids} to temporarily change the
894value of a fluid:
895
896@lisp
897(define f (make-fluid))
898(fluid-set! f "top level value")
899
900(define (handler . args)
901 (cons (fluid-ref f) args))
902
903(lazy-catch 'foo
904 (lambda ()
905 (with-fluids ((f "local value"))
906 (throw 'foo)))
907 handler)
908@result{}
909("top level value" foo)
910
911((lambda ()
912 (with-fluids ((f "local value"))
913 (handler 'foo))))
914@result{}
915("local value" foo)
916@end lisp
917
918@noindent
919In the @code{lazy-catch} version, the unwinding of dynamic context
920restores @code{f} to its value outside the @code{with-fluids} block
921before the handler is invoked, so the handler's @code{(fluid-ref f)}
922returns the external value.
923
924@code{lazy-catch} is useful because it permits the implementation of
925debuggers and other reflective programming tools that need to access the
926state of the call stack at the exact point where an exception or an
927error is thrown. For an example of this, see REFFIXME:stack-catch.
928
929
930@node Exception Implementation
931@subsubsection How Guile Implements Exceptions
932
933It is traditional in Scheme to implement exception systems using
934@code{call-with-current-continuation}. Continuations
935(@pxref{Continuations}) are such a powerful concept that any other
936control mechanism --- including @code{catch} and @code{throw} --- can be
937implemented in terms of them.
938
939Guile does not implement @code{catch} and @code{throw} like this,
940though. Why not? Because Guile is specifically designed to be easy to
941integrate with applications written in C. In a mixed Scheme/C
942environment, the concept of @dfn{continuation} must logically include
943``what happens next'' in the C parts of the application as well as the
944Scheme parts, and it turns out that the only reasonable way of
945implementing continuations like this is to save and restore the complete
946C stack.
947
948So Guile's implementation of @code{call-with-current-continuation} is a
949stack copying one. This allows it to interact well with ordinary C
950code, but means that creating and calling a continuation is slowed down
951by the time that it takes to copy the C stack.
952
953The more targeted mechanism provided by @code{catch} and @code{throw}
954does not need to save and restore the C stack because the @code{throw}
955always jumps to a location higher up the stack of the code that executes
956the @code{throw}. Therefore Guile implements the @code{catch} and
957@code{throw} primitives independently of
958@code{call-with-current-continuation}, in a way that takes advantage of
959this @emph{upwards only} nature of exceptions.
960
961
962@node Error Reporting
963@subsection Procedures for Signaling Errors
964
965Guile provides a set of convenience procedures for signaling error
966conditions that are implemented on top of the exception primitives just
967described.
968
969@deffn {Scheme Procedure} error msg args @dots{}
970Raise an error with key @code{misc-error} and a message constructed by
971displaying @var{msg} and writing @var{args}.
972@end deffn
973
974@deffn {Scheme Procedure} scm-error key subr message args data
975@deffnx {C Function} scm_error_scm (key, subr, message, args, data)
976Raise an error with key @var{key}. @var{subr} can be a string
977naming the procedure associated with the error, or @code{#f}.
978@var{message} is the error message string, possibly containing
979@code{~S} and @code{~A} escapes. When an error is reported,
980these are replaced by formatting the corresponding members of
981@var{args}: @code{~A} (was @code{%s} in older versions of
982Guile) formats using @code{display} and @code{~S} (was
983@code{%S}) formats using @code{write}. @var{data} is a list or
984@code{#f} depending on @var{key}: if @var{key} is
985@code{system-error} then it should be a list containing the
986Unix @code{errno} value; If @var{key} is @code{signal} then it
7cd44c6d
MV
987should be a list containing the Unix signal number; If
988@var{key} is @code{out-of-range} or @code{wrong-type-arg},
989it is a list containing the bad value; otherwise
07d83abe
MV
990it will usually be @code{#f}.
991@end deffn
992
993@deffn {Scheme Procedure} strerror err
994@deffnx {C Function} scm_strerror (err)
44ba562e
KR
995Return the Unix error message corresponding to @var{err}, an integer
996@code{errno} value.
997
998When @code{setlocale} has been called (@pxref{Locales}), the message
999is in the language and charset of @code{LC_MESSAGES}. (This is done
1000by the C library.)
07d83abe
MV
1001@end deffn
1002
1003@c begin (scm-doc-string "boot-9.scm" "false-if-exception")
1004@deffn syntax false-if-exception expr
1005Returns the result of evaluating its argument; however
1006if an exception occurs then @code{#f} is returned instead.
1007@end deffn
1008@c end
1009
1010
1011@node Dynamic Wind
1012@subsection Dynamic Wind
1013
661ae7ab
MV
1014For Scheme code, the fundamental procedure to react to non-local entry
1015and exits of dynamic contexts is @code{dynamic-wind}. C code could
1016use @code{scm_internal_dynamic_wind}, but since C does not allow the
1017convenient construction of anonymous procedures that close over
1018lexical variables, this will be, well, inconvenient.
1019
1020Therefore, Guile offers the functions @code{scm_dynwind_begin} and
1021@code{scm_dynwind_end} to delimit a dynamic extent. Within this
1022dynamic extent, which is calles a @dfn{dynwind context}, you can
1023perform various @dfn{dynwind actions} that control what happens when
1024the dynwind context is entered or left. For example, you can register
1025a cleanup routine with @code{scm_dynwind_unwind_handler} that is
1026executed when the context is left. There are several other more
1027specialized dynwind actions as well, for example to temporarily block
1028the execution of asyncs or to temporarily change the current output
1029port. They are described elsewhere in this manual.
1030
1031Here is an example that shows how to prevent memory leaks.
1032
1033@example
1034
1035/* Suppose there is a function called FOO in some library that you
1036 would like to make available to Scheme code (or to C code that
1037 follows the Scheme conventions).
1038
1039 FOO takes two C strings and returns a new string. When an error has
1040 occurred in FOO, it returns NULL.
1041*/
1042
1043char *foo (char *s1, char *s2);
1044
1045/* SCM_FOO interfaces the C function FOO to the Scheme way of life.
1046 It takes care to free up all temporary strings in the case of
1047 non-local exits.
1048 */
1049
1050SCM
1051scm_foo (SCM s1, SCM s2)
1052@{
1053 char *c_s1, *c_s2, *c_res;
1054
1055 scm_dynwind_begin (0);
1056
1057 c_s1 = scm_to_locale_string (s1);
1058
1059 /* Call 'free (c_s1)' when the dynwind context is left.
1060 */
1061 scm_dynwind_unwind_handler (free, c_s1, SCM_F_WIND_EXPLICITLY);
1062
1063 c_s2 = scm_to_locale_string (s2);
1064
1065 /* Same as above, but more concisely.
1066 */
1067 scm_dynwind_free (c_s2);
1068
1069 c_res = foo (c_s1, c_s2);
1070 if (c_res == NULL)
1071 scm_memory_error ("foo");
1072
1073 scm_dynwind_end ();
1074
1075 return scm_take_locale_string (res);
1076@}
1077@end example
1078
07d83abe
MV
1079@rnindex dynamic-wind
1080@deffn {Scheme Procedure} dynamic-wind in_guard thunk out_guard
1081@deffnx {C Function} scm_dynamic_wind (in_guard, thunk, out_guard)
1082All three arguments must be 0-argument procedures.
1083@var{in_guard} is called, then @var{thunk}, then
1084@var{out_guard}.
1085
1086If, any time during the execution of @var{thunk}, the
1087dynamic extent of the @code{dynamic-wind} expression is escaped
1088non-locally, @var{out_guard} is called. If the dynamic extent of
1089the dynamic-wind is re-entered, @var{in_guard} is called. Thus
1090@var{in_guard} and @var{out_guard} may be called any number of
1091times.
1092@lisp
1093(define x 'normal-binding)
1094@result{} x
1095(define a-cont (call-with-current-continuation
1096 (lambda (escape)
1097 (let ((old-x x))
1098 (dynamic-wind
1099 ;; in-guard:
1100 ;;
1101 (lambda () (set! x 'special-binding))
1102
1103 ;; thunk
1104 ;;
1105 (lambda () (display x) (newline)
1106 (call-with-current-continuation escape)
1107 (display x) (newline)
1108 x)
1109
1110 ;; out-guard:
1111 ;;
1112 (lambda () (set! x old-x)))))))
1113
1114;; Prints:
1115special-binding
1116;; Evaluates to:
1117@result{} a-cont
1118x
1119@result{} normal-binding
1120(a-cont #f)
1121;; Prints:
1122special-binding
1123;; Evaluates to:
1124@result{} a-cont ;; the value of the (define a-cont...)
1125x
1126@result{} normal-binding
1127a-cont
1128@result{} special-binding
1129@end lisp
1130@end deffn
1131
661ae7ab 1132@deftp {C Type} scm_t_dynwind_flags
07d83abe 1133This is an enumeration of several flags that modify the behavior of
661ae7ab
MV
1134@code{scm_dynwind_begin}. The flags are listed in the following
1135table.
07d83abe
MV
1136
1137@table @code
661ae7ab
MV
1138@item SCM_F_DYNWIND_REWINDABLE
1139The dynamic context is @dfn{rewindable}. This means that it can be
1140reentered non-locally (via the invokation of a continuation). The
1141default is that a dynwind context can not be reentered non-locally.
07d83abe
MV
1142@end table
1143
1144@end deftp
1145
661ae7ab
MV
1146@deftypefn {C Function} void scm_dynwind_begin (scm_t_dynwind_flags flags)
1147The function @code{scm_dynwind_begin} starts a new dynamic context and
1148makes it the `current' one.
07d83abe 1149
661ae7ab
MV
1150The @var{flags} argument determines the default behavior of the
1151context. Normally, use 0. This will result in a context that can not
1152be reentered with a captured continuation. When you are prepared to
1153handle reentries, include @code{SCM_F_DYNWIND_REWINDABLE} in
1154@var{flags}.
07d83abe
MV
1155
1156Being prepared for reentry means that the effects of unwind handlers
1157can be undone on reentry. In the example above, we want to prevent a
1158memory leak on non-local exit and thus register an unwind handler that
1159frees the memory. But once the memory is freed, we can not get it
1160back on reentry. Thus reentry can not be allowed.
1161
1162The consequence is that continuations become less useful when
661ae7ab
MV
1163non-reenterable contexts are captured, but you don't need to worry
1164about that too much.
1165
1166The context is ended either implicitly when a non-local exit happens,
1167or explicitly with @code{scm_dynwind_end}. You must make sure that a
1168dynwind context is indeed ended properly. If you fail to call
1169@code{scm_dynwind_end} for each @code{scm_dynwind_begin}, the behavior
1170is undefined.
07d83abe
MV
1171@end deftypefn
1172
661ae7ab
MV
1173@deftypefn {C Function} void scm_dynwind_end ()
1174End the current dynamic context explicitly and make the previous one
1175current.
07d83abe
MV
1176@end deftypefn
1177
1178@deftp {C Type} scm_t_wind_flags
1179This is an enumeration of several flags that modify the behavior of
661ae7ab
MV
1180@code{scm_dynwind_unwind_handler} and
1181@code{scm_dynwind_rewind_handler}. The flags are listed in the
1182following table.
07d83abe
MV
1183
1184@table @code
1185@item SCM_F_WIND_EXPLICITLY
1186@vindex SCM_F_WIND_EXPLICITLY
661ae7ab
MV
1187The registered action is also carried out when the dynwind context is
1188entered or left locally.
07d83abe
MV
1189@end table
1190@end deftp
1191
661ae7ab
MV
1192@deftypefn {C Function} void scm_dynwind_unwind_handler (void (*func)(void *), void *data, scm_t_wind_flags flags)
1193@deftypefnx {C Function} void scm_dynwind_unwind_handler_with_scm (void (*func)(SCM), SCM data, scm_t_wind_flags flags)
07d83abe 1194Arranges for @var{func} to be called with @var{data} as its arguments
661ae7ab
MV
1195when the current context ends implicitly. If @var{flags} contains
1196@code{SCM_F_WIND_EXPLICITLY}, @var{func} is also called when the
1197context ends explicitly with @code{scm_dynwind_end}.
07d83abe 1198
661ae7ab 1199The function @code{scm_dynwind_unwind_handler_with_scm} takes care that
07d83abe
MV
1200@var{data} is protected from garbage collection.
1201@end deftypefn
1202
661ae7ab
MV
1203@deftypefn {C Function} void scm_dynwind_rewind_handler (void (*func)(void *), void *data, scm_t_wind_flags flags)
1204@deftypefnx {C Function} void scm_dynwind_rewind_handler_with_scm (void (*func)(SCM), SCM data, scm_t_wind_flags flags)
07d83abe 1205Arrange for @var{func} to be called with @var{data} as its argument when
661ae7ab 1206the current context is restarted by rewinding the stack. When @var{flags}
07d83abe
MV
1207contains @code{SCM_F_WIND_EXPLICITLY}, @var{func} is called immediately
1208as well.
1209
661ae7ab 1210The function @code{scm_dynwind_rewind_handler_with_scm} takes care that
07d83abe
MV
1211@var{data} is protected from garbage collection.
1212@end deftypefn
1213
1214
1215@node Handling Errors
1216@subsection How to Handle Errors
1217
1218Error handling is based on @code{catch} and @code{throw}. Errors are
1219always thrown with a @var{key} and four arguments:
1220
1221@itemize @bullet
1222@item
1223@var{key}: a symbol which indicates the type of error. The symbols used
1224by libguile are listed below.
1225
1226@item
1227@var{subr}: the name of the procedure from which the error is thrown, or
1228@code{#f}.
1229
1230@item
1231@var{message}: a string (possibly language and system dependent)
1232describing the error. The tokens @code{~A} and @code{~S} can be
1233embedded within the message: they will be replaced with members of the
1234@var{args} list when the message is printed. @code{~A} indicates an
1235argument printed using @code{display}, while @code{~S} indicates an
1236argument printed using @code{write}. @var{message} can also be
1237@code{#f}, to allow it to be derived from the @var{key} by the error
1238handler (may be useful if the @var{key} is to be thrown from both C and
1239Scheme).
1240
1241@item
1242@var{args}: a list of arguments to be used to expand @code{~A} and
1243@code{~S} tokens in @var{message}. Can also be @code{#f} if no
1244arguments are required.
1245
1246@item
1247@var{rest}: a list of any additional objects required. e.g., when the
1248key is @code{'system-error}, this contains the C errno value. Can also
1249be @code{#f} if no additional objects are required.
1250@end itemize
1251
1252In addition to @code{catch} and @code{throw}, the following Scheme
1253facilities are available:
1254
1255@deffn {Scheme Procedure} display-error stack port subr message args rest
1256@deffnx {C Function} scm_display_error (stack, port, subr, message, args, rest)
1257Display an error message to the output port @var{port}.
1258@var{stack} is the saved stack for the error, @var{subr} is
1259the name of the procedure in which the error occurred and
1260@var{message} is the actual error message, which may contain
1261formatting instructions. These will format the arguments in
1262the list @var{args} accordingly. @var{rest} is currently
1263ignored.
1264@end deffn
1265
1266The following are the error keys defined by libguile and the situations
1267in which they are used:
1268
1269@itemize @bullet
1270@item
1271@cindex @code{error-signal}
1272@code{error-signal}: thrown after receiving an unhandled fatal signal
1273such as SIGSEGV, SIGBUS, SIGFPE etc. The @var{rest} argument in the throw
1274contains the coded signal number (at present this is not the same as the
1275usual Unix signal number).
1276
1277@item
1278@cindex @code{system-error}
1279@code{system-error}: thrown after the operating system indicates an
1280error condition. The @var{rest} argument in the throw contains the
1281errno value.
1282
1283@item
1284@cindex @code{numerical-overflow}
1285@code{numerical-overflow}: numerical overflow.
1286
1287@item
1288@cindex @code{out-of-range}
1289@code{out-of-range}: the arguments to a procedure do not fall within the
1290accepted domain.
1291
1292@item
1293@cindex @code{wrong-type-arg}
1294@code{wrong-type-arg}: an argument to a procedure has the wrong type.
1295
1296@item
1297@cindex @code{wrong-number-of-args}
1298@code{wrong-number-of-args}: a procedure was called with the wrong number
1299of arguments.
1300
1301@item
1302@cindex @code{memory-allocation-error}
1303@code{memory-allocation-error}: memory allocation error.
1304
1305@item
1306@cindex @code{stack-overflow}
1307@code{stack-overflow}: stack overflow error.
1308
1309@item
1310@cindex @code{regular-expression-syntax}
1311@code{regular-expression-syntax}: errors generated by the regular
1312expression library.
1313
1314@item
1315@cindex @code{misc-error}
1316@code{misc-error}: other errors.
1317@end itemize
1318
1319
1320@subsubsection C Support
1321
1322In the following C functions, @var{SUBR} and @var{MESSAGE} parameters
1323can be @code{NULL} to give the effect of @code{#f} described above.
1324
1325@deftypefn {C Function} SCM scm_error (SCM @var{key}, char *@var{subr}, char *@var{message}, SCM @var{args}, SCM @var{rest})
1326Throw an error, as per @code{scm-error} above.
1327@end deftypefn
1328
1329@deftypefn {C Function} void scm_syserror (char *@var{subr})
1330@deftypefnx {C Function} void scm_syserror_msg (char *@var{subr}, char *@var{message}, SCM @var{args})
1331Throw an error with key @code{system-error} and supply @code{errno} in
1332the @var{rest} argument. For @code{scm_syserror} the message is
1333generated using @code{strerror}.
1334
1335Care should be taken that any code in between the failing operation
1336and the call to these routines doesn't change @code{errno}.
1337@end deftypefn
1338
1339@deftypefn {C Function} void scm_num_overflow (char *@var{subr})
1340@deftypefnx {C Function} void scm_out_of_range (char *@var{subr}, SCM @var{bad_value})
1341@deftypefnx {C Function} void scm_wrong_num_args (SCM @var{proc})
1342@deftypefnx {C Function} void scm_wrong_type_arg (char *@var{subr}, int @var{argnum}, SCM @var{bad_value})
1343@deftypefnx {C Function} void scm_memory_error (char *@var{subr})
1344Throw an error with the various keys described above.
1345
1346For @code{scm_wrong_num_args}, @var{proc} should be a Scheme symbol
1347which is the name of the procedure incorrectly invoked.
1348@end deftypefn
1349
1350
1351@c Local Variables:
1352@c TeX-master: "guile.texi"
1353@c End: