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 @@
(setf idx (1+ idx))))
(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))
(do* ((i (if init -1 0) (1+ i))
(acc (if init init (elt list 0)) (func acc (elt list i))))
(do* ((i (if (= (length arguments) 3) -1 0)
(1+ i))
(acc (if (= (length arguments) 3) init (elt list 0))
(func acc (elt list i))))
((>= i (1- (length list)))))
......@@ -65,3 +67,4 @@
((@ arr :splice :apply) arr
(append (list (length arr) (length other)) other))))
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