Friday, January 02, 2009

Advantages of concatenative and stack-based languages

Factor has many features that make it stand out -- I've blogged extensively about some of these, such as interactive development, the compiler, various libraries, application deployment, and so on. In those respects, I think it is pretty clear that Factor is competitive, or even ahead of, existing languages.

However, I don't think I've ever written about the one aspect of Factor that many programmers find the most striking: the fact that it is concatenative language. For example, a recent blog post titled 10 programming languages worth checking out, the author decided to add Factor to the list not because of any of the features I mentioned in the first paragraph, but because it uses a stack to pass parameters; that alone make it "worth checking out" in his view.

Because many people have asked me the question, "why the stack", I've finally decided to put together an overview of what these languages, and especially Factor, are all about. I've mentioned most of the material below in presentations, comments on forums and blogs, mailing list posts, and on IRC.

Indeed, I believe that the underlying paradigm in Factor is the "secret weapon" which has allowed such a small community to build up a robust language implementation with a large collection of very capable libraries in only 5 years. There are inherent productivity advantages here, and we probably would have given up long ago if Factor was harder to use than existing languages.

Originally I was going to write a series of blog posts, but I decided to put it in the wiki instead, under the Concatenative language article there.

On another note, I haven't done much hacking for the last two weeks because of a vacation; our git repository has been pretty quiet of late. On January 5th I go back to work, and there is good stuff coming up for the UI developer tools, compiler, and web framework.

4 comments:

zimbatm said...

Hi Slava, I liked to read what you have to say. The content is good but understandly a bit biased towards factor. Here is some feedback.

In the "Name code not values" page, your ultimate example to retrieving a child value is :

{ [ orders>> ] [ first ] [ price>> ] } maybe

I was wondering if something like this wouldn't be better ? :

[ orders>> first price>> ] chain-or-null

Or where [ f ] is the default value:

[ orders>> first price>> ] [ f ] chain-or

What do you think ? It's shorter but hides that each term is executed separately. This could be ok, if chain- is a convension that expresses that.

On the "Keyword parameters" page, I don't agree that your example is the best way to pass named parameters. I know this is a matter of taste but I believe that the old { key:value, ... } construct is more straight-forward to read.

Compare :
<\email>
"jack@aol.com" >>from
{ "jill@aol.com" } >>to
"Hello there" >>subject
body >>body
send-email

With:

{ from: "jack@aol.com", to: { "jill@aol.com" }, subject: "Hello there", body: body } <\email> send-email

Anyways, I might be not used to factor enough :)

Happy new year,
zimbatm

grant rettke said...

Slava what is your favorite "beginners" stack-based or concatenative language? I am interesting in learning the fundamentals; I'm not too worried about libraries and "being practical" at the moment.

The first and only answer i've got to this question is the Joy language.

Slava Pestov said...

grant: I would suggest learning Factor, of course. Did you already try and encounter difficulties? Factor has many features and libraries but you don't have to absorb everything all at once. You can start with the basics, and having the interactive UI with the tools that it offers (documentation, walker, inspector) is handy for learning the paradigm, I think.

grant rettke said...

Hi Slava. I understand that you are biased of course :), I was just looking for your feedback as a concatenative language expert.

No, I didn't have any problems with Factor. Rather I had downloaded Joy and come to find that some of the words in the tutorial were not in the runtime, and it led me to wonder how much it is used by folks (as a first language in particular).

Since you posted on concatenative languages on the same day, I somehow felt that it was timely so I wanted to get your input.

I will test out that theory of yours.