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)
}
}

View File

@ -5,6 +5,12 @@
(print (rest (1 2 3)))
)
(print
(filter
(lambda (a) (eq 0 (mod a 2)))
(1 2 3 4 5))
)
(
(clear)
(map (lambda (a)

View File

@ -6,4 +6,6 @@
(print (and 1 false 2))
(print (or false false 2 false))
(if (gt 1 2) (print "ok") (print "not ok"))
)