From d5225a3d68eac93caee1885fd0f4c553da778196 Mon Sep 17 00:00:00 2001 From: Quentin Leonetti Date: Sat, 13 Jul 2019 20:57:12 +0200 Subject: [PATCH] Add logic functions --- desktop/sources/scripts/library.js | 33 ++++++++++++++++++++++++++++++ examples/logic.lisp | 9 ++++++++ 2 files changed, 42 insertions(+) create mode 100644 examples/logic.lisp diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js index f054041..a685542 100644 --- a/desktop/sources/scripts/library.js +++ b/desktop/sources/scripts/library.js @@ -28,7 +28,40 @@ function Library (ronin) { console.log(...args) } + // Logic + + this.gt = (a, b) => { + return a > b + } + + this.lt = (a, b) => { + return a < b + } + + this.eq = (a, b) => { + return a === b + } + + this.and = (...args) => { + for (let i = 0; i < args.length; i++) { + if (!args[i]) { + return args[i] + } + } + return args[args.length - 1] + } + + this.or = (...args) => { + for (let i = 0; i < args.length; i++) { + if (args[i]) { + return args[i] + } + } + return args[args.length - 1] + } + // Arrays + this.map = (fn, arr) => { return arr.map(fn) } diff --git a/examples/logic.lisp b/examples/logic.lisp new file mode 100644 index 0000000..f45f176 --- /dev/null +++ b/examples/logic.lisp @@ -0,0 +1,9 @@ +( + (print (lt 3 4)) + + (print (and 1 2 true 4)) + + (print (and 1 false 2)) + + (print (or false false 2 false)) +) \ No newline at end of file