Logical operations: Difference between revisions

imported>Brie
(Add Nu)
 
(4 intermediate revisions by 3 users not shown)
Line 911:
print "not a: ", !a, "\n"
}</syntaxhighlight>
 
=={{header|Binary Lambda Calculus}}==
Minimal definitions of the logical operations in lambda calculus are: and = <code>\a\b.a b a</code>, or = <code>\a\b.a a b</code>, not = <code>\b\x\y.b y x</code>. In BLC these are <code>00 00 01 01 110 10 110</code>, or = <code>00 00 01 01 110 110 10</code>, not = <code>00 00 00 01 01 1110 10 110</code> respectively.
 
=={{header|BQN}}==
Line 2,241 ⟶ 2,244:
 
=={{header|langur}}==
The logical operators in langur compare the "truthiness" of the left and right operands and do not require Booleans. A null is a non-truthy result.
 
The operators and, or, nand, nor, and?, or?, nand?, nor?, xor?, and nxor? are short-circuiting.
Line 2,247 ⟶ 2,250:
Operators that end with ? are null propagating or "database" operators, and will return null if either operand is null. They short-circuit differently than normal operators (only if the left operand is null).
 
<syntaxhighlight lang="langur">val .test = ffn(.a, .b) join("\n",{ [
join("\n", [
$"not \.a;: \{not .a}",
$"\not {{.a;}}: and{{not \.b;: \.a and .b;}}",
$"\{{.a;}} orand \{{.b;}}: \{{.a orand .b;}}",
$"\{{.a;}} nand \{{.b;}}: \{{.a nand .b;}}",
$"\{{.a;}} noror \{{.b;}}: \{{.a noror .b;}}",
$"\{{.a;}} xornor \{{.b;}}: \{{.a xornor .b;}}",
$"\{{.a;}} nxorxor \{{.b;}}: \{{.a nxorxor .b;}}",
"{{.a}} nxor {{.b}}: {{.a nxor .b}}",
"",
 
$"not? \.a;: \{not? .a}",
$"\.a; andnot? \{{.b;a}}: \.a and{{not? .b;a}}",
$"\{{.a;}} orand? \{{.b;}}: \{{.a orand? .b;}}",
$"\{{.a;}} nand? \{{.b;}}: \{{.a nand? .b;}}",
$"\{{.a;}} noror? \{{.b;}}: \{{.a noror? .b;}}",
$"\{{.a;}} xornor? \{{.b;}}: \{{.a xornor? .b;}}",
$"\{{.a;}} nxorxor? \{{.b;}}: \{{.a nxorxor? .b;}}",
"{{.a}} nxor? {{.b}}: {{.a nxor? .b}}",
"\n",
])
}
 
val .tests = [
Line 4,278 ⟶ 4,283:
 
However, it does support the short-circuiting ''&&'' and ''||'' logical operators as well as the conditional (or ternary) operator ''?:'' all of which behave as expected.
<syntaxhighlight lang="ecmascriptwren">var f = Fn.new { |a, b|
System.print("a = %(a)")
System.print("b = %(b)")
885

edits