allow function arguments as a vector (Clojure style)

This commit is contained in:
Pekka Laiho 2020-12-05 09:57:54 +07:00
parent 894bd96e06
commit a96b6faa93
2 changed files with 3 additions and 3 deletions

View File

@ -149,7 +149,7 @@ def | `(def addOne (fn (a) (+ a 1)))` | `<function>` | Define a value in the c
do | `(do (print 1) 2)` | `12` | Evaluate multiple expressions and return the value of the last.
env | `(env +)` | `<function>` | Return a definition from the current environment represented by argument. Without arguments return the current environment as a hash-map.
eval | `(eval (quote (+ 1 2)))` | `3` | Evaluate the argument.
fn | `(fn (a b) (+ a b))` | `<function>` | Create a function.
fn | `(fn (a b) (+ a b))` | `<function>` | Create a function. Arguments can also be given as a vector instead of a list.
if | `(if (< 1 2) "yes" "no")` | `"yes"` | If the first argument evaluates to true, evaluate and return the second argument, otherwise the third argument. If the third argument is omitted return `null` in its place.
let | `(let (a (+ 1 2)) a)` | `3` | Create a new local environment using the first argument (list) to define values. Odd arguments are treated as keys and even arguments are treated as values. The last argument is the body of the let-expression which is evaluated using this new environment.
load | `(load "file.mad")` | | Read and evaluate a file. The contents are implicitly wrapped in a `do` expression.

View File

@ -138,8 +138,8 @@ class Evaller
throw new MadLispException("fn requires exactly 2 arguments");
}
if (!($astData[1] instanceof MList)) {
throw new MadLispException("first argument to fn is not list");
if (!($astData[1] instanceof Seq)) {
throw new MadLispException("first argument to fn is not seq");
}
$bindings = $astData[1]->getData();