Added length, @, mapcar utility functions, exported all library function symbols.
authorVladimir Sedach <vsedach@gmail.com>
Sun, 4 Nov 2007 18:05:53 +0000 (18:05 +0000)
committerVladimir Sedach <vsedach@gmail.com>
Sun, 4 Nov 2007 18:05:53 +0000 (18:05 +0000)
parenscript.asd
src/lib/js-lib.lisp [new file with mode: 0644]
src/lib/js-utils.lisp
src/package.lisp

index 51b86a0..3ddfa1c 100644 (file)
@@ -31,7 +31,8 @@
                                       :components ((:static-file "functional.lisp")
                                                   (:file "js-html")
                                                   (:file "css"    )
-                                                  (:file "js-utils"))
+                                                  (:file "js-utils")
+                                                   (:file "js-lib"))
                                      :depends-on ("compilation-interface")))))
   :depends-on ())
 
diff --git a/src/lib/js-lib.lisp b/src/lib/js-lib.lisp
new file mode 100644 (file)
index 0000000..c9485e2
--- /dev/null
@@ -0,0 +1,15 @@
+(in-package :parenscript)
+
+;;; Script of library functions you can include with your own code to
+;;; provide standard Lisp functionality.
+
+(defparameter *ps-lisp-library*
+  '((defun mapcar (fun &rest as)
+      (let ((result-array (make-array)))
+        (if (= 1 (length as))
+            (dolist (element (aref as 0))
+              (result-array.push (fun element)))
+            (dotimes (i (length (aref as 0)))
+              (let ((args-array (mapcar (lambda (a) (return (aref a i))) as)))
+                (result-array.push (fun.apply fun args-array)))))
+        (return result-array)))))
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
index 639eefd..c37a315 100644 (file)
 
       ;; utils
       #:do-set-timeout
+      #:min
+      #:max
+      #:ceiling
+      #:abs
+      #:sin
+      #:cos
+      #:tan
+      #:acos
+      #:asin
+      #:atan
+      #:exp
+      #:floor
+      #:expt
+      #:round
+      #:random
+      #:oddp
+      #:evenp
+      #:ignore-errors
+      #:length
+      #:null
+      #:@
+
+      ;; libries
+      #:*ps-lisp-library*
+      #:mapcar
       ))
   "All symbols considerred part of the Parenscript language.")