diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2022-12-08 14:28:00 +0200 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2022-12-08 14:28:00 +0200 |
| commit | 642f073b446cbcee3eb74bad72129fa37e4c6f46 (patch) | |
| tree | 39f43ebc428d3684e7d5584bb12b4c55d4d078f3 /spec.md | |
| parent | 4674bc3a6fa11339d75d55fd82b9574cee587f5d (diff) | |
Fix fn call with zero arguments
Diffstat (limited to 'spec.md')
| -rw-r--r-- | spec.md | 36 |
1 files changed, 22 insertions, 14 deletions
@@ -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. |
