Booleans
Factor handbook ยป The language

Prev:Stack effect checking
Next:Numbers


In Factor, any object that is not f has a true value, and f has a false value. The t object is the canonical true value.
f
t


A union class of the above:
boolean


There are some logical operations on booleans:
>boolean ( obj -- ? )

not ( obj -- ? )

and ( obj1 obj2 -- ? )

or ( obj1 obj2 -- ? )

xor ( obj1 obj2 -- ? )


Boolean values are most frequently used for Conditional combinators.

The f object and f class
The f object is the unique instance of the f class; the two are distinct objects. The latter is also a parsing word which adds the f object to the parse tree at parse time. To refer to the class itself you must use POSTPONE: or \ to prevent the parsing word from executing.

Here is the f object:
f .
f

Here is the f class:
\ f .
POSTPONE: f

They are not equal:
f \ f = .
f

Here is an array containing the f object:
{ f } .
{ f }

Here is an array containing the f class:
{ POSTPONE: f } .
{ POSTPONE: f }

The f object is an instance of the f class:
USE: classes f class-of .
POSTPONE: f

The f class is an instance of word:
USE: classes \ f class-of .
word

On the other hand, t is just a word, and there is no class which it is a unique instance of.
t \ t eq? .
t

Many words which search collections confuse the case of no element being present with an element being found equal to f. If this distinction is important, there is usually an alternative word which can be used; for example, compare at with at*.