Re: using MISC (post 1987 Forth hardware) opcodes



Adam Warner wrote:


We agree I did not provide a good enough example to support my claim. This
one should be bulletproof: You have a reason to trace though a deep
tree-like data structure.

Ok, that might be an application requirement. Not a particularly common one in my experience.

Mechanically this involves pushing paths you
still need to travel onto a stack every time you branch within the tree.
Recursion makes this mechanical process invisible.

Here's part of the data structure. I'll describe tracing through the right
size of the solid region:

a
/ \
b c
. / \
. d e
. . . / \
. . f g
. . / \
. h i
. / \
. j k
. / \
. l m
. / \
. n o
. / \
. p q
. .
. .
. . .
. . .

1. Push (b) and process (c).
2. Push (d) and process (e).
3. Push (f) and process (g).
4. Push (h) and process (i).
5. Push (j) and process (k).
6. Push (l) and process (m).
7. Push (n) and process (o).
8. Push (p) and process (q). Return.
9. Pop (p) and process. Return.
10. Pop (n) and process. Return.
11. Pop (l) and process. Return.
12. Pop (j) and process. Return.
13. Pop (h) and process. Return.
14. Pop (f) and process. Return.
15. Pop (d) and process. Return.
16. Pop (b) and process. Return.

An environment with six cell stacks cannot traverse this data structure
(without implementing userspace stacks out of heap memory).

So put a stack in memory. It doesn't necessarily have to be heap if you have a reasonable upper bound on the required stack size.

No application requirement forces you to use the number stack to store a complicated data structure. Indeed, I expect most experienced Forthers would not do it this way.

When I did something similar many years ago, I found it useful to keep the tree traversal state on a separate stack even though I had a big number stack in that particular Forth implementation. For this kind of problem, a separate stack helps minimize stack gymnastics and facilitates factoring. These advantages more than compensate for the trivial extra complexity of explicitly creating and destroying frames on an auxiliary stack.

A language likes C creates and destroys frames suitable for this kind of thing willy-nilly whether you need them or not. Forth makes you ask. That's not much of a burden as far as I'm concerned. It's rare to have an application requirement push you in this direction in Forth.

So, it seems to me that your objection to small stacks comes down to "They won't let me write the code the way I want". That's not an application requirement, so you don't have a serious problem unless the small stack makes it significantly more difficult to code readably to the real application requirements. That's not the case here: the extra difficulty is trivial, and I think in a real application the way you want to do it would actually be more difficult to code and read.

--
John Doty, Noqsi Aerospace, Ltd.
--
Beheading a man with a stone axe is difficult, and the axe blade quickly loses its sharp edge and is tedious to resharpen. -Jared Diamond
.



Relevant Pages

  • Re: Is it wise to push all-in early in a tournament?
    ... The best times to make a push play ... But why call when you can push and take down a nice pot when your opponent ... But remember that if this "big bet" is a significant portion of your stack, ... I consider it my goal in any tournament to do the latter as much as ...
    (rec.gambling.poker)
  • Re: Is it wise to push all-in early in a tournament?
    ... whether or not the rest of the table is splashing chips around. ... I may push more than I want to and you may be more conservative than ... Do I want to play this opponent after the flop? ... push at anytime and I may not want to risk my stack on a suckout when I ...
    (rec.gambling.poker)
  • Virtual machine: assembly instructions
    ... push; Push the address of the first variable onto the stack ... itof: convert integer to float ... If top+1 of int stack is less than top; push true else push false ...
    (comp.programming)
  • Re: Building Unification Table - tranforming prolog like notation into lisp notation
    ... |> problem comes from tranlating prolog notation into lisp notation. ... ;; Here is a quickly done stack based solution for the problem Slobodan ... (defstruct composite-term str indices) ... (push (cons (composite-term-str item) ...
    (comp.lang.lisp)
  • Re: Free word order
    ... > Frontwardness of language: Going S O V. ... I agree that SVO is a bit mixed-up for me as a native speaker of a SOV ... In a SOV language by analogy, the arguments are pushed to the stack ... no idea so push it ...
    (sci.lang)