Boolean values: Difference between revisions
Content deleted Content added
added Clojure |
Underscore (talk | contribs) 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 {
> 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.
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
</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 ; true
if "true [print "yes] ; yes
if not "false [print "no] ; no</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 empty? [] [print "empty] ; empty list
if empty? "|| [print "empty] ; empty word</lang>
=={{header|Metafont}}==
Line 279 ⟶ 270:
False
>>> bool("False")
True</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>
=={{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
x = IIf(Int(Rnd * 2), True, False)
MsgBox x</lang>
=={{header|XSLT}}==
<lang xml><xsl:if test="true() or false()">
<xsl:if test="true() or false()">▼
▲ True and false are returned by built-in XPath functions.
▲ Node attributes set to "true" or "false" are just strings. Use string comparison to convert them to booleans.
▲ </xsl:if>
▲</xsl:if></lang>
▲ Test an attribute for its presence (empty or not), or whether a node set is empty.
▲ </xsl:if>
|