M
Martin DeMello
From http://sigfpe.blogspot.com/2007/02/exceptions-disjunctions-and.html:
In functional languages exceptions tend to be handled a little
differently. Whereas C++ has a throw keyword, there is no equivalent
in Scheme, say. Instead
the call-with-current-continuation function acts like catch. The
argument to call-with-current-continuation is a function (lambda
(throw) ...) and the argument to this function (itself a function),
here called throw, does the throwing. For example consider the scheme
expression:
(call-with-current-continuation
(lambda (throw) (+ 1 (throw 7))))
[ a = callcc {|c| c[7] + 1} in ruby - martin ]
The result is 7, not 8. The 7 is thrown 'past' the (+ 1 ...) and is
caught by the surrounding call-with-current-continuation. The
important difference from C++ is that if any subexpression is to throw
some value, it must be 'handed' a suitable throw function.
In functional languages exceptions tend to be handled a little
differently. Whereas C++ has a throw keyword, there is no equivalent
in Scheme, say. Instead
the call-with-current-continuation function acts like catch. The
argument to call-with-current-continuation is a function (lambda
(throw) ...) and the argument to this function (itself a function),
here called throw, does the throwing. For example consider the scheme
expression:
(call-with-current-continuation
(lambda (throw) (+ 1 (throw 7))))
[ a = callcc {|c| c[7] + 1} in ruby - martin ]
The result is 7, not 8. The 7 is thrown 'past' the (+ 1 ...) and is
caught by the surrounding call-with-current-continuation. The
important difference from C++ is that if any subexpression is to throw
some value, it must be 'handed' a suitable throw function.