Next: , Previous: Error messages, Up: GH


19.5 Executing Scheme code

Once you have an interpreter running, you can ask it to evaluate Scheme code. There are two calls that implement this:

— C Function: SCM gh_eval_str (char *scheme_code)

This asks the interpreter to evaluate a single string of Scheme code, and returns the result of the last expression evaluated.

Note that the line of code in scheme_code must be a well formed Scheme expression. If you have many lines of code before you balance parentheses, you must either concatenate them into one string, or use gh_eval_file.

— C Function: SCM gh_eval_str_with_catch (const char *scheme_code, scm_catch_handler_t handler)

Read and evaluate scheme_code, throwing to handler if necessary.

The next two functions use the standard handler, which writes a short message to stderr [not to current-error-port, sounds like a bug –ttn], and the catch tag to the current-output-port.

— C Function: SCM gh_eval_str_with_standard_handler (const char *scheme_code)

Read and evaluate scheme_code, catching exceptions using the standard handler.

— C Function: SCM gh_eval_str_with_stack_saving_handler (const char *scheme_code)

Read and evaluate scheme_code, saving the stack in case of exception.

— C Function: SCM gh_eval_file (char *fname)
— C Function: SCM gh_load (char *fname)

gh_eval_file is completely analogous to gh_eval_str, except that a whole file is evaluated instead of a string. gh_eval_file returns SCM_UNSPECIFIED.

gh_load is identical to gh_eval_file (it's a macro that calls gh_eval_file on its argument). It is provided to start making the gh_ interface match the R5RS Scheme procedures closely.

— C Function: SCM gh_eval_file_with_catch (const char *filename, scm_catch_handler_t handler)

Read and evalutate scheme code from file filename, throwing to handler if necessary.

— C Function: SCM gh_eval_file_with_standard_handler (const char *filename)

Read and evaluate scheme code from file filename, catching exceptions using the standard handler.