Added length, @, mapcar utility functions, exported all library function symbols.
[clinton/parenscript.git] / src / lib / js-utils.lisp
index 5644972..5e413bd 100644 (file)
 (defpsmacro ignore-errors (&body body)
   `(try (progn ,@body) (:catch (e))))
 
+;;; Data structures
+
+(defpsmacro length (a)
+  `(.size ,a))
+
 ;;; Misc
 
 (defpsmacro null (x)
   `(= ,x nil))
+
+(defpsmacro @ (obj &rest props)
+  "Handy slot-value/aref composition macro."
+  (if (null props)
+      obj
+      `(@ (slot-value
+           ,(if (stringp obj) `($ ,obj) obj)
+           ,(let ((prop (macroexpand (first props))))
+                 (if (symbolp prop)
+                     `',prop
+                     prop)))
+        ,@(cdr props))))
\ No newline at end of file