For Gauche 0.9.15Search (procedure/syntax/module):

Next: , Previous: , Up: Core library   [Contents][Index]

6.20 Eval and repl

Function: eval expr env

[R7RS eval] Evaluate expr under the environment env. In Gauche, env is just a <module> object.

R5RS and R7RS provide a portable way to obtain environment. R5RS way is described below. R7RS way is described in scheme.eval - R7RS eval.

Function: null-environment version
Function: scheme-report-environment version
Function: interaction-environment

[R5RS] Returns an environment specifier which can be used as the second argument of eval. Right now an environment specifier is just a module. (null-environment 5) returns a null module, which contains just the syntactic bindings specified in R5RS, (scheme-report-environment 5) returns a scheme module, which contains syntactic and procedure bindings in R5RS, and (interaction-environment) returns a user module that contains all the Gauche built-ins plus whatever the user defined. It is possible that the Gauche adopts a first-class environment object in future, so do not rely on the fact that the environment specifier is just a module.

An error is signaled if a value other than 5 is passed as version argument.

Function: read-eval-print-loop :optional reader evaluator printer prompter

This exports Gosh’s default read-eval-print loop to applications. Each argument can be #f, which indicates it to use Gauche’s default procedure(s), or a procedure that satisfies the following conditions.

reader

A procedure that takes no arguments. It is supposed to read an expression and returns it.

evaluator

A procedure that takes two arguments, an expression and an environment specifier. It is supposed to evaluate the expression and returns zero or more value(s).

printer

A procedure that takes zero or more arguments. It is supposed to print out these values. The result of this procedure is discarded.

prompter

A procedure that takes no arguments. It is supposed to print out the prompt. The result of this procedure is discarded.

Given those procedures, read-eval-print-loop runs as follows:

  1. Prints the prompt by calling prompter.
  2. Reads an expression by calling reader. If it returns EOF, exits the loop and returns from read-eval-print-loop.
  3. Evaluates an expression by calling evaluator
  4. Prints the result by calling printer, then repeats from 1.

When an error is signaled from one of those procedures, it is captured and reported by the default escape handler, then the loop restarts from 1.

It is OK to capture a continuation within those procedures and re-invoke them afterwards.


Next: , Previous: , Up: Core library   [Contents][Index]


For Gauche 0.9.15Search (procedure/syntax/module):