Booleans
Contrary to most popular programming languages at the moment of writing, Xoscript provides for only one single True object and one single False object. To clarify, each time you write, True it does not imply that a new object has been created. Instead, you always use a reference. This means that when you write the following:
>> x := True.
The x refers to the True object. Conditional code and loops also verify this reference. In Xoscript, the meaning of True and False is not fixed. In fact, a Xoscript program gets pretty shaken up over a statement like this:
True := False.
The result of such actions is undefined, however it remains a valid action and therefore formally allowed. Furthermore, there is a Boolean object, which is the root object of both True and False, as both are derivatives of the root object. The Boolean object itself, however, does not provide any practical application.
Gotchas
Be careful with using and: and or:
Out write: (False or: True or: True), stop.
Out write: (False or: True, or: True), stop.
Yields
False
True
because the message or: only takes 1 argument. The first message sends or:or: to False, which does not exists, so the object ignores the message and returns itself (False). On the other hand, the second line sends or: followed by another or: (using a chain symbol, i.e. a comma: ,).
[ Boolean ] = [ Boolean ]
Example:
Out write: (True = False), stop.
Result:
automatically generated from test: #404
[ Boolean ] !=: [ Boolean ]
Example:
(True ≠ False) true: {
Out write: ['x'].
}.
Result:
automatically generated from test: #405
[ Boolean ] string
Example:
Out write: True string, stop.
Out write: False string, stop.
Result:
automatically generated from test: #406
[ Boolean ] break
Example:
{ :i
Out write: i, stop.
(i > 10) break.
}× 20.
Result:
automatically generated from test: #407
[ Boolean ] continue
Example:
{ :i
(i > 10 and: i < 15) continue.
Out write: i, stop.
} * 20.
Result:
automatically generated from test: #408
[ Boolean ] true: [ Code ]
Example:
>> x := 10.
(x > 9 and: x < 11) true: {
Out write: x, stop.
}.
Result:
automatically generated from test: #409
[ Boolean ] false: [ Code ]
Example:
(['a'] > ['b']) false: {
Out write: ['a'], stop.
}, else: {
Out write: ['b'], stop.
}.
Result:
automatically generated from test: #410
[ Boolean ] not
Example:
Out write: True not, stop.
Out write: False not, stop.
Out write: True not not, stop.
Out write: False not not not, stop.
Result:
automatically generated from test: #411
[ Boolean ] either: [ Object ] or: [ Object ]
Example:
>> x := ( 1 > 2 ) either: ['Y'] or: ['N'].
>> y := ( 2 > 1 ) either: ['Y'] or: ['N'].
Out write: x, stop.
Out write: y, stop.
Result:
automatically generated from test: #412
[ Boolean ] and: [ Boolean ]
Example:
>> x := ( 2 > 1 ) and: ( 3 > 2 ).
>> y := ( 2 > 1 ) and: ( 2 > 3 ).
Out write: x, stop.
Out write: y, stop.
Result:
automatically generated from test: #413
[ Boolean ] nor: [ Boolean ]
Example:
>> x := ( 1 > 2 ) nor: ( 2 > 3 ).
>> y := ( 2 > 1 ) nor: ( 3 > 2 ).
Out write: x, stop.
Out write: y, stop.
Result:
automatically generated from test: #414
[ Boolean ] or: [ Boolean ]
Example:
>> x := 10.
Out write: (x = 11 or: x = 10), stop.
Result:
automatically generated from test: #415
[ Boolean ] number
Example:
Out write: True number, stop.
Out write: False number, stop.
Result:
automatically generated from test: #416