aboutsummaryrefslogtreecommitdiffstats
path: root/spec.md
diff options
context:
space:
mode:
Diffstat (limited to 'spec.md')
-rw-r--r--spec.md36
1 files changed, 22 insertions, 14 deletions
diff --git a/spec.md b/spec.md
index 953b672..934e119 100644
--- a/spec.md
+++ b/spec.md
@@ -1,28 +1,36 @@
# Language spec
- Dynamically and weakly typed, interpreted
-- Impure functions marked with ! (convention)
+- Impure functions marked with ! (convention), purity is tracked by the interpreter
- 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))
+ Number -3.14
+ Symbol PI
+ Tag :tag
+ 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.
+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. A function call with no arguments evaluates to the function itself.
### 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.
+
+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.
+
+Memoized pure functions can be created with a special `let memo`-binding:
+
+ (let memo f (\[x] x))
+
+Impure functions can be created with the builtin `\!`.
### Currying
@@ -43,20 +51,20 @@ Evaluates second argument and stores the resulting value in the environment.
`\`
Defines a function.
- (\[x y] + x y)
+ (\[x y] (+ x y))
`print!`
-Prints a value and a newline.
+Prints a value without 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.
+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).
(match (sum2 1 1)
2 (do-thing)
3 (do-other-thing)
- (do-else))
+ otherwise (do-else))
`head`
Gets the first element of a vector.