I've been reading up on programming languages to better my understanding with the textbook Essentials of Programming Languages (3e) - Friedman & Wand.
In a chapter regarding the states of languages (i.e. when we account for the effects that a computation may have rather than the immediately evaluated value), I've noticed that the terms environment and memory are used frequently, but I'm not sure how to grasp the difference.
According to the text, "an environment associates a value with each element of a finite set of variables," and "memory is a finite map from locations to a set of values called stored values."
Does this mean that environments are a part of memory? The part that especially confuses me is when we "extend the environment."
To give a short example, if I had a procedure such that
let f = proc (x) (x + 1) in
f (1)
then the text states that we "extend our environment" so variable f
points to a location (say, l1
) and argument x
points to l2
.
l1
in turn points to the procedure tuple (x, (x + 1), empty_env)
, and finally l2
points to the actual argument 1
.
We update the location contents according to the procedure, which means we update l2
with 2
, and the program finally returns 2
.
Thank you.