"(" should be: Push next word to X-stack
")" should be: pop and execute top of X-stack.
So "(+ m n)" is equal to "m n +"
And "(IF (< A B) (THEN C ELSE D)))" == "A B < IF C ELSE D THEN"
"(" should be: Push next word to X-stack
")" should be: pop and execute top of X-stack.
So "(+ m n)" is equal to "m n +"
And "(IF (< A B) (THEN C ELSE D)))" == "A B < IF C ELSE D THEN"
I don't see why you would, though. Even in your trivial example "(IF (< A B) (THEN C ELSE D)))" the brackets are unbalanced and even if they were, IF would be executed after THEN and ELSE. When you push a word to the "X-stack" you correspondingly have to push a word to an analogue of a stack in your mind to know what happens when ')' executes. You failed to do this and therefore your example is broken. In idiomatic Forth, you wouldn't have to worry: in most cases you only have to consider the data stack, and in most cases the sequences you just read to your left imply what's on top of that, not what you read ten words back.
Even if it was slightly easier to read than idiomatic Forth (I disagree that it is), in-line comments strike me as more important "shit" than superficial syntax sugar.
I guess Polish Notation wasn't as uncommon in the 70's as it is today, AFAIK pocket calculators used this too. And once you switch your mind over it feels just natural.
Yet what if the result is, your mind has become unnatural?
!!!
(if (< a b)
Would be parsed completely differently from: ( if ( < a b )
The first will have the interpreter look up and execute the words "(if", "(<", "a", and "b)". The second will have the interpeter look up the word "(", which will skip all the text that comes before a ")".> ")" should be: pop and execute top of X-stack.
> So "(+ m n)" is equal to "m n +"
I don't get it, what is the X-stack? Also can you elaborate this example in more details?
s
x +
s 1
x +
s 1
x + -
s 1 2
x + -
s 1 2 3
x + -
s 1 2 3 -
x +
s 1 2 3 - +
x
which should evaluate to 0?(IF (< A B)) (THEN C ELSE D) looks about right. This is about readability, all else stays the same. You can avoid the minute overhead of "(" by not using it on a critical situation.
(+ 1 2 3)