2 ms·
Sort of. The parenthesis around an expression like (a b +) imply a result of some type. That type is defined by the whatever type promotion rules are in place f
by cratermoon 5y ago
Sort of. The parenthesis around an expression like (a b +) imply a result of some type. That type is defined by the whatever type promotion rules are in place for the operands and operators. Thus, if a and b are integers in the range -MIN_VALUE to MAX_VALUE, and + is defined as integer addition, then the 'type' implied by (a b +) is an integer in that range (or possibly an error condition, if under/overflow).
The reason you don't see a stack language that evaluates from left to right is because then it wouldn't be a stack language.
- thrwaeasddsaf 5y agoBut stack languages generally do evaluate left to right. I don't see why you couldn't do right to left. Makes no semantic difference. But the original post has a snippet that should not only be evaluated right to left, but also bottom to top. Unless their indentation implies hidden parens.
- cratermoon 5y agoYeah, I mean right-to-left, in response to the question the article asks: Why have I never seen... ...a stack language that evaluates right-to-left? it's because the tokens are evaluated in the order they are consumed by the parser. But now that I think about it, the tokens only look left-to-right because that's how the text is displayed. So what's really happening is that tokens are evaluated in FIFO, and there's no reason the tokens for (a b +) couldn't be written as (+ b a).