Short-circuit evaluation: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(4 intermediate revisions by 4 users not shown)
Line 1,226:
<syntaxhighlight lang="e">def x := a(i) && (def funky := b(j))</syntaxhighlight>
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|EasyLang}}==
<syntaxhighlight lang=easylang>
func a x .
print "->a: " & x
return x
.
func b x .
print "->b: " & x
return x
.
print "1 and 1"
if a 1 = 1 and b 1 = 1
print "-> true"
.
print ""
print "1 or 1"
if a 1 = 1 or b 1 = 1
print "-> true"
.
print ""
print "0 and 1"
if a 0 = 1 and b 1 = 1
print "-> true"
.
print ""
print "0 or 1"
if a 0 = 1 or b 1 = 1
print "-> true"
.
</syntaxhighlight>
 
=={{header|Ecstasy}}==
Line 1,287 ⟶ 1,318:
 
=={{header|Elena}}==
ELENA 56.0x :
<syntaxhighlight lang="elena">import system'routines;
import extensions;
Func<bool, bool> a = (bool x){ console.writeLine:("a"); ^ x };
Func<bool, bool> b = (bool x){ console.writeLine:("b"); ^ x };
const bool[] boolValues = new bool[]{ false, true };
Line 1,299 ⟶ 1,330:
public program()
{
boolValues.forEach::(bool i)
{
boolValues.forEach::(bool j)
{
console.printLine(i," and ",j," = ",a(i) && b(j));
Line 1,736 ⟶ 1,767:
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Short-circuit_evaluation}}
 
'''Solution'''
 
[[File:Fōrmulæ - Short-circuit evaluation 01.png]]
 
[[File:Fōrmulæ - Short-circuit evaluation 02.png]]
 
=={{header|Go}}==
Line 1,954 ⟶ 1,991:
Shortcircuit.icn: 16 | true returned &null
i,j := procedure true, procedure true</pre>
 
=={{header|Insitux}}==
{{trans|Clojure}}
<syntaxhighlight lang="insitux">
(let a (fn (print-str "a ") %)
b (fn (print-str "b ") %)
f (pad-right " " 6))
 
(for i [true false] j [true false]
(print-str (f i) "OR " (f j) " = ")
(print (or (a i) (b j)))
(print-str (f i) "AND " (f j) " = ")
(print (and (a i) (b j))))
</syntaxhighlight>
{{out}}
<pre>
true OR true = a true
true AND true = a b true
true OR false = a true
true AND false = a b false
false OR true = a b true
false AND true = a false
false OR false = a b false
false AND false = a false
</pre>
 
=={{header|Io}}==
Line 5,077 ⟶ 5,139:
=={{header|Wren}}==
Wren has the '''&&''' and '''||''' short-circuiting operators found in many C family languages.
<syntaxhighlight lang="ecmascriptwren">var a = Fn.new { |bool|
System.print(" a called")
return bool
9,482

edits