Find a file
2012-07-16 23:37:48 -04:00
examples Get rid of interpreter, repl now reads, compiles, executes, prints 2012-07-15 10:03:49 -04:00
src/cloforth Changed recur to be a prim, since it can only recur in a word if it is in the word 2012-07-16 23:06:02 -04:00
test/cloforth/test Use : to define new words, not define 2012-07-15 10:05:57 -04:00
.gitignore Initial commit 2012-07-12 05:12:12 -07:00
init.c4 added command to print the top of the stack w/o popping it 2012-07-16 23:01:29 -04:00
project.clj Added main class 2012-07-16 23:37:48 -04:00
README.md Added some basic cloforth doc 2012-07-16 23:37:28 -04:00

cloforth

A little Cloforth-like language implemented in Clojure

Cloforth is a stack oriented, postfix languages. What this means is that numbers just get pushed onto the stack, so:

3

Will simply push 3 onto the stack, while

3 5

Will first push 3 then 5 onto the stack. The typical operators will pop a couple of numbers off of the stack, operate on them and then push the result back on, so that:

3 5 +

Will leave you with 8 on the stack.

Cloforth commands are called 'words'. So there is an 'nl' word which just prints a newline. So do this:

nl

And you will see a blank line printed. Another word is the plain old dot: . Yes, it's not much of a word, but that is the jargon. The . word justs prints whatever is on the top of the stack (popping it off in the process) Thus if you do this:

3 . nl

You will see a three followed by a newline printed.

Other handy words are dup, which pushes a copy of whatever is on top of the stack back onto the stack, so that

3 dup . nl

Will print the three and also leave it on top of the stack.

You can define your own words with :
Colon takes a name and a list of words
enclosed in [ ] and defines a new word.
Thus this:

plus1 [ 1 + ]

Defines a new word called 'plus1' that adds one to whatever is on the top of the stack.