Added Daniel Gackle <danielgackle@gmail.com>'s contributed [] (nested) array literal...
authorVladimir Sedach <vsedach@gmail.com>
Mon, 8 Dec 2008 02:40:57 +0000 (19:40 -0700)
committerVladimir Sedach <vsedach@gmail.com>
Mon, 8 Dec 2008 02:40:57 +0000 (19:40 -0700)
src/lib/ps-macro-lib.lisp
src/package.lisp
t/ps-tests.lisp

index aab3614..17ec73d 100644 (file)
 
 ;;; Data structures
 
+(defpsmacro [] (&rest args)
+  `(array ,@(mapcar (lambda (arg)
+                      (if (and (consp arg) (not (equal '[] (car arg))))
+                          (cons '[] arg)
+                          arg))
+                    args)))
+
 (defpsmacro length (a)
   `(@ ,a length))
 
index 834abea..126fd5a 100644 (file)
@@ -21,6 +21,7 @@
       #:list
       #:aref
       #:make-array
+      #:[]
 
       ;; operators
       #:! #:not #:~
index 409b2d5..dd96ba7 100644 (file)
@@ -332,6 +332,26 @@ x = 2 + sideEffect() + x + 5;")
   ({} a 1 b 2)
   "{a: 1, b: 2 }")
 
+(test-ps-js array-literal1
+  []
+  "[]")
+
+(test-ps-js array-literal2
+  ([])
+  "[]")
+
+(test-ps-js array-literal3
+  ([] 1 2 3)
+  "[1, 2, 3]")
+
+(test-ps-js array-literal4
+  ([] 1 (2 3))
+  "[1, [2, 3]]")
+
+(test-ps-js array-literal5
+  ([] (1 2) ("a" "b"))
+  "[[1, 2], ['a', 'b']]")
+
 (test-ps-js defun-rest1
   (defun foo (&rest bar) (alert bar[1]))
   "function foo() {