0
$\begingroup$

I was just reading this question regarding the difference between environment and memory. However, the textbook in question, Essentials of Programming Languages, third edition, by Friedman and Wand, also has chapter 4 State, which, as it says, discussed the concept of state. But, as far as I can tell, it doesn't seem to explicitly differentiate between environment, memory, and state, and it is unclear to me what the difference is. What is the precise difference between state and environment and memory?

$\endgroup$
0

2 Answers 2

2
$\begingroup$

Very informally:

An environment is a set of pairs (variable+value) that are accessible to a particular object/process during its execution.

A memory is a set of "locations" in which an object/process can read/store information. Usually a location is associated with a variable and the value of the variable is stored in that location (or in several locations).

The state of an object/system is the set of values of the properties (variables) of the object/system in a particular point in time (during an execution or process).

The big picture:

  • variables are logical "names" for values that can change in time (modified during the execution). They are called constants (from the viewpoint of a particular object/process) if the object/process cannot modify them.

  • environment refers to a set of variables from the viewpoint of an object/process; the object/process can read or (if allowed) modify them. Note that the emphasis, when talking about "environment", is usually on the "variables", not their (current) values.

  • memory is the place where variables are stored. Note that memory is a concept that is at a lower (implementation) level. To define a high-level programming language there is no need to "talk about memory" unless you need to implement it on a real architecture; but it can be useful to understand other concepts such as variables or arrays.

  • state is a "dump" ("snapshot") of the variables+current values (hence implicitly also a dump of the memory where they are stored) in a particular point in time of the execution/process

$\endgroup$
-1
$\begingroup$

I believe you can consider state and environment to be the same thing. The difference is mostly when writing logical deductions. The environment is the context that makes a given proposition true and may be a just a part of the global state. What memory introduces is aliasing; $A[i] = x$ may be falsified by a preceding $A[j] \leftarrow y$ if $i = j$. Without memory you don't have aliasing and the value of a variable is always the last value assigned to it.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.