Hacker Newsnew | comments | show | ask | jobs | submit login

Stack based and concatenative programming languages are something I find really interesting. It's really easy to implement a simple one, so one of my go-to benchmarks for trying out a new language is to implement a little stack based language in it.

They're a lot of fun, and some simple ideas can lead to really interesting results. Since all code is just a sequence of tokens it becomes trivial to treat words, quotations, and entire programs as lists and manipulate them a la Lisp. Another nice thing is many such languages give you access to the parser. One I wrote recently is (almost) interpreted directly from text and let's you hook into the parsing process. It doesn't have comments, but it's trivial to add them:

This turns "/*" into a function that will drop tokens until it comes to a terminating marker. Such functionality can be used for macros or to add to DSLs.

Also interesting is how the stack changes the way you write code. What you end up with is program that's entirely made of something like pipes in ML-like languages or chaining constructs in JavaScript. They're very easy to compose together (and generally there's less overhead) so it encourages "factoring" out into lots of little pieces; something you can do in almost any language but doesn't feel as natural IMO.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact