Boolean
From Erights
Revision as of 22:58, 10 January 2009 by Kevin Reid (Talk)
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