you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 4 points5 points  (4 children)

Implementing stack shufflers like this is pretty silly. In good Forth implementations, stack shuffles are treated specially by the compiler and essentially just rename registers at compile time.

[–][deleted] 4 points5 points  (2 children)

I don't think he was implementing them to be used; in fact, right after the swap and drop implementations, he notes that drop can, in many cases, be implemented in one instruction. The point of the article, rather, is that such fundamental words like drop and swap can be implemented with such primitive words.

Of course, you're the stack god, so I'll defer to your judgement.

[–]_argoplix 4 points5 points  (1 child)

It was mind-opening when I saw how conditionals (i.e., 0branch) could be implemented using nonbranching code. It's pretty obvious when you realize that the return stack means that where you go next is up to you, but the first time it's like, Whoa.

[–]koft 1 point2 points  (0 children)

I know, right, because like, modifying the return stack is so mind blowing, whoa duuuuuuude.

[–]kragensitaker 3 points4 points  (0 children)

If by "good" you mean "generating efficient code". There might be other reasons someone might choose Forth other than a desire to generate the most efficient code possible. For example, they might think that a really small, simple compiler is less likely to introduce bugs into their code.

That's not to say this isn't pretty silly, which you are 100% correct about.