Hacker News new | ask | show | jobs
by cduan 5601 days ago
PostScript is another stack-based language based on Forth, but with specialized graphics commands. It also has the delightful property that many printers can interpret it. I always wished I had known this while taking my intro CS courses, so that I could have submitted my problem sets as PostScript files, to be computed by the printer.
2 comments

I used PostScript to implement a back-propagation neural network trainer for one of my AI classes. It's not beautiful postscript code (many local variables, some parts are very clumsy because I didn't know better), but fun nonetheless: http://pastebin.com/eY0d11sA
I came to Forth after programming in Postscript and still have a fondness for stack-based languages. I actually think Postscript was the better language of the two, it seemed to easier somehow.

// In the early 90's I got a job that needed me to create a lot of reports / graphs out of a foxbase database. I had a postscript printer and a copy of Turbo C 2.0 (don't forget to download the floating point patch). Gotta love hand coding Postscript templates. I was loving life when I finally got a openstep box.

Factor's heterogenous stack (complex objects rather than integers) definitely reminds me more of PostScript than Forth, and I agree it can make programming much more straightforward. I also liked how PS handles flow control- while Forth uses rather traditional looking left-to-right reading constructs:

  3 5 > if ." greater" else ." less" then
PostScript goes with operators like "if" and "ifelse" that consume code literals from the stack (enclosed in curly braces):

  3 5 gt { (greater) print } { (less) print } ifelse
It's a little heavier weight, but very flexible and it feels like a natural way to handle postfix conditionals.