Hacker News new | past | comments | ask | show | jobs | submit login

For me, the main problem with forth is a lack of names -- most languages (functional or imperative or even declarative) assign names to things -- things like function parameters, temporary values and so on.

Even Prolog, which is as far from traditional structural program as one can go, usually has descriptive names for unbound variables.

Compared to this, Forth is very name-terse. You get "function names" at best, and nothing else. This really makes programs much harder to understand, as it requires one to remember much more things while reading the code.




The ANS Forth standard supports named local variables. Unfortunately Forth dialects vary quite a bit in their implementation and prefered use of local variables, and the semantics of local variables are a bit hairy.

Cf. https://www.complang.tuwien.ac.at/forth/gforth/Docs-html/ANS...


Note that Forth also supports locals. These will consume and remove N members from the stack so you can summon them as needed prior to calling the words.

But as someone that really got into Forth this year, I can assure that it does get better once you get more familiar with the language. I used to write commenting the stack effects on each line and now I barely need them as I write words in one sitting without that much effort.

Other developers are doing tacit programming in J or Haskell, pipe forward operators in F# or OCaml and threading macros on Lisp dialects and they seem to do fine.


It's been a long time since I did anything substantive with Forth, but, as I recall, the big problem here is that most Forth guides get so excited to show you how much rope the language gives you that they forget to teach you how not to hang yourself with it. So you're kind of left to figure out all the little idioms and best practices for stack management all on your own.


>> So you're kind of left to figure out all the little idioms and best practices for stack management all on your own.

That was my experience learning Forth in the 80's. Initially I tried to add compositional features I was familiar with from APL and Lisp. I raged against the limitations of the cell and schemed to use a typed stack. Eventually I became one with PAD and was able to ALLOT peace to my code. At some point I ranted on how the idiom of counted strings could be generalized to all sorts of useful sin and had an epiphany. 2ROT on!


What does a local variable mean in the context of Forth? Data guaranteed to be in registers, like the in-CPU stack of 8008?


The term you are looking for is "tacit" or "point-free" programming. Array languages are another example.


You're right in the sense that it's not in style, but there are both named "locals" and "arguments" in ANS Forth IIRC.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: