5 ms·
As I see it, the key characteristic of stack-oriented programming is not that it "uses postfix notation". Rather, the key characteristic is that there is an im
by triska 7y ago
As I see it, the key characteristic of stack-oriented programming is not that it "uses postfix notation".
Rather, the key characteristic is that there is an important implicit feature available, namely the stack (or, as for example in the case of PostScript, several stacks), by which arguments can be passed along.
As a consequence, you get a form of compositionality of language elements that is not available in languages that lack this feature: A language element may consume, change and create entities on the stack, and the next language element can pick them up implicitly.
This often allows very concise and elegant code, and can also be interpreted very efficiently.
- jerf 7y agoBest advocacy I know of: http://evincarofautumn.blogspot.com/2012/02/why-concatenative-programming-matters.html http://evincarofautumn.blogspot.com/2012/02/why-concatenativ... Presented by way of being an interesting link, and the educational nature of reading the best arguments in favor of something. I haven't done anything in concatenative programming in about 20 years, since I left math class and didn't need my HP 48G anymore.
- munk-a 7y agoThat's quite helpful, it may be a lack of in-depth reading of the page but the persistence and implicit passing of computation between operations is helpful to understand the differentiation. In more classic procedural languages you'll usually have a function stack that is being pushed and popped two but actual program values are handled using entirely arbitrarily loaded references that get juggled around as needed for computation - does stack programming often have a similar concept to frame popping when an issue with I/O or something similar is encountered or do we just get a panic that aborts computation?
- triska 7y agoTo get a glimpse of stack-oriented programming, I really like and recommend PostScript, because this also automatically introduces you to a widely used programming language with important practical applications, and it's also great fun to learn. So, for instance, let's elicit an error using Ghostscript, a freely available and efficient PostScript interpreter: $ gs GPL Ghostscript 9.27 (2019-04-04) ... At the "GS>" prompt, I now define "f" via: /f { /hello g } def Note that "f" refers to "g", which is not yet defined. Therefore, when I then invoke "f" via: GS>f I get an error: Error: /undefined in g And importantly, the stack is retained, so I can inspect it at this point, interactively, using for example "pstack": GS<1>pstack /hello This shows that /hello is still on the stack. From there, we can resume in various ways, for example by clearing the stack (with "clear"), by redefining and reinvoking "f" etc.
- haolez 7y agoIs PostScript used beyond page description? I'm really curious :)
- PeCaN 7y agoSun made a windowing system based on (Display) PostScript way back https://en.wikipedia.org/wiki/NeWS https://en.wikipedia.org/wiki/NeWS
- hnick 7y agoIt's Turing-complete, which makes writing programs to analyse documents a bit of a problem at times. But I think maybe you meant in the sense of "in the real world", and I can't think of any examples. Prefixing some postscript to a document to manipulate that file is something it can be suited for, rather than using an external language to do so.
- RodgerTheGreat 7y agoOnce I wrote a bingo card in PostScript which would randomize its cells every time you printed it. That's almost useful.
- kortex 7y agoI found a .ps that generates timing wheel patterns (discs with alternating black and white radial bands). you'd plug in inner/outer radius, number of bands, and you'd get a printable document from that file. As in, the .ps file was code, which printed as an image. I now know this is the origin of pdf but it blew my mind.
- pedrow 7y agoI recently saw an announcement[0] of a Z-machine in Postscript. The Z-machine is a runtime for text adventure games. Also posted on HN[1] but no comments were made. [0]: https://groups.google.com/d/msg/rec.arts.int-fiction/HNtntxCpcHA/IB0EiadzDgAJ https://groups.google.com/d/msg/rec.arts.int-fiction/HNtntxC... [1]: https://news.ycombinator.com/item?id=21367412 https://news.ycombinator.com/item?id=21367412
- narag 7y agoThere's an old language, pop11, that's similar to lisp but stack oriented. A few sections of the manual will show you the kind of stack tricks that make different order useful: https://www.cs.bham.ac.uk/research/projects/poplog/primer/#sec189 https://www.cs.bham.ac.uk/research/projects/poplog/primer/#s... Functions that return several results, implicit parameters, open stack, etc. It's a lot of fun.
- rixed 7y agoSounds like automatic currying in FPLs is equivalent to some of that.