unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Ignore errors while evaluating with `primitive-eval'
@ 2013-08-19 15:11 Alexandru Cojocaru
  2013-08-19 15:46 ` Mark H Weaver
  0 siblings, 1 reply; 2+ messages in thread
From: Alexandru Cojocaru @ 2013-08-19 15:11 UTC (permalink / raw)
  To: guile-user

Hi guys,
is it possible to ignore errors when evaluating a badly formed expression?

Take as an example this:

     (let ((cs (string->list "display")))
       (let l ((cs (cdr cs)) (s (car cs)))
         (primitive-eval `(begin
                    (,(list->symbol s) "aha")
                    (newline)))
         (if (not (null? cs))
         (l cs s))))

I would like to ignore all the errors while evaluating `(d "aha")', `(di 
"aha")', `(dis "aha")' etc.
and evaluate only `(display "aha")'.

What I want is to construct some (possibly incorrect) expressions on the 
fly and evaluate them.

Best regards,
Alexandru Cojocaru



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Ignore errors while evaluating with `primitive-eval'
  2013-08-19 15:11 Ignore errors while evaluating with `primitive-eval' Alexandru Cojocaru
@ 2013-08-19 15:46 ` Mark H Weaver
  0 siblings, 0 replies; 2+ messages in thread
From: Mark H Weaver @ 2013-08-19 15:46 UTC (permalink / raw)
  To: Alexandru Cojocaru; +Cc: guile-user

Hi,

Alexandru Cojocaru <xojoc@gmx.com> writes:

> is it possible to ignore errors when evaluating a badly formed
> expression?

Yes.  An easy way is to use 'false-is-exception', like this:

  (false-if-exception (primitive-eval '(this is an error)))
  => #f

However, this won't work if you need to tell the difference between the
evaluation returning #f and an error happening.  In that case, try this:

  (catch #t
    (lambda ()
      (primitive-eval '(this is an error)))
    (lambda (key . args)
      (display "An error occurred during evaluation.\n")))

  Happy hacking!
      Mark



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-08-19 15:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-19 15:11 Ignore errors while evaluating with `primitive-eval' Alexandru Cojocaru
2013-08-19 15:46 ` Mark H Weaver

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).