Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm interested in learning a stack-oriented programming language (such as Forth), which one would you recommend? The qualities I want are:

  • You should be able to develop non-trivial software in it, but it mustn't be a great language for that as:
  • I want to learn the language so I can try out a new paradigm (that is, not because I (think) that I will have great use of it). The reason I want to learn another paradigm is that I want to broaden my views on different approaches (learn to think in new ways, different from OOP, functional and structured). The language should let me do that (learn to think differently).
  • The language should have available and good resources to learn from. The resources should also approach stack-oriented programming in a way that you understand the paradigm (after all, I do this for the paradigm).
share|improve this question

closed as not constructive by gnat, MichaelT, Bart van Ingen Schenau, GlenH7, Kilian Foth May 19 '13 at 15:12

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

Whitespace!!!!! –  Michael K Mar 3 '11 at 16:03
Befunge!!!!!!!! –  Thomas Eding Nov 11 '12 at 2:35
add comment

7 Answers

up vote 10 down vote accepted

You answered your own question. FORTH is an outstanding language. Not only is it stack-oriented but also it'll also teach you a great deal about meta-programming. FORTH is also notable in that it can be self-hosting with a very small kernel of natively-implemented routines.

Additionally, one of the greatest programming books ever written, Thinking Forth, is nominally oriented towards that language, but its lessons apply to programming practice in all langauges and in all paradigms.

share|improve this answer
+1: Since the question mentioned forth, why not start with forth? –  S.Lott Mar 3 '11 at 16:30
add comment

I'm (reliably) told that Factor is a very interesting language to learn.

The Factor programming language combines powerful language features with a full-featured library. The implementation is fully compiled for performance, while still supporting interactive development. Factor applications are portable between all common platforms. Factor can deploy stand-alone applications on all platforms. Full source code for the Factor project is available under a BSD license...

Factor belongs to the family of concatenative languages: this means that, at the lowest level, a Factor program is a series of words (functions) that manipulate a stack of references to dynamically-typed values. This gives the language a powerful foundation which allows many abstractions and paradigms to be built on top...

    USING: io math sequences ;        
    "Hello world" print
    10 [ "Hello, Factor" print ] times
    "Hello, " "Factor" append print
share|improve this answer
Factor has a lot going for it. It's actively developed, comes with an interesting development environment, is well documented, and has a huge up-to-date library that offers concurrency abstractions, database bindings, and even a web server and web dev. framework. –  Corbin March Mar 3 '11 at 17:17
add comment

Why don't you start with FORTH.

It's the classic stack language and there's good documentation.

Its non-trivial having been used to control telescopes and boot loaders and all sorts of things...

Yet its simple enough to start messing with that you will probably find yourself being tempted to write your own compiler for it - which will take you on a whole new journey!

share|improve this answer
add comment

I would recommend:

  1. Lisp
  2. PostScript

I struck out Lisp since it's not purely stack based. I guess that shows what my CS degree is really worth. However, it still wouldn't be a bad example of a language that could teach stack-oriented programming since it does rely heavily on stacks for all of its operations.

Thanks to those commenters who brought this to my attention.

share|improve this answer
Why would you reccommend Lisp? –  Michael K Mar 3 '11 at 16:09
Is LISP stack-oriented? –  Anto Mar 3 '11 at 16:10
@SK-logic - that's what I'm reading. I'm about to make an edit. It looks like "pure" lisp in the original form would be the closest, but even though lisp is heavily reliant on the stack, it can't be called stack-based because it provides distinctly non-stack features. –  Joel Etherton Mar 3 '11 at 16:24
@Anto - I read that one, but it didn't really say anything about it definitively either way. I programmed in Lisp in college, so I know it is heavily reliant on stacks (confirmed by the wikipedia article), but since it's not mentioned on the stack-oriented languages article (en.wikipedia.org/wiki/Stack-oriented_programming_language), and I really think it would be if it qualified, I will accept that as proof positive. I have already issued an edit. Thanks :) –  Joel Etherton Mar 3 '11 at 16:29
+1 for Postscript. –  mouviciel Mar 3 '11 at 16:42
show 3 more comments

You might also consider concatenative languages:

There are many ways to categorize programming languages; one is to define them as either "concatenative" or "applicative". In an applicative language, things are evaluated by applying functions to arguments. This includes almost all programming languages in wide use, such as C, Python, ML, Haskell, and Java. In a concatenative programming language, things are evaluated by composing several functions which all operate on a single piece of data, passed from function to function. This piece of data is usually in the form of a stack. Additionally, in concatenative languages, this function composition is indicated by concatenating programs. Examples of concatenative languages include Forth, Joy, PostScript, Cat, and Factor...

Although the terms stack language and concatenative language sometimes get thrown around interchangeably, they actually represent similar but distinct classes of languages. A concatenative language is not necessarily a stack language. For example, Om uses prefix notation, rather than postfix, and passes the remainder of the program as the data from function to function. See Deque for another example of a stack-free concatenative language.

Stacks are a pretty fundamental concept in computer science, and many languages use stacks internally in the implementation. Any language that allows recursive definitions uses some type of call stack to save return addresses between function calls, and often the same stack is used to spill values which cannot be allocated in registers. However, this is just implementation detail, and this call stack is not exposed directly to the programmer (except in languages with first-class continuations; I'll touch upon this later).

So what makes stack languages different? The key concept here is that there are multiple stacks: all stack languages have a call stack to support recursion, but they also have a data stack (sometimes called an operand stack) to pass values between functions. The latter is what stack language programmers mean when they talk about "the" stack...

share|improve this answer
add comment

Forth! If you want an example of a serious Forth-based application, look no further than OpenBoot. Every RISC-based Sun workstation and server has shipped with OpenBoot. One can have a blast playing with an OpenBoot-based Sun machine without ever booting Solaris.

Also, Forth was used to develop the old FedEx hand scanners. Forth is still widely used in resource-constrained environments.

share|improve this answer
add comment

Don't forget:

  • Onyx - stack-oriented scripting
  • Enchilada - Robbert van Dalen is one of those geniuses that doesn't realize he's a genius. That makes other people question if he's a genius. Make no mistake, he's a genius.
  • Staapl - A Racket extension. I love Scheme so this was extra appealing.
share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.