mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-26 15:14:12 +00:00
allow function arguments as a vector (Clojure style)
This commit is contained in:
parent
894bd96e06
commit
a96b6faa93
@ -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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
load | `(load "file.mad")` | | Read and evaluate a file. The contents are implicitly wrapped in a `do` expression.
|
||||||
|
@ -138,8 +138,8 @@ class Evaller
|
|||||||
throw new MadLispException("fn requires exactly 2 arguments");
|
throw new MadLispException("fn requires exactly 2 arguments");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!($astData[1] instanceof MList)) {
|
if (!($astData[1] instanceof Seq)) {
|
||||||
throw new MadLispException("first argument to fn is not list");
|
throw new MadLispException("first argument to fn is not seq");
|
||||||
}
|
}
|
||||||
|
|
||||||
$bindings = $astData[1]->getData();
|
$bindings = $astData[1]->getData();
|
||||||
|
Loading…
Reference in New Issue
Block a user