eval

The (r6rs eval) library allows a program to create Scheme expressions as data at run time and evaluate them.

procedure:  (eval expression environment-specifier) 

Evaluates expression in the specified environment and returns its value. Expression must be a valid Scheme expression represented as a datum value, and environment-specifier must be a library specifier, which can be created using the environment procedure described below.

If the first argument to eval is not a syntactically correct expression, then eval must raise an exception with condition type &syntax. Specifically, if the first argument to eval is a definition or a splicing begin form containing a definition, it must raise an exception with condition type &syntax.

procedure:  (environment import-spec ...) 

Import-spec must be a datum representing an <import spec> (see report section on “Library form”). The environment procedure returns an environment corresponding to import-spec

The bindings of the environment represented by the specifier are immutable: If eval is applied to an expression that attempts to assign to one of the variables of the environment, eval must raise an exception with a condition type &assertion.

(library (foo)
  (export)
  (import (r6rs))
  (write
    (eval ’(let ((x 3)) x)
          (environment ’(r6rs))))) 
  writes 3

(library (foo)
  (export)
  (import (r6rs))
  (write
    (eval
      ’(eval:car (eval:cons 2 4))
      (environment
        ’(prefix (only (r6rs) car cdr cons null?)
                 eval:))))) 
  writes 2