News for hackers. Stuff that matters.
Re:Forth: A New Way to Program a Mini Computer (1974) by timonoko on Saturday October 08, 2022 @05:08PM (#33136022)
This is always annoying to read as they wasted ")" to some shit.

"(" 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"

Re:Forth: A New Way to Program a Mini Computer (1974) by timonoko on Sunday October 09, 2022 @03:16AM (#33138856)
IF-sentence was totally wrong. Per se.

(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.

Re:Forth: A New Way to Program a Mini Computer (1974) by shadowofneptune on Wednesday October 12, 2022 @05:12AM (#33174588)
I am not sure what you mean. "(" and ")" as their own words form comments in Forth. As an example:

    (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 ")".
Re:Forth: A New Way to Program a Mini Computer (1974) by timonoko on Wednesday October 12, 2022 @07:41AM (#33175511)
Of course we fix the parser too, so that ( and ) are always separate. Otherwise too ugly.
Re:Forth: A New Way to Program a Mini Computer (1974) by flohofwoe on Wednesday October 12, 2022 @06:07AM (#33174876)
Looks like Lisp, ugh ;)

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.

Re:Forth: A New Way to Program a Mini Computer (1974) by bbarnett on Wednesday October 12, 2022 @08:01AM (#33175692)
And once you switch your mind over it feels just natural.

Yet what if the result is, your mind has become unnatural?

!!!

Re:Forth: A New Way to Program a Mini Computer (1974) by 0x445442 on Wednesday October 12, 2022 @10:56AM (#33177897)
RPN with pocket calculators was nice because of the screen real estate restrictions. But on computers there’s a lot of screen real estate to show the program and the variable assignments to intermediate results. Even with long procedures, it’s easy to scroll, read and understand the execution flow with that extra screen space.
Re:Forth: A New Way to Program a Mini Computer (1974) by dandanua on Wednesday October 12, 2022 @10:43AM (#33177720)
The reverse Polish notation (postfix) is the most natural notation if you want just to compute things, IMO. But if you want to grasp what is going on without computation - other notations can be better for readability.
Re:Forth: A New Way to Program a Mini Computer (1974) by bmacho on Wednesday October 12, 2022 @07:37AM (#33175487)
> "(" 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 +"

I don't get it, what is the X-stack? Also can you elaborate this example in more details?

Re:Forth: A New Way to Program a Mini Computer (1974) by timonoko on Wednesday October 12, 2022 @07:52AM (#33175616)
X is separate execution stack. It is very short depending how many brackets you use. When I made such Forth some 50 years ago, the "pop and execute" was one cycle on Nova 1200, no overhead. And x-stack was one 8-bit page.
Re:Forth: A New Way to Program a Mini Computer (1974) by bmacho on Wednesday October 12, 2022 @08:32AM (#33175978)
Thanks. Am I getting right, ( + 1 ( - 2 3 ) ) parses as

    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?
Re:Forth: A New Way to Program a Mini Computer (1974) by boomlinde on Wednesday October 12, 2022 @11:57AM (#33178890)
You can certainly override the ( word to replace its functionality. You can even do so late in the compilation process so that the new semantics only apply to the code you write without affecting the rest of the dictionary.

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.

Re:Forth: A New Way to Program a Mini Computer (1974) by wjbr on Saturday October 15, 2022 @05:45PM (#33218945)
How would it work with more than two arguments?

  (+ 1 2 3)