Short-circuit evaluation: Difference between revisions

no edit summary
No edit summary
Line 2,225:
SSEVAL2+1^ROSETTA +3
TRUE</pre>
 
=={{header|Nanoquery}}==
Nanoquery does not short-circuit by default, so short-circuit logic functions have been implemented by nested ifs.
<lang nanoquery>def short_and(bool1, bool2)
global a
global b
if a(bool1)
if b(bool2)
return true
else
return false
end
else
return false
end
end
 
def short_or(bool1, bool2)
if a(bool1)
return true
else
if b(bool2)
return true
else
return false
end
end
end
 
def a(bool)
println "a called."
return bool
end
 
def b(bool)
println "b called."
return bool
end
 
println "F and F = " + short_and(false, false) + "\n"
println "F or F = " + short_or(false, false) + "\n"
 
println "F and T = " + short_and(false, true) + "\n"
println "F or T = " + short_or(false, true) + "\n"
 
println "T and F = " + short_and(true, false) + "\n"
println "T or F = " + short_or(true, false) + "\n"
 
println "T and T = " + short_and(true, true) + "\n"
println "T or T = " + short_or(true, true) + "\n"</lang>
{{out}}
<pre>a called.
F and F = false
 
a called.
b called.
F or F = false
 
a called.
F and T = false
 
a called.
b called.
F or T = true
 
a called.
b called.
T and F = false
 
a called.
T or F = true
 
a called.
b called.
T and T = true
 
a called.
T or T = true
</pre>
 
=={{header|Nemerle}}==
Anonymous user