diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2022-09-25 17:15:16 +0300 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2022-12-05 14:21:53 +0200 |
| commit | 09e74ca747d49c69eebd0013f12c9fd5b26c07d7 (patch) | |
| tree | 3219be4fd948ee31428a4ea3050882efc3f851a8 /spec.md | |
| parent | 2a35e9cb7ad4f0ed350362135dd0d3094db27d09 (diff) | |
Improve docs
Diffstat (limited to 'spec.md')
| -rw-r--r-- | spec.md | 74 |
1 files changed, 74 insertions, 0 deletions
@@ -0,0 +1,74 @@ +# Language spec + +- Dynamically and weakly typed, interpreted +- Impure functions marked with ! (convention) +- Boolean functions marked with ? (convention) +- Loops implemented with recursion + +## Value types + + Number -3.14 + Symbol PI + Boolean true + String "foobar" + Vector [1 2 3] + Hash map { a 1 b 2 } + Function (\[x y] (+ x y)) + +## Syntax + +### Function calls + +A sequence of values surrounded by parens is considered a function call In a function call, the first element must evaluate to a function value. The function will be invoked with the rest of the elements as arguments to the function. + +### Function definition +Calling the builtin variadic function '\' constructs a new function. The first argument must be a vector of symbols (parameter list). The rest of the arguments form the function body. The evaluated value of the last argument is returned as the return value of the function. + +### Currying + +Functions are automatically curried +E.g. + + (let f1 (\[x y] (+ x y))) + (let f2 (\[x] (\[y] (+ x y)))) + ; f1 equivalent to f2 + +## Some builtin functions + +`let` +Evaluates second argument and stores the resulting value in the environment. + + (let sum2 (\[x y] (+ x y))) + +`\` +Defines a function. + + (\[x y] + x y) + +`print!` +Prints a value and a newline. + + (print! PI) + +`match` +Matches first argument (value) to even positioned arguments (matchers). On match (at position i), evaluates the odd positioned argument (branch) right after it (at position i + 1). If given an even number of arguments, the last argument will act as the default branch. + + (match (sum2 1 1) + 2 (do-thing) + 3 (do-other-thing) + (do-else)) + +`head` +Gets the first element of a vector. + + (head vec) + +`tail` +Drops the first element of a vector. + + (tail vec) + +`prepend` +Pushes the first argument to the front of the second argument (vector). + + (prepend x xs) |
