Arc provides several operations for error handling and non-linear control flow. Since Arc's control flow mechanisms are built on top of MzScheme, see the MzScheme manual on exceptions and control flow for details.
Arc's simplest mechanism for non-linear control flow is catch
and throw
. This allows execution to jump back to the catch
expression, for example to exit a loop early.
arc> (catch (each x '(2 4 6 9 10 12) (prn "Examining " x) (if (odd x) (throw x)))) Examining 2 Examining 4 Examining 6 Examining 9 9
Arc also provides access to MzScheme's exception mechanism, which provides a way to trap errors or raise error.
The ccc
function is equivalent to Scheme's call-with-current-continuation
(often abbreviated as call/cc
). Continuations are extremely powerful; for details
see Teach Yourself Scheme in Fixnum Days, Chapter 20 of "On Lisp",
Call with Current Continuation Patterns, or Advanced Scheme Techniques. In MzScheme, continuations are relatively expensive if the call stack is deep since capturing a continuation copies the stack.