Boolean values: Difference between revisions

Content added Content deleted
(added Clojure)
m (Fixed lang tags (using MediaWiki::API).)
Line 87:
No objects in the standard library coerce to boolean, but user-written objects may choose to do so; they can then be used in place of booleans.
 
<lang e>? def bowlian {
? def bowlian {
> to __conformTo(guard) {
> if (guard == boolean) { return true }
Line 99 ⟶ 98:
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.
 
<lang erlang>1> 1 < 2.
1> 1 < 2.
true
2> 1 < 1.
false
3> 0 == false.
false</lang>
</lang>
 
=={{header|FALSE}}==
Line 113 ⟶ 110:
=={{header|Forth}}==
In conditionals, zero is false, non-zero is true. There are predefined constants for the canonical forms (all bits set/clear).
<lang forth>TRUE . \ -1
TRUEFALSE . \ -10</lang>
FALSE . \ 0
</lang>
 
=={{header|Haskell}}==
Line 149 ⟶ 144:
=={{header|Logo}}==
Logo has predefined symbols for true and false ("true and "false), which are the values returned by predicates and required by logical operators and conditionals.
<lang logo>print 1 < 0 ; false
print 1 < 0 ; false
print 1 > 0 ; true
if "true [print "yes] ; yes
if not "false [print "no] ; no</lang>
</lang>
Unlike other lispy languages, there are no other implicit conversions. You must test explicitly for zero or empty collections.
<lang logo>if equal? 0 ln 1 [print "zero]
if equal? 0 ln 1 [print "zero]
if empty? [] [print "empty] ; empty list
if empty? "|| [print "empty] ; empty word</lang>
</lang>
 
=={{header|Metafont}}==
Line 279 ⟶ 270:
False
>>> bool("False")
True</lang>
>>> </lang>
 
=={{header|R}}==
Line 308 ⟶ 298:
=={{header|SNUSP}}==
Zero is false and non-zero is true, as used by the sole skip-if-zero operator ('''?''').
<lang snusp>$/?\=false= + =true=#
\-/</lang>
$/?\=false= + =true=#
\-/
</lang>
 
=={{header|Standard ML}}==
Line 345 ⟶ 333:
VB has the <code>Boolean</code> data type and the constants <code>True</code> and <code>False</code>, in addition to what's listed under [[#BASIC|BASIC]], above. When used outside of a boolean context, <code>True</code> and <code>False</code> return values depending on their context -- <code>-1</code> and <code>0</code> in a numeric context, <code>"True"</code> and <code>"False"</code> if used as strings.
 
<lang visualbasicvb>Dim x As Boolean
x = IIf(Int(Rnd * 2), True, False)
MsgBox x</lang>
 
=={{header|XSLT}}==
<lang xml><xsl:if test="true() or false()">
True and false are returned by built-in XPath functions.
<xsl:if test="true() or false()">
</xsl:if>
True and false are returned by built-in XPath functions.
</xsl:if test="@myAttribute='true'">
Node attributes set to "true" or "false" are just strings. Use string comparison to convert them to booleans.
<xsl:if test="@myAttribute='true'">
</xsl:if>
Node attributes set to "true" or "false" are just strings. Use string comparison to convert them to booleans.
<xsl:if test="true()@myAttribute or falsenot($nodeSet)">
</xsl:if>
Test an attribute for its presence (empty or not), or whether a node set is empty.
<xsl:if test="@myAttribute or not($nodeSet)">
</xsl:if></lang>
Test an attribute for its presence (empty or not), or whether a node set is empty.
</xsl:if>
</lang>