The do word

We will start by giving a name (a label) to a code block so that you can call that code by its name and evaluate it with the do word, which we already saw in action in the Evaluation with do and reduce section in Chapter 3, Using Words, Values, and Types. Here, the word pri5 is bound to a piece of code, which prints five digits separated by dashes:

;-- see Chapter06/do-does-has-func.red:pri5: [ repeat i 5 [prin i prin "-"] ]do pri5 ;== 1-2-3-4-5- ; evaluate code block with label pri5type? pri5 ;== block!

However, pri5 is not yet a real function; it is still a block, and you have to invoke it with do.

The block could also contain interactive code, such as that shown in the following example:

do [     pass: ask "Enter Password: " ...

Get Learn Red - Fundamentals of Red now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.