CPS710 |
Assignment 5 | |
Semantics of HL - Part 2 |
HL defines one additional special scope: in a set former expression, the set former variable is implicitly declared as a NUM variable whose scope is the condition of set former only, i.e. between the vertical bar and the closing curly bracket of the set former. Note that this scope does not include the set former's domain because the definition would end up being self-referential.
These semantics mean that the following two code snippets produce the same result:
Loop1:
for i in {1,2,3},4,{5} do println i; end; | Result:
1 2 3 4 5 | Loop 2:
for i in 1,2,{3,4},5 do println i; end; | Result:
1 2 3 4 5 |
Loop1:
for i in 5,4,3,2,1 do println i; end; | Result:
5 4 3 2 1 | Loop 2:
for i in {5,4,3,2,1} do println i; end; | Result:
1 2 3 4 5 |
A return statement which is inside nested function definitions applies to the innermost function definition, as is standard in most programming languages. For example, in the program:
return x; // this is an invalid return function a() function b() ... return y; // this is a return from b end; ... return z; // this is a return from a end;
The parameter of the return statement, when there is one, must evaluate to a value of the same type as the return type as the function. The value of that parameter is the value of the entire function call.
When the return statement doesn't have any parameters, the value of the entire function call is null.