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

REBOL 3 Concepts: Tour: Evaluation

Pending Revision

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


This section is obsolete and being replaced. It is kept only as a source for new content.

Blocks are evaluated to compute their results. When a block is evaluated the values of its variables are obtained. The following examples evaluate the variables age, snack-time, birthday, and friends that were defined in the previous section:

print age
if current-time > snack-time [print snack-time]
print third friends

A block can be evaluated multiple times by using a loop, as shown in the following examples:

loop 10 [prin "*"]  ;("prin" is not a typo, see manual)
loop 20 [
    wait 8:00
    send read

repeat count 3 [print ["count:" count]]
count: 1
count: 2
count: 3

The evaluation of a block returns a result. In the following examples, 5 and PM are the results of evaluating each block:

print do [2 + 3]
print either now/time < 12:00 ["AM"]["PM"]

In REBOL there are no special operator precedence rules for evaluating blocks. The values and words of a block are always evaluated from first to last, as shown in the following example:

print 2 + 3 * 10

Parentheses can be used to control the order of evaluation, as shown in the following examples:

2 + (3 * 10)
(length? "boat") + 2

You can also evaluate a block and return each result that was computed within it. This is the purpose of the reduce function:

reduce [1 + 2  3 + 4  5 + 6]
3 7 11

  TOC < Back Next > - WIP Wiki Feedback Admin