REBOL 3 Docs | Guide | Concepts | Functions | Datatypes | Errors |
TOC < Back Next > | Updated: 18-Feb-2009 Edit History |
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
22
if current-time > snack-time [print snack-time]
12:32
print third friends
Georgia
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 friend@rebol.com read http://www.cnn.com ] 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]
5
print either now/time < 12:00 ["AM"]["PM"]
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
50
Parentheses can be used to control the order of evaluation, as shown in the following examples:
2 + (3 * 10)
32
(length? "boat") + 2
6
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 > | REBOL.com - WIP Wiki | Feedback Admin |