Boolean
From Erights
(Difference between revisions)
Kevin Reid (Talk | contribs) (category) |
(copy in tests from E-on-CL scope-univ.updoc r1044) |
||
| (One intermediate revision not shown) | |||
| Line 1: | Line 1: | ||
| - | The '''<code>Boolean</code>''' type has exactly two members, <code>false</code> and <code>true</code>. All three names | + | The '''<code>Boolean</code>''' type has exactly two members, <code>false</code> and <code>true</code>. All three of these objects print with those names. |
| - | + | ? true | |
| + | # value: true | ||
| + | |||
| + | ? false | ||
| + | # value: false | ||
| + | |||
| + | ? boolean | ||
| + | # value: Boolean | ||
| - | + | The [[universal scope]] contains <code>boolean</code> (no capital), <code>false</code>, and <code>true</code>. | |
| - | pick | + | == Protocol == |
| + | |||
| + | {{instance msgdoc|pick|2|<var>t</var>, <var>f</var>|any}} | ||
false.pick(<var>t</var>, <var>f</var>) returns <var>f</var>; true.pick(<var>t</var>, <var>f</var>) returns <var>t</var>. | false.pick(<var>t</var>, <var>f</var>) returns <var>f</var>; true.pick(<var>t</var>, <var>f</var>) returns <var>t</var>. | ||
| - | + | ? true.pick(1, 2) | |
| - | + | # value: 1 | |
| - | + | ||
| + | ? false.pick(3, 4) | ||
| + | # value: 4 | ||
| + | |||
| + | {{instance msgdoc|not|0||[[Boolean]]}} | ||
Boolean negation. | Boolean negation. | ||
| - | + | ? !true | |
| + | # value: false | ||
| + | |||
| + | ? !false | ||
| + | # value: true | ||
| - | or | + | {{instance msgdoc|or|1|<var>other</var> :[[Boolean]]|[[Boolean]]}} |
Boolean or. The argument is coerced to a boolean. | Boolean or. The argument is coerced to a boolean. | ||
| - | == | + | ? false | false |
| + | # value: false | ||
| + | |||
| + | ? false | true | ||
| + | # value: true | ||
| + | |||
| + | ? false | def _{to __conformTo(==boolean) :any {return false}} | ||
| + | # value: false | ||
| + | |||
| + | ? true | false | ||
| + | # value: true | ||
| + | |||
| + | ? true | true | ||
| + | # value: true | ||
| + | |||
| + | ? true | -1 | ||
| + | # problem: the int -1 doesn't coerce to a boolean | ||
| + | |||
| + | ? true | def _{to __conformTo(==boolean) :any {return true}} | ||
| + | # value: true | ||
| - | and | + | {{instance msgdoc|and|1|<var>other</var> :[[Boolean]]|[[Boolean]]}} |
Boolean and. The argument is coerced to a boolean. | Boolean and. The argument is coerced to a boolean. | ||
| - | == | + | ? true & true |
| + | # value: true | ||
| + | |||
| + | ? true & false | ||
| + | # value: false | ||
| + | |||
| + | ? true & def _{to __conformTo(==boolean) :any {return true}} | ||
| + | # value: true | ||
| + | |||
| + | ? false & true | ||
| + | # value: false | ||
| + | |||
| + | ? false & false | ||
| + | # value: false | ||
| + | |||
| + | ? false & -1 | ||
| + | # problem: the int -1 doesn't coerce to a boolean | ||
| + | |||
| + | ? false & def _{to __conformTo(==boolean) :any {return false}} | ||
| + | # value: false | ||
| - | xor | + | {{XXX}} discuss ideal default wording of coercion failure errors |
| + | |||
| + | {{instance msgdoc|xor|1|<var>other</var> :[[Boolean]]|[[Boolean]]}} | ||
Boolean exclusive or. The argument is coerced to a boolean. | Boolean exclusive or. The argument is coerced to a boolean. | ||
| - | == | + | ? false ^ false |
| + | # value: false | ||
| + | |||
| + | ? false ^ true | ||
| + | # value: true | ||
| + | |||
| + | ? true ^ def _{to __conformTo(==boolean) :any {return true}} | ||
| + | # value: false | ||
| + | |||
| + | ? true ^ false | ||
| + | # value: true | ||
| + | |||
| + | ? true ^ true | ||
| + | # value: false | ||
| + | |||
| + | ? false ^ -1 | ||
| + | # problem: the int -1 doesn't coerce to a boolean | ||
| + | |||
| + | ? false ^ def _{to __conformTo(==boolean) :any {return true}} | ||
| + | # value: true | ||
| + | === op__cmp/1 === | ||
Comparison with other Booleans. See [[Message op__cmp]]. | Comparison with other Booleans. See [[Message op__cmp]]. | ||
| + | |||
| + | {{XXX}} write tests for this | ||
[[Category:ELib specification]] | [[Category:ELib specification]] | ||
Latest revision as of 22:58, 10 January 2009
The Boolean type has exactly two members, false and true. All three of these objects print with those names.
? true # value: true ? false # value: false ? boolean # value: Boolean
The universal scope contains boolean (no capital), false, and true.
Contents |
Protocol
pick/2
- Signature: pick(t, f) :any
false.pick(t, f) returns f; true.pick(t, f) returns t.
? true.pick(1, 2) # value: 1 ? false.pick(3, 4) # value: 4
not/0
- Signature: not() :Boolean
Boolean negation.
? !true # value: false ? !false # value: true
or/1
- Signature: or(other :Boolean) :Boolean
Boolean or. The argument is coerced to a boolean.
? false | false
# value: false
? false | true
# value: true
? false | def _{to __conformTo(==boolean) :any {return false}}
# value: false
? true | false
# value: true
? true | true
# value: true
? true | -1
# problem: the int -1 doesn't coerce to a boolean
? true | def _{to __conformTo(==boolean) :any {return true}}
# value: true
and/1
- Signature: and(other :Boolean) :Boolean
Boolean and. The argument is coerced to a boolean.
? true & true
# value: true
? true & false
# value: false
? true & def _{to __conformTo(==boolean) :any {return true}}
# value: true
? false & true
# value: false
? false & false
# value: false
? false & -1
# problem: the int -1 doesn't coerce to a boolean
? false & def _{to __conformTo(==boolean) :any {return false}}
# value: false
XXX discuss ideal default wording of coercion failure errors
xor/1
- Signature: xor(other :Boolean) :Boolean
Boolean exclusive or. The argument is coerced to a boolean.
? false ^ false
# value: false
? false ^ true
# value: true
? true ^ def _{to __conformTo(==boolean) :any {return true}}
# value: false
? true ^ false
# value: true
? true ^ true
# value: false
? false ^ -1
# problem: the int -1 doesn't coerce to a boolean
? false ^ def _{to __conformTo(==boolean) :any {return true}}
# value: true
op__cmp/1
Comparison with other Booleans. See Message op__cmp.
XXX write tests for this

