Dochi is strongly influenced by Factor, Lua and Clojure.
Its design goal is to be lightweight and embeddable, similar to Lua.
Its default data structures are immutable, like Clojure.
It has been designed to be a largely static language.
- Code is a list of words, like Forth/Factor
- They operate on a stack
- Bindings can be introduced at any point:
- Results in 4:
1 (a) a 2 + a + - Results in 11:
2 3 4 (a b c) a a + b + c +
- Results in 4:
- Top level definitions use the ‘def’ keyword:
def square (a) a a * - All word definitions are inside a
module name - Use
use module-nameto import another module, or usemodule-name.word - Code quotations:
number? ["yes" write] ["no" write] if - Lists:
{1 2 3 4}is syntax sugar forf 4 ; 3 ; 2 ; 1 ;where;is cons - Literal values:
- Keywords:
:hello - Strings:
"hello" - Character:
Ch{h} - List:
L{1 2 3 4} - Table:
T{:a 1 :b 2 :key value} - Cons:
C{1 2}
- Keywords:
| word | stack effect | description |
|---|---|---|
| pp | (value → ) | pretty prints a value |
| write | (string → ) | writes a string to output |
| →string | (value → string) | converts a value to a string |
| if | (condition true-quot false-quot → ) | branch based on condition |
| + – * / | (num num → num) | operate on two numbers |
| < <= > >= = | (value value → bool) | compare two values |
| << | (table value keyword → ) | associate keyword with value in table |
| >> | (table keyword → value) | return association of keyword in table |
| keys | (table → list) | table keys |
| values | (table → list) | table values |
| union | (table table → union) | union of two tables |
| ; | (value value → cons) | cons two values |
| head | (cons → value) | head of cons |
| tail | (cons → value) | tail of cons |
| length | (list → number) | length of list |
| nth | (list n → value) | nth value of list |
Parse.dochiParseFileTurns a string of code into a[ChiModuleAST].Interpreter.emptyStatean empty interpreter state.Interpreter.injectASTcompiles and injects a list ofChiModuleASTinto the interpreter state.Interpreter.injectLibinjects a HaskellChiModuleinto the interpreter state.Interpreter.runWordruns a word in the given interpreter state.Interpreter.runDochiruns a string of code in the given interpreter state.Util.runFilestakes a list of filenames, parses and compiles them, and runs ‘main.main’Util.runFilesWithStatedoes the same with an initial state.