Verified Commit 963e71b9 authored by Vladimir Sedach's avatar Vladimir Sedach
Browse files

Fix initial value handling of ps-runtime-lib's REDUCE

parent b9040086
...@@ -52,10 +52,12 @@ ...@@ -52,10 +52,12 @@
(setf idx (1+ idx)))) (setf idx (1+ idx))))
result)) result))
(defun reduce (func list &optional init) ;; the use of init here is actually a bit broken wrt null (defun reduce (func list &optional init)
(let* ((acc)) (let* ((acc))
(do* ((i (if init -1 0) (1+ i)) (do* ((i (if (= (length arguments) 3) -1 0)
(acc (if init init (elt list 0)) (func acc (elt list i)))) (1+ i))
(acc (if (= (length arguments) 3) init (elt list 0))
(func acc (elt list i))))
((>= i (1- (length list))))) ((>= i (1- (length list)))))
acc)) acc))
...@@ -65,3 +67,4 @@ ...@@ -65,3 +67,4 @@
((@ arr :splice :apply) arr ((@ arr :splice :apply) arr
(append (list (length arr) (length other)) other)))) (append (list (length arr) (length other)) other))))
arr))) arr)))
v
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment