schemeinterpreter

What is environment for an interpreter?


I'm taking a course named Programming Language Principles. It introduces design of a simple interpreter.

And gere's one piece code of this interpreter:

(define valof
 (lambda (exp env)
  (dmatch exp
    [,sym (guard (symbol? sym)) (env sym)]
    ... )))

I want to know what is environment in an interpreter.


Solution

  • In an interpreter like the one you're looking at, the environment is the object that associates values with variable names. Typically it is a list of frames, and each frame is a list of variable bindings.

    Take a look at Structure and Interpretation of Computer Programs for a discussion of how an evaluator uses an environment.