diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js index a685542..532dc89 100644 --- a/desktop/sources/scripts/library.js +++ b/desktop/sources/scripts/library.js @@ -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 + } } diff --git a/desktop/sources/scripts/lisp.js b/desktop/sources/scripts/lisp.js index c54763e..31ea659 100644 --- a/desktop/sources/scripts/lisp.js +++ b/desktop/sources/scripts/lisp.js @@ -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) } } diff --git a/examples/arrays.lisp b/examples/arrays.lisp index 76306e6..3389fa1 100644 --- a/examples/arrays.lisp +++ b/examples/arrays.lisp @@ -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) diff --git a/examples/logic.lisp b/examples/logic.lisp index f45f176..2c612d9 100644 --- a/examples/logic.lisp +++ b/examples/logic.lisp @@ -6,4 +6,6 @@ (print (and 1 false 2)) (print (or false false 2 false)) + + (if (gt 1 2) (print "ok") (print "not ok")) ) \ No newline at end of file