if e then e1 else e2where e, e1, and e2 are boolean expression, and the if-then-else has the usual (non-strict) semantics. Assume that we want to write, in this language, an expression like e1 && e2 in C, namely a non-strict conjunction with the following semantics:
r |- e1 eval false ---------------------------- r |- (e1 && e2) eval false r |- e1 eval true r |- e2 eval v ------------------------------------------ r |- (e1 && e2) eval v
if e1 then e2 else false
function non_strict_and(name e1, e2: boolean):boolean; begin if e1 then e2 else false end;Note: in Pascal syntax we should write the conditional as follows:
if e1 then non_strict_and := e2 else non_strict_and := falseCall by value would not do the job, because the parameters have to be evaluated before the function is executed (hence we would get a strict semantics). Call by reference and call by value-result are out of question, because they cannot allow as actual parameters generic expressions (only variables).
r |- e1 eval v1 r |- e2 eval v2 ----------------------------------------- if v1 = true or v2 = true r |- (e1 nor e2) eval false r |- e1 eval v1 r |- e2 eval v2 ----------------------------------------- if v1 = v2 = false r |- (e1 nor e2) eval true
x < 0 nor (x = 0 nor 1/x > 0)where x is an identifier of type integer. Say what are the results (true, false, or error) of the above expression, depending on the possible values of x.
let x = 0 in let y = x in let x = y + 1 in x + y end + x end end