Thread #108048352 | Image & Video Expansion | Click to Play
File: pushswapdup.png (64.3 KB)
64.3 KB PNG
What are your thoughts on the Forth programming language?
42 RepliesView Thread
>>
>>108048352
Swapping because you can only deal with the topmost element of the stack is an artificial limitation.
In most languages you know exactly how many arguments are passed to your function at compile time and you don't need to swap things around. Just refer to the arguments by name. Forth is one of the only languages where a stack underflow is even possible.
A weird quirk like that makes Forth feel like a toy, theoretical language like how Lambda Calculus isn't meant for real work.
>>
>>
>>
>>
>>
>>
>>108048585
>>108048490
>>108048483
You know you can define your own words with the DUP ROT SWAP etc commands and automate 90% of the language right
>>
>>
>>108048352
I started making my own Forth but I got filtered on implementing create does. Sad times. :(
Regarding OP's example, having top of stack be a register reduces stack thrashing and increases run-time speed.
>>
>>
>>
File: file.png (98.9 KB)
98.9 KB PNG
>>108048352
you just want this image
>>
>>
>>108048585
The stack is just for easy implementation of the base language. You can still manipulate registers with it, and at the end of the day your program is basically supposed to be written in a DSL you put together and abstracted all the annoying shit behind.
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>108048352
>What are your thoughts on the Forth programming language?
The Unabomber's favorite language.
It's a really cool idea, a genius idea, but not too ergonomic for actual use (i've tried).
Forth is alive everywhere, because many virtual machine bytecodes are actually code for stack machines.
>>
>>
>>
File: POL9.png (48.9 KB)
48.9 KB PNG
>>108056571
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>108048399
Regarding the stack. Yes you can make a mess of dups and rots where keeping track of what's on the stack becomes impossible. An when you try to directly translate code from other language you know from before, this is what happens almost certainly. Thats why the gforth manual has a section on "Designing the stack effect".
After some practice it feels like the mental overhead from having to keep track of the stack is about the same as keeping track of variable names in code that names intermediate variables.
>>
>>
the stak manilulation is waste of CPU cycles
Iike the idea of having a simple interpreted shell and call convention to glue assembly routines calls. such interactivity can really elevate assembly-written projects and environments
>>