scsh-users
[Top] [All Lists]

Re: Doubt about evaluating code

To: Gautham Anil <gautham_anil@cse.iitb.ac.in>, scsh-users@scsh.net
Subject: Re: Doubt about evaluating code
From: Andreas Bernauer <andreas.bernauer@gmx.de>
Date: Sun, 16 Oct 2005 18:49:24 +0200
Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:sender:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=ZJpMGkAvXEyoxs673/TT2qinCuXHEbl2miKrrfh6GeNauXTP94X7pBANaz8iyNHhpm3w8bMSCRzLukgsK+wqX1wLk8BUXwo3l8VmGYDOhwoMu7IHzwmhGl3/sZ+ASX8BxzsJXgU7iWNPjxTRowSxo9Hro+rHaYVCBX/jIKT92Y4=
List-id: <scsh-users.list-id.scsh.net>
Reply-to: andreas.bernauer@gmx.de
Sender: bernauer@gmail.com
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.

<Prev in Thread] Current Thread [Next in Thread>