3 ms·
>For instance, suppose we push 200 operands onto the stack Then you're already doing something gravely wrong. The data stack should not be used like a data str
by chunes 5y ago
>For instance, suppose we push 200 operands onto the stack
Then you're already doing something gravely wrong. The data stack should not be used like a data structure. That would be analagous to passing 200 arguments to a function.
- DonHopkins 5y agoPostScript has a special data type called a "mark" just for making dynamically sized arrays. So in PostScript when you see: [ 1 2 3 ] What actually happens is that "[" simply pushes a "mark", 1 2 and 3 push numbers (or you could execute any code that pushed any number of any kind of object, including nested arrays and dictionaries), and "]" does the equivalent of "counttomark array astore exch pop" where "counttomark" pushes 3 (the number of items after the mark), "array" consumes 3 and returns an an empty array of 3 elements, and "astore" pops the array, consumes as many stack elements as it is long, puts them into place in the array, and then pushes the modified array back on the stack, then "exch pop" discards the mark and keeps the array. But you're right, no Forth programmer in their right mind would push 200 items on the stack, and Forth doesn't have a "mark" type (or rather, it doesn't tag objects on the stack with their type like PostScript and Lisp do, so there is no telling the difference between a mark and other types).