Order of evaluation

You will know from other programming languages that a strict, so-called precedence order is followed to determine the order that operations are evaluated in expressions. Sometimes, you need to consult the precedence table to be sure, or use parentheses to indicate the evaluation order.

In Red, you can and should also use parentheses for the same reason, but otherwise expressions are evaluated from left to right, as shown here:

1 + 2 * 3   ;== 9     ; other languages would return 7!1 + (2 * 3) ;== 7     ; use ( ) to get that result in Red

Another way to enforce the common evaluation order is to put the expression inside a block and use the math function:

math [1 + 2 * 3]    ;== 7

To get a better feeling for this, let's examine a more ...

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.