Skip to content

Instantly share code, notes, and snippets.

@reiddraper
Created February 27, 2013 04:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reiddraper/5045067 to your computer and use it in GitHub Desktop.
Save reiddraper/5045067 to your computer and use it in GitHub Desktop.

I've been reading a bit about concatenative languages recently, and figured I'd compose a short reading list for others interested.

I won't explain what a concatenative language is, but I do want to quickly say a couple of the reasons I find them interesting.

Refactoring

I already like to write really tiny functions, and concatenative languages make it really easy to factor a function into a smaller one. Here's an example, in a made up concatenative language:

# add one to a number and then square the result
define add-one-and-square == 1 + dup *

If we decide this is too long, we just have to choose a point to cut the function, and give it another name. No need to figure out the named dependencies, or use any automatic refactoring tool:

# add one to a number and then square the result
define add-one-and-square == 1 + square
define square == dup *

Metaprogramming

What I'm about to describe isn't a feature of all concatenative languages, namely, statically typed ones like Cat do not support this (as far as I'm aware anyway). In Lisps, code is data, but only when you explicitly 'quote' it. You can't decide to take any reference you have to a function and turn it back into a list. In languages like Factor and Joy, you can. Concatenative langs call anonymous functions 'quotations', and a quotation and a list are the same thing. Here's a trivial example:

# here's a normal functional 'map',
# which adds 1 to each number
[1 2 3 4 5] [1 +] map

# before we apply the quotation (`[1 +]` above), we can
# manipulate it. Here we simply get rid of the
# `dup +` part.
[1 2 3 4 5] [dup + dup *] rest rest map

The list

Anyway, here's the reading list:

  1. Why Concatenative Programming Matters. A good introduction to the subject.
  2. The Joy of Concatenative Languages Parts 1-3 Some really interesting words on statically typing concatenative languages
  3. Mathematical foundations of Joy. Some theory.
  4. The Joy Homepage (mirror) Reading the FAQ page here is when I had the revelation that lists and quotations were the same thing (not just when you ask them to be, like in lisp). The tutorial is also good.
  5. Linear Logic and Permutation Stacks--The Forth Shall Be First. This last one is a bit different, but I'm personally really interested in Linear typing (and uniqueness, etc.), so I found the relationship between concatenative languages and linear typing really cool. I'd love to see a low-level concatenative language combine these two.
  6. There's a bunch of LtU threads about concatenative languages, here's a good start. Here too.
@reiddraper
Copy link
Author

@jduey added 'Thinking in Forth' by Leo Brodie.

@mcpherson
Copy link

You could check out http://concatenative.org/ and, in particular, the Factor language at http://factorcode.org.

@fogus
Copy link

fogus commented Feb 28, 2013

The Theory of Concatenative Combinators: http://tunes.org/~iepos/joy.html

My History with Forth and Stack Machines: http://www.yosefk.com/blog/my-history-with-forth-stack-machines.html

Stack Computers - the New Wave: http://www.ece.cmu.edu/~koopman/stack_computers/index.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment