Evaluators

In order to specify the behaviors upon an error and an interrupt(signal), set an appropriate function to each of the special variables *error-handler* and *signal-handler* in advance. There is no correctable or continue-able error. After analyzing errors you must abort the current execution by reset or appropriate throw to upper level catchers. reset is equivalent to (throw 0 NIL), since EusLisp's top-level creates catch frame named 0.

Error handlers should be programmed as functions with three or four arguments: code msg1 form &optional (msg2). Code is the error code which identifies system defined errors, such as 14 for 'mismatch argument' or 13 for 'undefined function'. These mappings are described in "c/eus.h". msg1 and msg1 are messages displayed to the user. form is the S-expression which caused the error.

Signal handlers should be programmed as functions receiving two arguments: sig and code. Sig is the signal number ranging from 1 to 31, and code is the minor signal code defined in signal-number dependent manners.

^D (end-of-file) at the top-level terminates eus session. This is useful when eus is programmed as a filter.

Eval-dynamic is the function to find the dynamic value bound to a symbol used as a let or lambda variable. This is useful for debugging.



identity obj [function]

returns obj itself. Note the difference between identity and quote. identity is a function whereas quote is a special form. Therefore, (identity 'abc) is evaluated to abc and (quote 'abc) == (quote (quote abc)) is evaluated to 'abc. Identity is often used as the default value for :key parameters of many generic sequence functions.


eval form [environment] [function]

evaluates form and returns its value. Hook function can be called before entering the evaluation, if *evalhook* is set to some function that accept form and environment.


apply func &rest args [function]

func is applied to args. Func must be evaluated to be a function symbol (a symbol which has a function definition), a lambda form, or a closure. Macros and special forms cannot be applied. The last element of args must be a list of arguments while other args should be bare arguments. Thus, if the last args is NIL, then apply is almost equivalent to funcall, except that apply has one more arguments than funcall. (apply #'max 2 5 3 '(8 2)) -> 8.


funcall func &rest args [function]

applies func to args. The number of args must coincide to the number of arguments the func requests.


quote obj [special]

evaluates to obj itself.


function func [special]

makes a function closure. If func is a symbol, its function definition is retrieved.


evalhook hookfunc form [env] [function]

evaluates form once after binding hookfunc to *evalhook*.


eval-dynamic variable [function]

finds the value of variable (symbol) on the stack.


macroexpand form [function]

expands form if it is a macro call. If form is expanded to a macro call again, expansion is repeated until non macro call results.


eval-when situation {form}* [special]

Situation is a list of compile, load and eval. Forms are evaluated when the current execution mode matches with situation. eval-when is important to control the behavior and environment of the compiler. If compile is specified, forms are evaluated by the compiler so that the result will affect the consequent compilation. For example, defmacro should be evaluated by the compiler in order to let the compiler expand macro calls at compile time. If load is given in the situation list, forms are compiled to be loaded (evaluated) at load time, i.e., compiled functions are defined at load time. This is the normal effect that we expect to the compiler. load situation is used to control the compiler's environment. If eval is included in situation list, forms are evaluated when their source code is loaded.


the type form [special]

Declares form is of type. type is either a class object, :integer, :fixnum, or :float.


declare declaration* [special]

Each declaration is a list of a declaration specifier and an integer or target symbols. Declarations are important to let the compiler produce faster code.
special declares special variables
type declares the type of variables; (type integer count); valid type specifiers are integer, :integer fixnum, :float and float. The type keyword may be omitted if type specifier is either one listed here. So (integer count) is a correct declaration. Other types (classes) such as float-vector, integer-vector, etc. need to be preceded by type, as (type float-vector vec1).
ftype declares the result type of functions
optimize set *optimize* parameter (0-3) of the compiler
safety set *safety* parameter (0-3) of the compiler
space set *space* parameter (0-3) of the compiler
inline not recognized
not-inline not recognized


proclaim proclamation [function]
globally declares the types of variables and compiler options. The same declarations are accepted as described for declare special form. However, proclaim is a function of one argument and proclamation is evaluated.


warn format-string &rest args [function]

prints warning-message given as format-string and args to *error-output*.


error format-string &rest args [function]
calls the current error-handler function bound to *error-handler*. The default error-handler 'euserror' first prints arguments to *error-output* using format, then enters a new top level session. The prompt shows you the depth of your error session. Throwing to the number, you can go back to the lower level error session.


In the multithread EusLisp, special variables are shared among threads and the same *error-handler* is referenced by different threads. To avoid this inconvenience, multithread EusLisp provides the install-error-handler function which installs different error handler for each thread.



install-error-handler handler [function]

installs the handler as the error handler of the current thread.


k-okada 2013-05-21