4 ms·
Forth is extensible, it is not complete out of the box like a C compiler. Just extend it with named local variables and use them. There is no shame and unless y
by flembat 4y ago
Forth is extensible, it is not complete out of the box like a C compiler.
Just extend it with named local variables and use them.
There is no shame and unless you are on some rare and exotic stack machine, no performance penalty using local variables.
I also need to add safe strings with their own memory pool, rather than block copying bytes around in the same dictionary where my code lives.
I am just not a good enough programmer to use Forth strings without crashing a lot.
- kragen 4y agofrom my non-expert viewpoint, the big penalty for named local variables in forth is that it is a barrier to breaking up a word into smaller words, because pieces of code inside the same word that communicate through a local variable will stop working if you break them into separate words bigger words impede using the forth repl as a line-by-line stepping debugger, so they diminish the interactivity that is the reason you'd use want to forth in the first place agreed about strings; one of the first things i wrote in forth was a straight port of bernstein's stralloc, last millennium
- Karrot_Kream 4y agoIf you can keep variables separate between different words, you can make sure that the variable stays local to the word. It is error-prone but can stop the variable from leaking and keep words separate.
- kragen 4y agowhat do you mean
- Karrot_Kream 4y agoDefine variables before you start defining words. Make sure you use one variable per word. It's a manual process but when composing words helps make sure variable collisions don't happen.
- kragen 4y agoyou don't need to do that, you can define a separate variable named x above every colon definition if you want it hides the earlier declarations of the same name
- Karrot_Kream 4y agoSure, I prefer not shading but that works too.