On 10/15/05, Gautham Anil <gautham_anil@cse.iitb.ac.in> wrote:
> I am doing some Genetic Programming in scsh. I need to evaluate many
> randomly generated codes. The program must continue gracefully with the
> next piece of generated code in the common case that the current piece
> does not compile.
>
> How do I do this? As I see, all errors in the code causes the shell to
> show up. Also, there is no srfi-12 support. So, how this can be done?
You could use code from SUnet (http://sourceforge.net/projects/sunet):
from file scheme/httpd/surfles/handle-fatal.scm
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Error-Handler
;;
;; Adopted from WITH-FATAL-ERROR-HANDLER, but handles everything that
;; is catchable. We must catch everything because we also want
;; exceptions (and warnings) to be catched (e.g. when the surflet is
;; loaded.)
(define (with-fatal-handler* handler thunk)
(call-with-current-continuation
(lambda (accept)
((call-with-current-continuation
(lambda (k)
(with-handler (lambda (condition more)
(call-with-current-continuation
(lambda (decline)
(k (lambda () (handler condition decline)))))
(more)) ; Keep looking for a handler.
(lambda () (call-with-values thunk accept)))))))))
(define-syntax with-fatal-handler
(syntax-rules ()
((with-fatal-handler handler body ...)
(with-fatal-handler* handler
(lambda () body ...)))))
So you say something like
(with-fatal-handler
(lambda (condition decline)
;;; Your code goes here. If you don't want to handle the
condition, call (decline).
)
(try-this-function))
Cheers,
Andreas Bernauer.
|