3 ms·
The canonical example is how it's done in Forth: Ask for a number and it's already on the stack. Ask for three numbers and you push onto the stack three times.
by chipsy 12y ago
The canonical example is how it's done in Forth: Ask for a number and it's already on the stack. Ask for three numbers and you push onto the stack three times. Upside: Terse code. Downside: Stack juggling can be a big maintenance burden.
FWIW I've realized that in languages that are variable centric, an anonymous naming convention is often preferable to a human name because it centers one's concerns around the algorithm. After studying the options for a while I now flip between descriptive word style and "single letter and number." So I have a lot of "x0, x1, i0, s0, a0" in my function arguments. Where it's a record type, I'm deciding between abbreviation and descriptive - which ultimately depends on how often and densely I expect the data structure to be accessed(short names imply it gets used in a dense, idiomatic style).
- evincarofautumn 12y agoYep. I am working on a statically typed stack-based language, as I quite like the Forth style. Stack manipulation sucks, so I mainly use locals for auxiliary parameters, to get them out of the way of the main data structure or values that a definition is manipulating implicitly. For example: define do_the_thing (Foo bool -> Bar): -> should_log; if (should_log): dup log_foo foo_to_bar if (should_log): dup log_bar