Anonymous user
Logical operations: Difference between revisions
m
Fixed lang tags.
Underscore (talk | contribs) (Added Perl 6.) |
m (Fixed lang tags.) |
||
Line 10:
All the operators below work equally well on arrays of boolean types. In fact, a packed array of boolean is an array of bits, providing a direct link between logical and bitwise operations.
=={{header|ALGOL 68}}==
)</lang>▼
=={{header|AutoHotkey}}==
<lang AutoHotkey>a = 1
Line 49:
msgbox % "not a is " . (!a)</lang>
=={{header|AWK}}==
<lang awk>$ awk '{print "and:"($1&&$2),"or:"($1||$2),"not:"!$1}'▼
▲$ awk '{print "and:"($1&&$2),"or:"($1||$2),"not:"!$1}'
0 0
and:0 or:0 not:1
Line 88 ⟶ 87:
=={{header|ColdFusion}}==
=={{header|Common Lisp}}==
Line 161 ⟶ 160:
=={{header|Erlang}}==
<lang Erlang>1> true and false.
false
2> false or true.
Line 171 ⟶ 169:
true
5> not (true and true).
false</lang>
▲</lang>
=={{header|FALSE}}==
FALSE uses zero/non-zero for testing False and True. Comparison operators return -1 for True and 0 for False, which work with bitwise operators for logical operations.
=={{header|Forth}}==
Forth can use bitwise operators if the boolean values are well formed: TRUE (-1) and FALSE (0). '''0<>''' converts an ill-formed flag (zero/non-zero) to a well-formed flag (false/true).
=={{header|Fortran}}==
Line 261 ⟶ 258:
Instead of a function and printing, which is unidiomatic for Haskell, here are the operations in the same style as in [[Bitwise operations]]:
=={{header|Io}}==
)</lang>▼
=={{header|J}}==
Line 284 ⟶ 281:
An example more closely following the others on this page (J is interactive so indented lines are user-entered and lines flush left are system outputs):
▲ and=: *.
or=: +.
not=: -.
Line 293 ⟶ 289:
0 0 0 1
0 1 1 1
1 1 0 0</lang>
=={{header|Java}}==
Line 315 ⟶ 310:
=={{header|Logo}}==
The boolean literals are used as words ("true and "false) when used in a program.
AND and OR may have arity greater than two if used in parentheses (and :a :b :c).
=={{header|M4}}==
<lang m4>define(`logical',
`and($1,$2)=eval($1&&$2) or($1,$2)=eval($1||$2) not($1)=eval(!$1)')
logical(1,0)</lang>
▲</lang>
Output:
Line 336 ⟶ 329:
=={{header|Mathematica}}==
<lang Mathematica>And[a,b,...]
Not[a]</lang>▼
▲</lang>
And can also be given using the infix operator &&, Or can also be used using the infix operator ||. Not[a] can also be written as !a.
Furthermore Mathematica supports:
<lang Mathematica>Xor[a, b,...]
</lang>▼
Note that the functions are not restricted to 2 arguments; any number of arguments are allowed (except for the function Not).
All these functions can also be used with infix operators, the characters for that are: \[Xor], \[Nand], \[Nor], and \[Xnor]. Or by typing [escape] [name boolean operator] [escape].
=={{header|MAXScript}}==
▲)</lang>
=={{header|Metafont}}==
Line 418 ⟶ 407:
=={{header|Pascal}}==
<lang pascal>procedure printlogic(a, b: boolean);
begin
writeln('a and b is ', a and b);
writeln('a or b is ', a or b);
writeln('not a is', not a);
end;</lang>
</lang>▼
=={{header|Perl}}==
Line 460 ⟶ 447:
=={{header|Pop11}}==
<lang pop11>define print_logic(a, b);▼
▲define print_logic(a, b);
printf(a and b, 'a and b is %p\n');
printf(a or b, 'a or b is %p\n');
printf(not(a), 'not a is %p\n');
enddefine;</lang>
Example usage is:
<lang pop11>print_logic(true, false);</lang>▼
▲print_logic(true, false);
=={{header|PowerShell}}==
Line 525 ⟶ 508:
=={{header|Slate}}==
func arity = 1 ifTrue: [inform: 'True ' ; (func as: String) ; ' = ' ; (func sendTo: {True}) printString.
inform: 'False ' ; (func as: String) ; ' = ' ; (func sendTo: {False}) printString.].
Line 534 ⟶ 516:
[ |:each| inform: each first printString ; (func as: String) ; each second printString ; ' = ' ; (func sendTo: each) printString]]
].</lang>
</lang>▼
Output:
True/\False = False
False/\True = False
Line 550 ⟶ 529:
False\/False = False
True not = False
False not = True</lang>
</lang>▼
=={{header|Smalltalk}}==
Line 586 ⟶ 564:
that are the same as the well-formed flags in Forth.
<lang
=={{header|V}}==
Using stack shuffles.
▲ ].</lang>
Using view.
▲ ].</lang>
Using internal defines
▲].</lang>
=={{header|Visual Basic .NET}}==
<lang
=={{header|XSLT}}==
</xsl:template>
|