Boolean values: Difference between revisions

m
(→‎Joy: add)
imported>Tromp
 
(20 intermediate revisions by 11 users not shown)
Line 426:
PRINT FALSE
PRINT TRUE</syntaxhighlight>
 
==={{header|Cherrycake}}===
The boolean value of true in Cherrycake is represented with a 'true' keyword, and the boolean value of false in Cherrycake is represented with a 'false' keyword. Booleans can also be represented with other types, such as binary and integers. In binary types, 0x01 and 0b01 represent true, and 0x00 and 0b00 represent false. In integer types, 1 represents true and 0 represents false.
 
==={{header|Commodore BASIC}}===
Line 548 ⟶ 551:
if not(2 < 1) then print "2 not < 1"
if not(1 = 0) then print "1 not = 0"</syntaxhighlight>
 
==={{header|SmallBASIC}}===
<syntaxhighlight lang="basic">
a = true
b = false
</syntaxhighlight>
 
==={{header|smart BASIC}}===
Line 656 ⟶ 665:
=={{header|Befunge}}==
Zero is false, non-zero is true. This is only used by the horizontal and vertical switch operators (<code>_</code> and <code>|</code>).
 
=={{header|Binary Lambda Calculus}}==
 
The standard representations for the booleans in lambda calculus are true = \then. \else. then, false = \then. \else. else, which correspond to BLC programs <code>00 00 110</code> and <code>00 00 10</code>.
 
=={{header|BQN}}==
 
Line 902 ⟶ 916:
EasyLang does not have built-in boolean types or constants. Operators that "return" a boolean type (e.g. >, <=) cannot be used outside of conditional statements and loops.
 
You can use 1 or 0 in place of true and false, or you can just use the strings "true" and "false".
 
<syntaxhighlight lang="easylang">
boolNumber = 1
if boolNumber = 1
print "True"
else
print "False"
.
boolString$ = "true"
if boolString$ = "true"
print "True"
else
Line 931 ⟶ 939:
Ecstasy's defines [https://github.com/xtclang/xvm/blob/master/lib_ecstasy/src/main/x/ecstasy/Boolean.x an enumeration named Boolean], which contains the values <span style="background-color: #e5e4e2"><tt>&nbsp;False&nbsp;</tt></span> and <span style="background-color: #e5e4e2"><tt>&nbsp;True&nbsp;</tt></span>.
<syntaxhighlight lang="java">
module GeorgeBoole {
{
@Inject Console console;
 
void run() {
{
Boolean f = False;
assert !f == True;
Line 949 ⟶ 955:
console.print($"0==1 = {0==1}");
console.print($"!False = {!False}");
}
}
}
</syntaxhighlight>
 
Line 1,070 ⟶ 1,076:
 
In an <code>if</code> and similar, <code>nil</code> is false and anything else is true. To make that clear docstrings etc say "non-nil" for true. (See last item in [http://www.gnu.org/software/emacs/manual/html_node/elisp/Documentation-Tips.html elisp manual documentation tips].)
 
=={{header|EMal}}==
<syntaxhighlight lang="emal">
^|EMal has a dedicated Logical type expressed by the logic keyword.
|It's not nullable and holds the two values false and true.
|There are no implicit conversions, but explicit conversions
|from/to int (0,1) or text ("⊥", "⊤") are allowed.
|^
logic booleanTrue = true
logic booleanFalse = false
if 2 > 1 and true and not false
writeLine("true: " + true + ", false: " + false)
end
if false == logic!0
writeLine("explicit conversion from integer")
end
if true == logic!"⊤"
writeLine("explicit conversion from text")
end
writeLine(int!true) # is one
writeLine(text!false) # is "⊥"
</syntaxhighlight>
{{out}}
<pre>
true: ⊤, false: ⊥
explicit conversion from integer
explicit conversion from text
1
</pre>
 
=={{header|Erlang}}==
Erlang doesn't technically define boolean types. Instead, the atoms <tt>true</tt> and <tt>false</tt> are used. However, they are integrated well enough into the language there should be no problem with that as long as you don't expect false and true to mean anything but literal false and true.
Line 1,384 ⟶ 1,421:
[...or use as a condition]
if the CPU is working correctly, say "Whew."</syntaxhighlight>
 
=={{Header|Insitux}}==
 
Simply <code>true</code> and <code>false</code>, however, anything which is not <code>false</code> or <code>null</code> is considered truthy.
 
=={{header|J}}==
 
Line 1,390 ⟶ 1,432:
This approach also works well with [[wp:Bayes'_theorem|Bayes' theorem]], as false matches 0% probability and true matches 100% probability.
=={{header|Java}}==
<p>
Java has <tt>true</tt> and <tt>false</tt> keywords, representing the only values of type <tt>boolean</tt>. There are also object wrappers <tt>Boolean.TRUE</tt> and <tt>Boolean.FALSE</tt>, of type <tt>Boolean</tt> which may be un-boxed into <tt>boolean</tt>s (auto-unboxed in Java 1.5+). There are no automatic conversions from any other types into <tt>boolean</tt>, and it is a compile-time error to use any type other than <tt>boolean</tt> or <tt>Boolean</tt> in a place that expects a <tt>boolean</tt> (e.g. if-statement condition, while-statement condition, operand of a logical operator, etc.).
In Java, <code>true</code> and <code>false</code> are used to reference a <code>boolean</code> value.<br />
There is no use of <kbd>0</kbd> and <kbd>1</kbd>, or <kbd>undefined</kbd> vs. <kbd>defined</kbd>.
</p>
<p>
As with the other primitive data-types, <code>boolean</code> has a wrapper class, <code>Boolean</code>, which includes a
set of valuable <kbd>boolean</kbd> operations.
</p>
<syntaxhighlight lang="java">
boolean valueA = true;
boolean valueB = false;
</syntaxhighlight>
<p>
Or.
</p>
<syntaxhighlight lang="java">
Boolean valueA = Boolean.TRUE;
Boolean valueB = Boolean.FALSE;
</syntaxhighlight>
<p>
Additionally.
</p>
<syntaxhighlight lang="java">
Boolean valueA = Boolean.valueOf(true);
Boolean valueB = Boolean.valueOf(false);
</syntaxhighlight>
 
=={{header|JavaScript}}==
The Boolean type has two values: <code>true</code> and <code>false</code>
Line 1,993 ⟶ 2,061:
=== There are no keywords for true and false ===
 
Perl has no builtin "true" or "false" keywords. ThisAn isold atrick caveat,of becauseusing truethem and false areas bareword strings andis strongly discouraged evaluatein tomodern true:Perl.
 
<syntaxhighlight lang="perl"># This does not work
# true and false are not special so will be treated as bareword strings
if (true) { print "true is true\n" }; # This prints
if (false) { print "false is true\n" }; # So does this
if (spongebob) { print "spongebob is true\n" }; # A bareword string</syntaxhighlight>
 
=== Special cases ===
Line 2,369 ⟶ 2,431:
v := 1.bool; -- ok
if i.bool then ... end; -- ok</syntaxhighlight>
 
In this case, <code>0.bool</code> is false, and <code>n.bool</code> with n not equal to 0 is true.
 
=={{header|S-BASIC}}==
Although S-BASIC has no explicit boolean data type, it allows integer,
real, fixed, string, and character variables to hold the results of boolean operations and to represent true and false conditions in IF, WHILE, and REPEAT statements. For types real.double, real, and fixed, a value of zero is false, and any non-zero value is true. For integers, the value 0 is treated as false, while -1 (or FFFFH), the bit-wise negation of zero, is treated as true.
For characters and strings, 'Y', 'y', 'T', and 't' are treated as true,
while 'N', 'n', 'F', and 'f' are treated as false. (For strings, only the first character is considered.) For convenience, the $CONSTANT compiler directive can be used to provide values for "true" and "false".
<syntaxhighlight lang = "BASIC">
$constant true = 0FFFFH
$constant false = 0
 
var a, another = char
var b, adult, age = integer
var c = real
 
repeat
begin
input "Applicant's age in years"; age
adult = (age >= 18)
if adult then
print "Applicant has full access"
else
print "Applicant has restricted access"
input "Do another (y/n)"; another
end
until not another
 
a = (2 > 3)
b = (2 > 3)
c = (2 > 3)
print "2 > 3 as char: "; a
print "2 > 3 as int : "; b
print "not (2 > 3) : "; not b
print "2 > 3 as real: "; c
print "not (2 > 3) : "; not c
end
</syntaxhighlight>
{{out}}
<pre>
Applicant's age in years? 19
Applicant has full access
Do another (y/n)? n
2 > 3 as char: F
2 > 3 as int : 0
not (2 > 3) :-1
2 > 3 as real: 0
not (2 > 3) :-1
</pre>
 
=={{header|Scala}}==
Booleans in Scala are given by the literals <code>true</code> and <code>false</code>, case sensitive, which are the only instances of the class <code>Boolean</code>.
Line 2,398 ⟶ 2,508:
is False
</pre>
 
=={{header|Sidef}}==
Sidef defines the ''true'' and ''false'' boolean values, which are part of the ''Bool'' type.
Line 2,577 ⟶ 2,688:
 
This class has two methods: the operator ''!'' which returns the logical complement of its receiver and ''toString'' which returns its string representation.
<syntaxhighlight lang="ecmascriptwren">var embed = true
System.printAll([embed, ", ", !embed, ", ", "Is Wren embeddable? " + embed.toString])</syntaxhighlight>
 
Line 2,584 ⟶ 2,695:
true, false, Is Wren embeddable? true
</pre>
 
=={{header|XLISP}}==
Boolean "false" may be represented by <tt>#F</tt>, <tt>#!FALSE</tt>, <tt>NIL</tt>, or the empty list; any other value is counted as true in conditional expressions, but it is also possible to represent the Boolean value "true" using your choice of the symbols <tt>#T</tt>, <tt>#!TRUE</tt>, and <tt>T</tt>. All these symbols are case-insensitive. Note that <tt>T</tt>, unlike the others, is a variable: it is bound by default to the constant <tt>#T</tt>, but you can (although you shouldn't) assign it any other value including "false" (by doing something like <tt>(setq t nil)</tt>). Boolean values are printed as <tt>#T</tt> and <tt>()</tt>.
Anonymous user