Safely calling lisp lambda function from C?

PR polos.ruetz at
Tue Sep 8 17:27:59 UTC 2015

2015-09-08 18:15 GMT+02:00, bruce li <leilmyxwz at>:
> cl_object callback_wrapper(cl_object lambda, cl_object ...) {
>     cl_funcall(2, lambda, some_params);
> }
> It works OK if the passed in lambda function is syntactically correct.
> But it fails disastrously if the function contains errors...

Please note: the code snippets are taken from EQL. (I hope this helps.)

Fully protected function calls:

    const cl_env_ptr l_env = ecl_process_env();
    CL_CATCH_ALL_BEGIN(l_env) {
        CL_UNWIND_PROTECT_BEGIN(l_env) {
            cl_funcall(1, (cl_object)function);

> A second question is... can I traverse lisp lists in C? I would like
> to collect everything into a C++ vector and pass that on to the
> engine's API.

Trivial traversing of Lisp lists:

    QStringList l;
    if(LISTP(l_list)) {
        cl_object l_el = l_list;
        while(l_el != Cnil) {
            l << toQString(cl_car(l_el));
            l_el = cl_cdr(l_el);

More information about the ecl-devel mailing list