%eclent;
]>
Data and control flowC Referenceecl_bds_bindBind a special variableFunctionsecl_bds_bindcl_env_ptr cl_envcl_object varcl_object valueecl_bds_pushcl_env_ptr cl_envcl_object varDescriptionEstablishes a variable binding for the symbol var in the Common Lisp environment env, assigning it value.This macro or function is the equivalent of LET* and LET.ecl_bds_push does a similar thing, but reuses the old value of the same variable. It is thus the equivalent of (LET ((VAR VAR)) ...)Every variable binding must undone when no longer needed. It is best practice to match each call to ecl_bds_bind by another call to ecl_bds_unwind in the same function.ecl_bds_unwindUndo one variable bindingFunctionecl_bds_unwind1cl_env_ptr cl_envecl_bds_unwind_ncl_env_ptr cl_envint nDescriptionecl_bds_unwind1 undoes the outermost variable binding, restoring the original value of the symbol in the process.ecl_bds_unwind_n does the same, but for the n last variables.Every variable binding must undone when no longer needed. It is best practice to match each call to ecl_bds_bind by another call to ecl_bds_unwind in the same function.ECL_SETC equivalent of setMacroECL_SETcl_object varcl_object valueDescriptionAssigns a global value to the symbol var. Note that this global value might be overriden by special variable bindings, including the ones that are active when ECL_SET is usedThis macro is of set.ECL_SETQC equivalent of setqMacroECL_SETQcl_env_ptr cl_envcl_object varcl_object valueDescriptionAssigns value to the special variable denoted by the symbol var, in the Common Lisp environment cl_env.This macro implements a variable assignment, not a variable binding. It is thus the equivalent of setq.ecl_symbol_valueC equivalent of symbol-valueFuncitonecl_symbol_valuecl_env_ptr cl_envcl_object varDescriptionRetrieves the value of the special variable or constant denoted by the symbol var, in the Common Lisp environment cl_env.This function implements the equivalent of symbol-value and works both on special variables and constants.If the symbol is not bound, an error is signaled.ecl_va_argAccepting a variable number of argumentsMacrostypedef struct { ... } ecl_va_list[1];ecl_va_startecl_va_list arglistlast_argumentnargn_ordinarycl_object ecl_va_argecl_va_list arglistcl_object ecl_va_endecl_va_list arglistDescriptionThe macros above are used to code a function that accepts an arbitrary number of arguments. We will describe them in a practical example
cl_object my_plus(cl_narg narg, cl_object required1, ...)
{
cl_env_ptr env = ecl_process_env();
cl_object other_value;
ecl_va_list varargs;
ecl_va_start(varargs, required1, narg, 1);
while (narg > 1) {
cl_object other_value = ecl_va_arg(varargs);
required1 = ecl_plus(required1, other_value);
}
ecl_va_end(varargs);
ecl_return1(env, required1);
}
The first thing to do is to declare the variable that will hold the arguments. This is varargs in our example and it has the type ecl_va_list.This arguments list is initialized with the ecl_va_start macro, based on the supplied number of arguments, narg, the number of required arguments which are passed as ordinary C arguments (1 in this case), the last such ordinary arguments, required, and the buffer for the argument list, varargs.Once varargs has been initialized, we can retrieve these values one by one using ecl_va_arg. Note that the returned value always has the type cl_object, for it is always a Common Lisp object.The last statement before returning the output of the function is ecl_va_end. This macro performs any required cleanup and should never be omitted.ecl_nth_value, ecl_nvaluesAccessing output valuesFunctions and macroscl_object ecl_nvaluescl_env_ptr envcl_object ecl_nth_valuecl_env_ptr envint nDescriptionCommon Lisp functions may return zero, one or more values. In &ECL;, the first two cases do not require any special manipulation, as the C function returns either NIL or the first (zeroth) value directly. However, if one wishes to access additional values from a function, one needs to use these two macros or functionsecl_nvalues(env) returns the number of values that the function actually outputs. The single argument is the lisp environment. This value is larger or equal to 0 and smaller than ECL_MULTIPLE_VALUES_LIMIT.Once we know the number of return values, they can be directly accessed using the function ecl_nth_value(env,n), where n is a number larger than or equal to 1, and smaller than ECL_MULTIPLE_VALUES_LIMIT, which must correspond to a valid output value. No checking is done.Note that in both cases these macros and functions have to be used right after the Lisp function was called. This is so because other Lisp functions might destroy the content of the return stack.ExampleA C/C++ exceprt
cl_env_ptr env = ecl_process_env();
cl_object a = ecl_make_fixnum(13);
cl_object b = ecl_make_fixnum(6);
cl_object modulus = cl_floor(2, a, b);
cl_object remainder = ecl_nth_value(env, 1);
The somewhat equivalent Common Lisp code
(multiple-value-bind (modulus equivalent)
(floor 13 6))
ecl_return0, ecl_return1, ...Returning multiple valuesecl_return0cl_env_ptr cl_envecl_return1cl_env_ptr cl_envcl_object value1ecl_return2cl_env_ptr cl_envcl_object value1cl_object value2ecl_return3cl_env_ptr cl_envcl_object value1cl_object value2cl_object value3DescriptionReturns N values from a C/C++ function in a way that a Common Lisp function can recognize and use them. The 0-th value is returned directly, while values 1 to N are stored in the Common Lisp environment cl_env. This macro has to be used from a function which returns an object of type cl_object.ECL_BLOCK_BEGINC macro for blockECL_BLOCK_BEGIN(env,code) {} ECL_BLOCK_END;DescriptionECL_BLOCK_BEGIN establishes a block named code that becomes visible for the Common Lisp code. This block can be used then as a target for cl_return.env must be the value of the current Common Lisp environment, obtained with ecl_process_env.The C/C++ program has to ensure that the code in ECL_BLOCK_END gets executed, avoiding a direct exit of the block via goto or a C/C++ return.ECL_CATCH_BEGINC macro for catchECL_CATCH_BEGIN(env,tag) {} ECL_CATCH_END;DescriptionECL_CATCH_BEGIN establishes a destination for throw with the code given by tag.env must be the value of the current Common Lisp environment, obtained with ecl_process_env.The C/C++ program has to ensure that the code in ECL_CATCH_END gets executed, avoiding a direct exit of the catch block via goto or a C/C++ return.ECL_UNWIND_PROTECT_BEGINC macro for unwind-protectECL_UNWIND_PROTECT_BEGIN(env) {} ECL_UNWIND_PROTECT_EXIT {} ECL_UNWIND_PROTECT_END;DescriptionECL_UNWIND_PROTECT_BEGIN establishes two blocks of C code that work like the equivalent ones in Common Lisp: a protected block, contained between the "BEGIN" and the "EXIT" statement, and the exit block, appearing immediately afterwards. The form guarantees that the exit block is always executed, even if the protected block attempts to exit via som nonlocal jump construct (throw,return, etc).env must be the value of the current Common Lisp environment, obtained with ecl_process_env.The utility of this construct is limited, for it only protects against nonlocal exits caused by Common Lisp constructs: it does not interfere with C goto, return or with C++ exceptions.ANSI Dictionary&ANSI-C-Dict;Lisp symbolC function or constantapplycl_object cl_apply(cl_narg narg, cl_object function, ...)call-arguments-limitECL_CALL_ARGUMENTS_LIMITcompiled-function-pcl_object cl_compiled_function_p(cl_object object)complementcl_object cl_complement(cl_object function)constantlycl_object cl_constantly(cl_object value)everycl_object cl_every(cl_narg narg, cl_object predicate, ...)eqcl_object cl_eq(cl_object x, cl_object y)eqlcl_object cl_eql(cl_object x, cl_object y)equalcl_object cl_equal(cl_object x, cl_object y)equalpcl_object cl_equalp(cl_object x, cl_object y)fboundpcl_object cl_fboundp(cl_object function_name)fdefinitioncl_object cl_fdefinition(cl_object function_name)fmakunboundcl_object cl_fmakunbound(cl_object function_name)funcallcl_object cl_funcall(cl_narg narg, cl_object function, ...)function-lambda-expressioncl_object cl_function_lambda_expression(cl_object function)functionpcl_object cl_functionp(cl_object object)get-setf-expansioncl_object cl_get_setf_expansion(cl_narg narg, cl_object place, ...)identitycl_object cl_identity(cl_object x)LET, LET*cl_object ecl_bds_bind(cl_env_ptr env, cl_object symbol, cl_object value)lambda-parameters-limitECL_LAMBDA_PARAMETERS_LIMITmultiple-values-limitECL_MULTIPLE_VALUES_LIMITnotcl_object cl_not(cl_object object)noteverycl_object cl_notevery(cl_narg narg, cl_object predicate, ...)notanycl_object cl_notany(cl_narg narg, cl_object predicate, ...)setcl_object ECL_SET(cl_object symbol, cl_object value)setqcl_object ECL_SETQ(cl_env_ptr env, cl_object symbol, cl_object value)symbol-valuecl_object ecl_symbol_value(cl_env_ptr env, cl_object symbol)somecl_object cl_some(cl_narg narg, cl_object predicate, ...)values-listcl_object cl_values_list(cl_object list)Description