this documentation is work-in-progress, edit here (md).

Booleans

sections in this chapter:
gotchas »
[ Boolean ] = [ Boolean ] »
[ Boolean ] !=: [ Boolean ] »
[ Boolean ] string »
[ Boolean ] break »
[ Boolean ] continue »
[ Boolean ] true: [ Code ] »
[ Boolean ] false: [ Code ] »
[ Boolean ] not »
[ Boolean ] either: [ Object ] or: [ Object ] »
[ Boolean ] and: [ Boolean ] »
[ Boolean ] nor: [ Boolean ] »
[ Boolean ] or: [ Boolean ] »
[ Boolean ] number »

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:

False

	

[ Boolean ] !=: [ Boolean ]

Example:


 (True ≠ False) true: { 
 	Out write: ['x'].
 }.
 
	

Result:

x
	

[ Boolean ] string

Example:


 Out write: True string, stop.
 Out write: False string, stop.
 
	

Result:

True
False

	

[ Boolean ] break

Example:


 { :i
 		Out write: i, stop.
     (i > 10) break.
 } × 20.
 
	

Result:

0
1
2
3
4
5
6
7
8
9
10
11

	

[ Boolean ] continue

Example:


 { :i
      (i > 10 and: i < 15) continue.
      Out write: i, stop.
 } * 20.
 

	

Result:

0
1
2
3
4
5
6
7
8
9
10
15
16
17
18
19

	

[ Boolean ] true: [ Code ]

Example:


 >> x := 10.
 (x > 9 and: x < 11) true: {
 	Out write: x, stop.
 }.
 

	

Result:

10

	

[ Boolean ] false: [ Code ]

Example:


 (['a'] > ['b']) false: {
   Out write: ['a'], stop.
 }, else: {
   Out write: ['b'], stop.
 }.
 
	

Result:

a
b

	

[ 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:

False
True
True
True

	

[ 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:

N
Y

	

[ 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:

True
False

	

[ 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:

True
False

	

[ Boolean ] or: [ Boolean ]

Example:


 >> x := 10.
 Out write: (x = 11 or: x = 10), stop.
 
	

Result:

True

	

[ Boolean ] number

Example:


 Out write: True number, stop.
 Out write: False number, stop.
 
	

Result:

1
0