Logical operations: Difference between revisions

Added Quackery.
(Added Quackery.)
Line 2,868:
 
Note: Any normal object can be treated as a Boolean in Python. Numeric objects which evaluate to any non-zero value are "True" otherwise they are false. Non-empty strings, lists, tuples and other sequences are "True" otherwise they are false. The pre-defined ''None'' object is also treated as "False." In Python 2.3 pre-defined objects named ''True'' and ''False'' were added to the language; prior to that it was a common convention to include a line: ''False, True = 0, 1'' to use these as names. Custom classes which implement ''__nonzero__'' or ''__len__'' or some other special methods can be implicitly evaluated as Booleans based on those results.
 
=={{header|Quackery}}==
 
Quackery also has the boolean words <code>nand</code> and <code>xor</code>.
 
<lang Quackery> [ iff [ say "true" ]
else [ say "false"] ] is echobool ( b --> )
 
[ 2dup and
say "A and B is " echobool cr
over or
say "A or B is " echobool cr
not
say "not A is " echobool cr ] is task ( A B --> )</lang>
 
{{out}}
 
As a dialogue in the Quackery shell.
 
<pre>/O> true true task
...
A and B is true
A or B is true
not A is false
 
Stack empty.
 
/O> true false task
...
A and B is false
A or B is true
not A is false
 
Stack empty.
 
/O> false true task
...
A and B is false
A or B is true
not A is true
 
Stack empty.
 
/O> false false task
...
A and B is false
A or B is false
not A is true
 
Stack empty.</pre>
 
=={{header|R}}==
1,462

edits