I have three patches to suggest for parenscript. Two seem relatively
minor to me, but a third modifies random to be more like CL:RANDOM. It
gives us the following:
CL-USER> (ps:ps (random 2.3))
"2.3 * Math.random();"
CL-USER> (ps:ps (random 2))
"Math.floor(2 * Math.random());" ;; as in ps's original random
But I expect the following to be perhaps a bit more contentious...
CL-USER> (ps:ps (random (+ 2 2)))
"var max1 = 2 + 2;
var val2 = max1 * Math.random();
if (Math.floor(max1) === max1) {
Math.floor(val2);
} else {
val2;
};"
Hope I haven't tried too hard to be like CL here? I hope my patches are
useful and would like them to be considered for inclusion.
Thanks,
Yong.
From cfdeeef4283c4e6d2f571bef3e815a5cf986aae0 Mon Sep 17 00:00:00 2001
From: Chew Theam Yong <[email protected]>
Date: Tue, 11 May 2010 21:38:29 +1200
Subject: [PATCH] Renamed function argument 'as' to 'arrs' for consistency, just like in
nconc. (PS ok, it's really because 'as' is an Actionscript 3 keyword).
---
runtime/ps-runtime-lib.lisp | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/runtime/ps-runtime-lib.lisp b/runtime/ps-runtime-lib.lisp
index 0c37cfb..89c9dbb 100644
--- a/runtime/ps-runtime-lib.lisp
+++ b/runtime/ps-runtime-lib.lisp
@@ -5,13 +5,13 @@
(defparameter *ps-lisp-library*
'(progn
- (defun mapcar (fun &rest as)
+ (defun mapcar (fun &rest arrs)
(let ((result-array (make-array)))
- (if (= 1 (length as))
- (dolist (element (aref as 0))
+ (if (= 1 (length arrs))
+ (dolist (element (aref arrs 0))
((@ result-array push) (fun element)))
- (dotimes (i (length (aref as 0)))
- (let ((args-array (mapcar (lambda (a) (return (aref a i))) as)))
+ (dotimes (i (length (aref arrs 0)))
+ (let ((args-array (mapcar (lambda (a) (return (aref a i))) arrs)))
((@ result-array push) ((@ fun apply) fun args-array)))))
(return result-array)))
--
1.6.0.4
From 936972d4c7f31a16fdddfd31eb824e867c30bf08 Mon Sep 17 00:00:00 2001
From: Chew Theam Yong <[email protected]>
Date: Tue, 11 May 2010 21:38:55 +1200
Subject: [PATCH] Changed gensym to ps-gensym for consistency/replicable gensyms.
---
src/lib/ps-loop.lisp | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/lib/ps-loop.lisp b/src/lib/ps-loop.lisp
index dbc45b5..a0195bb 100644
--- a/src/lib/ps-loop.lisp
+++ b/src/lib/ps-loop.lisp
@@ -191,10 +191,10 @@
(push (list var nil expr expr test tag) (iterations state)))))
(defun while-clause (state)
- (while-or-until :while (gensym) state))
+ (while-or-until :while (ps-gensym) state))
(defun until-clause (state)
- (while-or-until :until (gensym) state)))
+ (while-or-until :until (ps-gensym) state)))
(defun body-clause (term state)
(case term
--
1.6.0.4
From 5ef9fa76a723cddfa63bb7f5fd025f1c0ba9f82d Mon Sep 17 00:00:00 2001
From: Chew Theam Yong <[email protected]>
Date: Tue, 11 May 2010 21:39:16 +1200
Subject: [PATCH] Make RANDOM more Common-Lispy by adding support for float input arguments.
---
src/macros.lisp | 17 ++++++++++++++---
1 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/src/macros.lisp b/src/macros.lisp
index 8aa9a63..314e215 100644
--- a/src/macros.lisp
+++ b/src/macros.lisp
@@ -53,9 +53,20 @@
(and (numberp base) (= base 10) `(* (log ,n) (@ *math *log10e*)))
`(/ (log ,n) (log ,base))))
(sqrt (n) `((@ *math sqrt) ,n))
- (random (&optional upto) (if upto
- `(floor (* ,upto ((@ *math random))))
- '((@ *math random)))))
+ (random (&optional upto)
+ (cond ((null upto)
+ '((@ *math random)))
+ ((floatp upto)
+ `(* ,upto ((@ *math random))))
+ ((integerp upto)
+ `(floor (* ,upto ((@ *math random)))))
+ (t ;; an expression
+ (with-ps-gensyms (max val)
+ `(let* ((,max ,upto)
+ (,val (* ,max ((@ *math random)))))
+ (if (= (floor ,max) ,max) ;; integerp
+ (floor ,val)
+ ,val)))))))
(define-ps-symbol-macro pi (getprop *math '*pi*))
--
1.6.0.4
_______________________________________________
parenscript-devel mailing list
[email protected]
http://common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel