Boolean values: Difference between revisions
Content deleted Content added
added Clojure |
Underscore (talk | contribs) m Fixed lang tags (using MediaWiki::API). |
||
Line 87: | 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. |
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> |
<lang e>? def bowlian { |
||
? def bowlian { |
|||
> to __conformTo(guard) { |
> to __conformTo(guard) { |
||
> if (guard == boolean) { return true } |
> if (guard == boolean) { return true } |
||
Line 99: | Line 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. |
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> |
<lang erlang>1> 1 < 2. |
||
1> 1 < 2. |
|||
true |
true |
||
2> 1 < 1. |
2> 1 < 1. |
||
false |
false |
||
3> 0 == false. |
3> 0 == false. |
||
false |
false</lang> |
||
⚫ | |||
=={{header|FALSE}}== |
=={{header|FALSE}}== |
||
Line 113: | Line 110: | ||
=={{header|Forth}}== |
=={{header|Forth}}== |
||
In conditionals, zero is false, non-zero is true. There are predefined constants for the canonical forms (all bits set/clear). |
In conditionals, zero is false, non-zero is true. There are predefined constants for the canonical forms (all bits set/clear). |
||
<lang forth> |
<lang forth>TRUE . \ -1 |
||
FALSE . \ 0</lang> |
|||
FALSE . \ 0 |
|||
⚫ | |||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
Line 149: | Line 144: | ||
=={{header|Logo}}== |
=={{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. |
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> |
<lang logo>print 1 < 0 ; false |
||
print 1 < 0 ; false |
|||
print 1 > 0 ; true |
print 1 > 0 ; true |
||
if "true [print "yes] ; yes |
if "true [print "yes] ; yes |
||
if not "false [print "no] ; no |
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. |
Unlike other lispy languages, there are no other implicit conversions. You must test explicitly for zero or empty collections. |
||
<lang logo> |
<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 list |
||
if empty? "|| [print "empty] ; empty word |
if empty? "|| [print "empty] ; empty word</lang> |
||
</lang> |
|||
=={{header|Metafont}}== |
=={{header|Metafont}}== |
||
Line 279: | Line 270: | ||
False |
False |
||
>>> bool("False") |
>>> bool("False") |
||
True |
True</lang> |
||
>>> </lang> |
|||
=={{header|R}}== |
=={{header|R}}== |
||
Line 308: | Line 298: | ||
=={{header|SNUSP}}== |
=={{header|SNUSP}}== |
||
Zero is false and non-zero is true, as used by the sole skip-if-zero operator ('''?'''). |
Zero is false and non-zero is true, as used by the sole skip-if-zero operator ('''?'''). |
||
<lang snusp> |
<lang snusp>$/?\=false= + =true=# |
||
⚫ | |||
$/?\=false= + =true=# |
|||
\-/ |
|||
</lang> |
|||
=={{header|Standard ML}}== |
=={{header|Standard ML}}== |
||
Line 345: | Line 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. |
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 |
<lang vb>Dim x As Boolean |
||
x = IIf(Int(Rnd * 2), True, False) |
x = IIf(Int(Rnd * 2), True, False) |
||
MsgBox x</lang> |
MsgBox x</lang> |
||
=={{header|XSLT}}== |
=={{header|XSLT}}== |
||
<lang xml> |
<lang xml><xsl:if test="true() or false()"> |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
<xsl:if test="@myAttribute='true'"> |
|||
⚫ | |||
<xsl:if test="@myAttribute='true'"> |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
<xsl:if test="@myAttribute or not($nodeSet)"> |
|||
⚫ | |||
⚫ | |||
⚫ | |||
</lang> |