Short-circuit evaluation: Difference between revisions

Content added Content deleted
(Added Dyalect programming language)
Line 884: Line 884:
end;
end;
end.</lang>
end.</lang>

=={{header|Dyalect}}==

{{trans|Swift}}

<lang dyalect>func a(v) {
print(nameof(a), terminator: "")
return v
}
func b(v) {
print(nameof(b), terminator: "")
return v
}
func test(i, j) {
print("Testing a(\(i)) && b(\(j))")
print("Trace: ", terminator: "")
print("\nResult: \(a(i) && b(j))")

print("Testing a(\(i)) || b(\(j))")
print("Trace: ", terminator: "")
print("\nResult: \(a(i) || b(j))")

print()
}
test(false, false)
test(false, true)
test(true, false)
test(true, true)</lang>

{{out}}

<pre>Testing a(false) && b(false)
Trace: a
Result: false
Testing a(false) || b(false)
Trace: ab
Result: false

Testing a(false) && b(true)
Trace: a
Result: false
Testing a(false) || b(true)
Trace: ab
Result: true

Testing a(true) && b(false)
Trace: ab
Result: false
Testing a(true) || b(false)
Trace: a
Result: true

Testing a(true) && b(true)
Trace: ab
Result: true
Testing a(true) || b(true)
Trace: a
Result: true</pre>


=={{header|E}}==
=={{header|E}}==
Line 895: Line 956:
<lang e>def x := a(i) && (def funky := b(j))</lang>
<lang e>def x := a(i) && (def funky := b(j))</lang>
The choice we make is that <code>funky</code> is ordinary if the right-side expression was evaluated, and otherwise is <em>ruined</em>; attempts to access the variable give an error.
The choice we make is that <code>funky</code> is ordinary if the right-side expression was evaluated, and otherwise is <em>ruined</em>; attempts to access the variable give an error.

=={{header|Elena}}==
=={{header|Elena}}==
ELENA 4.x :
ELENA 4.x :