4 ms·
The retain parameter is a secondary stack for temporarily storing things from the data stack. It can be manipulated through the `r>` and `>r` words. The former
by jdp 16y ago
The retain parameter is a secondary stack for temporarily storing things from the data stack. It can be manipulated through the `r>` and `>r` words. The former puts the top of the data stack at the top of the retain, and one does the opposite. The `dip` word isn't a primitive in this implementation, but instead is defined as `swap >r call r>`, which saves the value underneath the top value of the stack (which is expected to be a quotation), calls the quotation, and then restores the retained value to the top of the data stack.
- JulianMorrison 16y agoThis clearly derives from Forth's (much lower level) manipulation of the return stack as transient storage (with the same operators).
- thesz 16y agoTwo stacks are halves of Turing machine tapes: http://en.wikipedia.org/wiki/Stack_machine#Stacks_in_automata_theory http://en.wikipedia.org/wiki/Stack_machine#Stacks_in_automat...
- ntoshev 16y agoDoes this mean that the language would not be Turing-complete without the second stack? What is the retain stack typically used for?
- thesz 16y agoThis precisely mean that language without second stack (more or less) is not Turing complete. But, if your language can store lists on a stack, you're Turing complete again! One example if a Joy language, where you can have quotation on stack, assemble them and decompose back. Most of the time you store there various intermediate values. It depends on the nature of language. For example, Forth variants often store loop counters on retain stack.