adds if and filter

This commit is contained in:
Quentin Leonetti
2019-07-13 21:15:03 +02:00
parent d5225a3d68
commit 56402870fc
4 changed files with 24 additions and 0 deletions

View File

@@ -66,6 +66,10 @@ function Library (ronin) {
return arr.map(fn)
}
this.filter = (fn, arr) => {
return arr.filter(fn)
}
this.first = (arr) => {
return arr[0]
}
@@ -155,7 +159,12 @@ function Library (ronin) {
this.mul = function (a, b) {
return a * b
}
this.div = function (a, b) {
return a / b
}
this.mod = function (a, b) {
return a % b
}
}

View File

@@ -35,6 +35,13 @@ function Lisp (input, lib) {
return interpret(input[2], new Context(lambdaScope, context))
}
},
if: function (input, context) {
if (interpret(input[1], context)) {
return interpret(input[2], context)
}
return interpret(input[3], context)
}
}