Format of the Semantic Structure Diagrams and a Discussion of Scope in Scheme
Scope in Scheme
In a high level programming language, environment refers to the set of identifiers, values, and identifiers bound to values that can be accessed (are visible) from a particular point in a piece of code, with respect to the scope rules in effect at that particular time. In Scheme, lexical (block) scoping is used, as opposed to dynamic scoping, which is used in languages such as the scripting language Perl. Lexical scoping is called just that because the scope of a particular binding can be assessed from a just a textual analysis of a program. In this example,
(let ((x 1)) (let ((x (+ x 2))) (+ x x))) => 6The outer let expression binds 1 to x. This binding is visible within the outer let's body, which is actually the inner let. In the inner let, x is bound to the expression (+ x 2) within it's body, which is the expression (+ x x). Inner binding is said to be in the shadow of the outer binding. So, when this statement is evaluated, x is bound to 1, and since it is visible to the inner let only, but not its body, the value is used to evaluated (+ x 2), which is 3. That value obtained, the innermost expression, the (+ x x), can see the value 3 bound to x, and evaluate to 6. This can and was all determined by a simple textual analysis of this let statement. Scheme code examples will always be color coded blue. Semantic Notation
Environment
The notation Env_xx is used throughout the semantic discussions in this paper. Env_0 is always used at the beginning on a semantic diagram. I am using the top level digit (the digit directly following the underscore) to represent the toplevel scope in each diagram. If there is another digit, for example, Env_02, the 2 represents a scope area below, that is, contained within and in the shadow of the outer scope. Environment is colored coded red.
Returns
Returns in the semantic diagrams return a value to the toplevel scope to be used for something, such as output in that scope, and shown as 'Return:value'. Returns are colored coded green.
Input/Output
I/O operations are represented by 'I/O_x', where the x is a numeric digit. I/O operations are shown when the statement being described is expected to output some evaluated value at the end of its interpretation. I/O operations are color coded purple.
Other code
All other Scheme code, such as keywords, parentheses, and expressions, are represented in brown.