HCoop
/
clinton
/
parenscript.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
083b7f8
)
Added 'reduce' function to runtime lib.
author
Vladimir Sedach
<vsedach@gmail.com>
Sun, 8 Feb 2009 08:13:11 +0000
(
01:13
-0700)
committer
Vladimir Sedach
<vsedach@gmail.com>
Sun, 8 Feb 2009 08:13:11 +0000
(
01:13
-0700)
runtime/ps-runtime-lib.lisp
patch
|
blob
|
blame
|
history
diff --git
a/runtime/ps-runtime-lib.lisp
b/runtime/ps-runtime-lib.lisp
index
0823f7a
..
3c61c70
100644
(file)
--- a/
runtime/ps-runtime-lib.lisp
+++ b/
runtime/ps-runtime-lib.lisp
@@
-72,4
+72,11
@@
then append it as a member."
(unless (member el arr-to-sub)
(setf (aref result idx) el)
(setf idx (1+ idx))))
- (return result)))))
+ (return result)))
+
+ (defun reduce (func list &optional init) ;; the use of init here is actually a bit broken wrt null
+ (let* ((acc))
+ (do* ((i (if init -1 0) (1+ i))
+ (acc (if init init (elt list 0)) (func acc (elt list i))))
+ ((>= i (1- (length list)))))
+ (return acc)))))