3 ms·
> One such property is the use of reverse polish notation and the lack or eschewal of local variables. What do you gain by eschewing local variables in favor o
by jancsika 7y ago
> One such property is the use of reverse polish notation
and the lack or eschewal of local variables.
What do you gain by eschewing local variables in favor of reverse polish notation that throws values onto a stack?
- rabidrat 7y agoThere are two hard problems in computer science: cache invalidation, naming things, and off-by-one errors. Eschewing local variables means you have fewer things to name.
- tom_mellior 7y agoI never understood the "naming things" part to be about temporary variables. IMO it's about exported APIs, global identifiers, and especially about finding resources by some useful name in a distributed system. In any case, Forth is a language for implementing your own DSLs by defining a whole bunch of "words" that all need to be named. So it's not like you get around the harder part of "naming things".
- rvense 7y agoI heard the two problems are that we have only one joke and it's not funny.
- clarry 7y agoThe code becomes trivial to factor, because you don't have any named variable references that would need to be changed. If you find a sequence of words you want to put in a function, you can literally just cut and paste them out. Likewise, you can inline a word just by copypasting its definition in place.
- boomlinde 7y agoAs someone else mentioned you get many natural factorization points because often you can just copy a portion of code verbatim into a new word. Of course, you can implement named parameters and local variables in Forth. There is even a standard for locals in ANS Forth.