Short-circuit evaluation: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 200:
---
</pre>
 
 
=={{header|AppleScript}}==
Line 634 ⟶ 633:
return 0;
}</lang>
 
=={{header|C++}}==
Just like C, boolean operators <nowiki>&&</nowiki> and || are shortcircuit operators.
<lang cpp>#include <iostream>
 
bool a(bool in)
{
std::cout << "a" << std::endl;
return in;
}
 
bool b(bool in)
{
std::cout << "b" << std::endl;
return in;
}
 
void test(bool i, bool j) {
std::cout << std::boolalpha << i << " and " << j << " = " << (a(i) && b(j)) << std::endl;
std::cout << std::boolalpha << i << " or " << j << " = " << (a(i) || b(j)) << std::endl;
}
 
int main()
{
test(false, false);
test(false, true);
test(true, false);
test(true, true);
return 0;
}</lang>
{{out}}
<pre>a
false and false = false
a
b
false or false = false
a
false and true = false
a
b
false or true = true
a
b
true and false = false
a
true or false = true
a
b
true and true = true
a
true or true = true</pre>
 
=={{header|C sharp|C#}}==
Line 745 ⟶ 693:
a
True or True = True</lang>
 
=={{header|C++}}==
Just like C, boolean operators <nowiki>&&</nowiki> and || are shortcircuit operators.
<lang cpp>#include <iostream>
 
bool a(bool in)
{
std::cout << "a" << std::endl;
return in;
}
 
bool b(bool in)
{
std::cout << "b" << std::endl;
return in;
}
 
void test(bool i, bool j) {
std::cout << std::boolalpha << i << " and " << j << " = " << (a(i) && b(j)) << std::endl;
std::cout << std::boolalpha << i << " or " << j << " = " << (a(i) || b(j)) << std::endl;
}
 
int main()
{
test(false, false);
test(false, true);
test(true, false);
test(true, true);
return 0;
}</lang>
{{out}}
<pre>a
false and false = false
a
b
false or false = false
a
false and true = false
a
b
false or true = true
a
b
true and false = false
a
true or false = true
a
b
true and true = true
a
true or true = true</pre>
 
=={{header|Clojure}}==
Line 1,224 ⟶ 1,223:
a(true) || b(true): true
</pre>
 
=={{header|Fōrmulæ}}==
 
In [https://wiki.formulae.org/Short-circuit_evaluation this] page you can see the solution of this task.
 
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text ([http://wiki.formulae.org/Editing_F%C5%8Drmul%C3%A6_expressions more info]). Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for transportation effects more than visualization and edition.
 
The option to show Fōrmulæ programs and their results is showing images. Unfortunately images cannot be uploaded in Rosetta Code.
 
=={{header|Forth}}==
Line 1,411 ⟶ 1,402:
x = false y = true
</pre>
 
=={{header|Fōrmulæ}}==
 
In [https://wiki.formulae.org/Short-circuit_evaluation this] page you can see the solution of this task.
 
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text ([http://wiki.formulae.org/Editing_F%C5%8Drmul%C3%A6_expressions more info]). Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for transportation effects more than visualization and edition.
 
The option to show Fōrmulæ programs and their results is showing images. Unfortunately images cannot be uploaded in Rosetta Code.
 
=={{header|Go}}==
Line 2,753 ⟶ 2,752:
a(0) || b(1): AB
a(0) || b(0): AB</pre>
 
=={{header|Perl 6}}==
{{Works with|rakudo|2018.03}}
<lang perl6>use MONKEY-SEE-NO-EVAL;
 
sub a ($p) { print 'a'; $p }
sub b ($p) { print 'b'; $p }
 
for 1, 0 X 1, 0 -> ($p, $q) {
for '&&', '||' -> $op {
my $s = "a($p) $op b($q)";
print "$s: ";
EVAL $s;
print "\n";
}
}</lang>
{{out}}
<pre>a(1) && b(1): ab
a(1) || b(1): a
a(1) && b(0): ab
a(1) || b(0): a
a(0) && b(1): a
a(0) || b(1): ab
a(0) && b(0): a
a(0) || b(0): ab</pre>
 
=={{header|Phix}}==
Line 3,310 ⟶ 3,284:
a:#f b:#f
</pre>
 
=={{header|Raku}}==
(formerly Perl 6)
{{Works with|rakudo|2018.03}}
<lang perl6>use MONKEY-SEE-NO-EVAL;
 
sub a ($p) { print 'a'; $p }
sub b ($p) { print 'b'; $p }
 
for 1, 0 X 1, 0 -> ($p, $q) {
for '&&', '||' -> $op {
my $s = "a($p) $op b($q)";
print "$s: ";
EVAL $s;
print "\n";
}
}</lang>
{{out}}
<pre>a(1) && b(1): ab
a(1) || b(1): a
a(1) && b(0): ab
a(1) || b(0): a
a(0) && b(1): a
a(0) || b(1): ab
a(0) && b(0): a
a(0) || b(0): ab</pre>
 
=={{header|REXX}}==
Line 3,744:
a(0) || b(1): AB
a(0) || b(0): AB</pre>
 
=={{header|Simula}}==
<lang simula>BEGIN
Line 4,262 ⟶ 4,263:
a: Waar = x
a: Waar = x</pre>
 
=={{header|Visual Basic .NET}}==
{{trans|c++}}
10,333

edits