Jump to content

Short-circuit evaluation: Difference between revisions

no edit summary
No edit summary
Line 2,388:
x = a(i) and b(i); print ""
y = a(i) or b(i)</syntaxhighlight>
 
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
Module Short_circuit_evaliation {
function a(a as boolean) {
=a
doc$<=format$(" Called function a({0}) -> {0}", a)+{
}
}
function b(b as boolean) {
=b
doc$<=format$(" Called function b({0}) -> {0}", b)+{
}
}
boolean T=true, F, iv, jv
variant L=(F, T), i, j
i=each(L)
global doc$ : document doc$
while i
j=each(L)
while j
(iv, jv)=(array(i), array(j))
doc$<=format$("Calculating x = a({0}) and b({1}) -> {2}", iv, jv, iv and jv)+{
}
x=if(a(iv)->b(jv), F)
doc$<=format$("Calculating y = a({0}) or b({1}) -> {2}", iv, jv, iv or jv)+{
}
y=if(a(iv)->T, b(jv))
doc$<={
}
end while
end while
clipboard doc$
report doc$
}
Short_circuit_evaliation
</syntaxhighlight>
{{out}}
<pre>
Calculating x = a(False) and b(False) -> False
Called function a(False) -> False
Calculating y = a(False) or b(False) -> False
Called function a(False) -> False
Called function b(False) -> False
 
Calculating x = a(False) and b(True) -> False
Called function a(False) -> False
Calculating y = a(False) or b(True) -> True
Called function a(False) -> False
Called function b(True) -> True
 
Calculating x = a(True) and b(False) -> False
Called function a(True) -> True
Called function b(False) -> False
Calculating y = a(True) or b(False) -> True
Called function a(True) -> True
 
Calculating x = a(True) and b(True) -> True
Called function a(True) -> True
Called function b(True) -> True
Calculating y = a(True) or b(True) -> True
Called function a(True) -> True
</pre>
 
=={{header|Maple}}==
404

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.