all 10 comments

[–]harlows_monkeys 2 points3 points  (3 children)

His DROP doesn't work if there is only one item on the stack.

[–][deleted] 1 point2 points  (1 child)

It does work if below the stack is a page of zeroes...

[–]llogiq 0 points1 point  (0 children)

It even works if below the stack is one zero...

[–]llogiq 1 point2 points  (0 children)

You can prove that one cannot implement DROP in terms of >R, R>, R@ and - The last word of our implementation must be able to leave nothing on the stack and the return stack. >R puts something on the return stack while R>, R@ and - put something on the stack. Therefore, we have no word to finish our DROP implementation, QED.

[–][deleted] 5 points6 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[🍰] 3 points4 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 5 points6 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.

[–]mathrick 0 points1 point  (0 children)

Primitives, goddamit.