Previous: Instances, Up: Lisp objects


3.11 Bytecodes

A bytecodes object is a lisp object with a piece of code that can be interpreted. The objects of type t_bytecode are implicitly constructed by a call to eval, but can also be explicitly constructed with the make_lambda function.

— Function: cl_object cl_safe_eval (cl_object form, cl_object env, cl_object err_value
— Function: cl_object cl_eval (cl_object form)

cl_safe_eval evaluates form in the lexical environment env, which can be nil. Before evaluating it, the expression form must be bytecompiled. cl_eval is the equivalent of cl_safe_eval but without environment and with err_value set to nil. It exists only for compatibility with previous versions.

          cl_object form = c_string_to_object("(print 1)");
          cl_safe_eval(form,Cnil);
          cl_safe_eval(form, Cnil);
— Function: cl_object si_make_lambda (cl_object name, cl_object def)

Builds an interpreted lisp function with name given by the symbol name and body given by def. For instance, we would achieve the equivalent of

          (funcall #'(lambda (x y) (block foo (+ x y)))
                   1 2)

with the following code

          cl_object def = c_string_to_object("((x y) (+ x y))");
          cl_object name = _intern("foo")
          cl_object fun = si_make_lambda(name, def);
          return funcall(fun, MAKE_FIXNUM(1), MAKE_FIXNUM(2));

Notice that si_safe_lambda performs a bytecodes compilation of the definition and thus it may signal some errors. Such errors are not handled by the routine itself you might consider using cl_safe_eval or cl_eval instead:

          cl_object def = c_string_to_object("#'(lambda-block foo (x y) (+ x y))");
          cl_object fun = cl_eval(def);
          return funcall(fun, MAKE_FIXNUM(1), MAKE_FIXNUM(2));