Next: , Previous: Dynamic-Wind, Up: Standards Support


7.4.11 Eval

(require 'eval)

— Function: eval expression environment-specifier

Evaluates expression in the specified environment and returns its value. Expression must be a valid Scheme expression represented as data, and environment-specifier must be a value returned by one of the three procedures described below. Implementations may extend eval to allow non-expression programs (definitions) as the first argument and to allow other values as environments, with the restriction that eval is not allowed to create new bindings in the environments associated with null-environment or scheme-report-environment.

          (eval '(* 7 3) (scheme-report-environment 5))
                                                             ⇒  21
          
          (let ((f (eval '(lambda (f x) (f x x))
                         (null-environment))))
            (f + 10))
                                                             ⇒  20
— Function: scheme-report-environment version
— Function: null-environment version
— Function: null-environment

Version must be an exact non-negative integer n corresponding to a version of one of the Revised^n Reports on Scheme. Scheme-report-environment returns a specifier for an environment that contains the set of bindings specified in the corresponding report that the implementation supports. Null-environment returns a specifier for an environment that contains only the (syntactic) bindings for all the syntactic keywords defined in the given version of the report.

Not all versions may be available in all implementations at all times. However, an implementation that conforms to version n of the Revised^n Reports on Scheme must accept version n. An error is signalled if the specified version is not available.

The effect of assigning (through the use of eval) a variable bound in a scheme-report-environment (for example car) is unspecified. Thus the environments specified by scheme-report-environment may be immutable.

— Function: interaction-environment

This optional procedure returns a specifier for the environment that contains implementation-defined bindings, typically a superset of those listed in the report. The intent is that this procedure will return the environment in which the implementation would evaluate expressions dynamically typed by the user.

Here are some more eval examples:

     (require 'eval)
     ⇒ #<unspecified>
     (define car 'volvo)
     ⇒ #<unspecified>
     car
     ⇒ volvo
     (eval 'car (interaction-environment))
     ⇒ volvo
     (eval 'car (scheme-report-environment 5))
     ⇒ #<primitive-procedure car>
     (eval '(eval 'car (interaction-environment))
           (scheme-report-environment 5))
     ⇒ volvo
     (eval '(eval '(set! car 'buick) (interaction-environment))
           (scheme-report-environment 5))
     ⇒ #<unspecified>
     car
     ⇒ buick
     (eval 'car (scheme-report-environment 5))
     ⇒ #<primitive-procedure car>
     (eval '(eval 'car (interaction-environment))
           (scheme-report-environment 5))
     ⇒ buick