From 5de7d7fdc45f59d95bca6eba62174ea67863bbe6 Mon Sep 17 00:00:00 2001 From: Quentin Leonetti Date: Sat, 13 Jul 2019 18:18:35 +0200 Subject: [PATCH] adds first and rest --- desktop/sources/scripts/library.js | 9 +++++++++ examples/arrays.lisp | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js index 083282e..f054041 100644 --- a/desktop/sources/scripts/library.js +++ b/desktop/sources/scripts/library.js @@ -28,10 +28,19 @@ function Library (ronin) { console.log(...args) } + // Arrays this.map = (fn, arr) => { return arr.map(fn) } + this.first = (arr) => { + return arr[0] + } + + this.rest = ([_, ...arr]) => { + return arr + } + // Rects this.pos = (x, y, t = 'pos') => { diff --git a/examples/arrays.lisp b/examples/arrays.lisp index 97fad47..76306e6 100644 --- a/examples/arrays.lisp +++ b/examples/arrays.lisp @@ -1,5 +1,10 @@ (print (map (lambda (a) (add a 1)) (1 2 3))) +( + (print (first (1 2 3))) + (print (rest (1 2 3))) +) + ( (clear) (map (lambda (a)