News for hackers. Stuff that matters.
Re:Forth: Stack-Manipulation Operators by zozbot234 on Friday May 14, 2021 @09:20PM (#27161408)
I'm not sure that I agree. I think stack manipulation is the most elegant idiom available given the constraints that FORTH is working with. The values and variables features seem to introduce unwanted coupling, and complicate the language's underlying model.

Of course it goes without saying that most FORTH code should not contain low-level stack manipulation. But most useful stack operations can be abstracted quite readily, and this kind of abstraction is a meaningful part of FORTH idiomatic style.

Re:Forth: Stack-Manipulation Operators by kragen on Friday May 14, 2021 @11:19PM (#27162022)
It's an interesting point of view.

When you say "The values and variables features...introduce unwanted coupling, and complicate the...model," do you mean implementing them in a Forth, or using them in your application code? I don't think I've ever seen either a Forth or a Forth program that didn't use variables, so I think the model is unavoidably going to get that complicated for any program more complicated than (-b±√(b²-4ac))/2a. (You could replace VARIABLEs (and CONSTANTs) with VALUEs, and having both is clearly unnecessary.)

As for the coupling, do you mean that if one subroutine writes a variable and another reads it, then that couples them? That's true, but I was talking about using a variable inside a single subroutine, as an alternative to stack manipulations. That's not the only good way to use variables in Forth, and it's not always better than stack manipulations, but I'm saying it's a reliable way to get over the "I'm too dumb for Forth" hump that most of us hit at some point.

> But most useful stack operations can be abstracted quite readily, and this kind of abstraction is a meaningful part of FORTH idiomatic style.

Yes, that is surely true.

Is there some Forth code you think of as exemplary that I could learn from?