Re: Handling branch cuts for hypergeometric function s



   From: "Mike Thomas" 
   
   | > Using catch/throw or conditions allows the dynamic behaviour
   | > that we would want
   | 
   | I don't think it would, because once an exception is thrown, the catch
   | routine cannot cause the calculation to resume.
   
   What about a call/cc in Common Lisp?
   
     http://home.comcast.net/~bc19191/blog/040521.html

call/cc is not necessary.  The stated premise that the catch routine
cannot resume the computation throwing the exception [sic] is simply
incorrect.

First, the CL terminolofy the "throwing an exception" is "signalling a
condition".  A handler can run either inside the dynamic environment
of the call to signal, or else after throwling out of the computation
to the dynamic environment that established the condition handler.
See respectively the standard CL macros handler-bind and handler-case.

Here is a simple and silly example using handler-bind:

(define-condition zeroness-unknown (condition)
  ((value :accessor zeroness-unknown-value :initarg :value)))

(defun nonzerop (x)
  (handler-bind
      ((zeroness-unknown (lambda (c)
                           (invoke-restart
                            'nonzero
                            (y-or-n-p "Is ~d nonzero? [y or n] "
                                      (zeroness-unknown-value c))))))
    (test-nonzero x)))

(defun test-nonzero (x)
  (restart-bind ((nonzero (lambda (answer)
                            (return-from test-nonzero answer))))
    (signal (make-condition 'zeroness-unknown :value x))))


cl-user(21): (nonzerop 3)
Is 3 nonzero? [y or n] n
nil
cl-user(22): (nonzerop 3)
Is 3 nonzero? [y or n] y
t