REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 6-Feb-2009 Edit History  

REBOL 3 Concepts: Math: Logic Functions

Pending Revision

This document was written for R2 and has yet to be revised for R3.

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.

Contents

and

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

or

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

xor

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

complement

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

not

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