4 ms·
<rant> The "why concatenative programming matters" example is a strawman to begin with. The correct solution in standard Forth is "DUP >R DUP * SWAP * + R> ABS
by astrobe_ 9y ago
<rant>
The "why concatenative programming matters" example is a strawman to begin with. The correct solution in standard Forth is "DUP >R DUP * SWAP * + R> ABS -" not the rot3 garbage they exhibit (yes, I ignored the useless z parameter because it's beyond the idiocy I can deal with).
Same goes for the (ab+cd) example, that simply writes "* >R * R> +".
Two stacks, problem solved. Forth lets you use the return stack for a reason. If you're a chicken, just provide a second user stack and hide the return stack. Problem solved.
But I guess that introducing and writing about the powerful (this word, really, should be treated as an intellectual smell) ";" operator is more fun. The only problem is that this operator actually doesn't work on stacks but arrays. Oops.
But, hey, can have infix notation!
</rant>
- glibgil 9y ago> ";" operator is more fun. The only problem is that this operator actually doesn't work on stacks but arrays. Oops. It's suppose to work on arrays. He's creating a concatenative array processing language. > This is basically a more sane version of forks and hooks in J > I want to create my own little concatenative array language > I'm not a fan of APL/J style one-liners, I prefer simple expressions with lots of `where`. > So I started to think about design of a sane array programming language. And I contunued to dream about it until meeting a real problem > A concatenative array programming language... I'd rather start from something simple. Like `;` operation, that brings the power of forks and hooks in J into concatenative programming https://github.com/evincarofautumn/kitten/issues/174 https://github.com/evincarofautumn/kitten/issues/174 https://github.com/suhr/esobsc/commit/809241a726f2c97dac90bccf2779b3792c6bc5bf https://github.com/suhr/esobsc/commit/809241a726f2c97dac90bc...
- Someone 9y ago> The correct solution in standard Forth is "DUP >R DUP * SWAP * + R> ABS -" I don’t think that can be correct. Multiplication is commutative, so SWAP before * doesn’t do anything, getting “DUP >R DUP * * + R> ABS -“, which means it computes x^2 y for some x and y somewhere along the way. To compute y^2+x^2-|y| in forth, I would use multiple functions, for example : ^2 DUP * ; : x^2-|x| DUP ^2 SWAP ABS - ; : f x^2-|x| SWAP ^2 + ;
- astrobe_ 9y agoI stand corrected, I forgot a DUP: DUP >R DUP * SWAP DUP * + R> ABS - I didn't want to use helper words to allow for a 1:1 comparison. And I also forgot that standard Forth has TUCK (<=> SWAP OVER), so one can do it without the return stack as well (using helpers this time): TUCK ^2 SWAP ^2 + SWAP ABS -