Skip to content

Incorrect Order of Arithmetic Operations #5277

Answered by hiiamboris
piotrbajdek asked this question in Q&A
Discussion options

You must be logged in to vote

Quoting the R2 core manual which is also relevant for Red here:

The evaluation of expressions from left to right is independent of the type of operator that is used. For example:

print 1 + 2 * 3
9

And:

In REBOL, rather than requiring users to remember the precedence of operators, you only need to remember the left-to-right rule. More importantly, for advanced code such as expressions that handle expressions (in reflection, for example) you do not need to reorder terms based on precedence. The evaluation order is kept simple.

My personal view is this design just makes the interpreter much faster and simpler, as this way it operates on the data directly, not requiring an AST.

When you …

Replies: 2 comments 10 replies

Comment options

You must be logged in to vote
10 replies
@greggirwin
Comment options

@piotrbajdek
Comment options

@hiiamboris
Comment options

@piotrbajdek
Comment options

@hiiamboris
Comment options

Answer selected by hiiamboris
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants
Converted from issue

This discussion was converted from issue #5276 on January 28, 2023 19:24.