[Ecls-list] How do I get back errors

Juan Jose Garcia Ripoll lisp at arrakis.es
Thu Jan 19 03:38:09 UTC 2006


On Tue, 2006-01-17 at 11:06 +1100, David Creelman wrote:
> I find myself entering strings incorrectly, etc when interacting with
> ECL, and I see that there are some error functions in externals.h. 
> 
> If I entered a CL string incorrectly, which function do I use to get
> back an error ? Is there a catch all error report function ?
> 
> ... Or should I be checking more often for Cnil on return?

I interpret your problem as having passed a wrong argument to
c_string_to_object() and this causing an error. c_string_to_object() is
not protected against reader and evaluation errors. That means when the
input of your function is malformed, ECL signals an error and looks for
an error handler.

The optimal solution for this problem is not to hack
c_string_to_object() but to add means for C code to intercept lisp
conditions, much like HANDLER-CASE or HANDLER-BIND. Until this is done,
there might be this simple (but completely untested) approach to your
problem:

const char *handler = "
#.(lambda (string)
    ;;
    ;; Read a lisp object from STRING. The output are two values
    ;;   VALUES(0) = object read or NIL
    ;;   VALUES(1) = NIL or condition due to reader error
    ;;
    (handler-case
	(values (read-from-string string) nil)
      (error (c) (values nil c))))
";

cl_object
my_c_string_to_object(const char *string)
{
    static cl_object string_parser = NULL;

    if (string_parser == NULL) {
       ecl_register_static_root(&string_parser);
       string_parser = c_string_to_object(handler);
    }
    return funcall(2, string_parser, make_simple_string(string));
}

In VALUES(0) you will read the object to be parsed if everything
succeeded, in VALUES(1) you should get a condition. There are trivial
modifications to turn VALUES(1) into a string.

Regards

Juanjo





More information about the ecl-devel mailing list