REBOL 3 Docs | Guide | Concepts | Functions | Datatypes | Errors |
TOC < Back Next > | Updated: 6-Feb-2009 Edit History |
Logic functions can be performed on logic values and on some scalar values including integer!, char!, tuple!, and bitset!. When working with logic values, the logic functions return boolean values. When working with other types of values, the logic functions on the bits.
The and function compares two logic values and returns true if they are both true' :
print (1 < 2) and (2 < 3)
true
print (1 < 2) and (4 < 3)
false
When used with integers, the and function compares bit for bit and returns 1 if both bits are 1, or 0 if neither bit is 1 :
print 3 and 5
1
The or function compares two logic values and returns true if either of them are true or false or if both are false' :
print (1 < 2) or (2 < 3)
true
print (1 < 2) or (4 < 3)
true
print (3 < 2) or (4 < 3)
false
When used with integers, or compares bit for bit and returns 1 if either bit is 1 or 0 if both bits are 0:
print 3 or 5
7
The xor function compares two logic values and returns true if and only if one of the values is true and the other is false.
print (1 < 2) xor (2 < 3)
false
print (1 < 2) xor (4 < 3)
true
print (3 < 2) xor (4 < 3)
false
When used with integers, xor compares bit for bit and returns 1 if and only if one bit is 1 and the other 0 . Otherwise, it returns 0 :
print 3 xor 5
6
The complement function returns the logic or bitwise complement of a value. It is used for bitmask integer numbers and inverting bitsets.
print complement true
false
print complement 3
-4
For a logic value not returns true if the value is false and false if the value is true. It does not perform numerical bitwise operations.
print not true
false
print not false
true
TOC < Back Next > | REBOL.com - WIP Wiki | Feedback Admin |