From: David Vázquez Date: Sun, 20 Jan 2013 16:03:51 +0000 (+0000) Subject: MAKE-ARRAY, AREF, ASET and ARRAYP functions X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=e20b874683975419bcc58a380208d13e95944d35;p=jscl.git MAKE-ARRAY, AREF, ASET and ARRAYP functions --- diff --git a/ecmalisp.lisp b/ecmalisp.lisp index d015254..80f2344 100644 --- a/ecmalisp.lisp +++ b/ecmalisp.lisp @@ -1775,6 +1775,26 @@ (type-check (("x" "string" x)) "lisp.write(x)")) +(define-builtin make-array (n) + (js!selfcall + "var r = [];" *newline* + "for (var i = 0; i < " n "; i++)" *newline* + (indent "r.push(" (ls-compile nil) ");" *newline*) + "return r;" *newline*)) + +(define-builtin arrayp (x) + (js!bool + (js!selfcall + "var x = " x ";" *newline* + "return typeof x === 'object' && 'length' in x;"))) + +(define-builtin aref (array n) + (concat "(" array ")[" n "]")) + +(define-builtin aset (array n value) + (concat "(" array ")[" n "] = " value)) + + (defun macro (x) (and (symbolp x) (let ((b (lookup-in-lexenv x *environment* 'function)))