Skip to content

Commit

Permalink
Fixes vector-cumulate to have same signature as fold
Browse files Browse the repository at this point in the history
Cumulation is really just accumulating the stepwise results of fold into
a single collection (in this case, a vector). It makes more sense to
keep the argument order this way (with knil first) as it matches the API
for fold / vector-fold, which means one can switch between them as they
choose.

After talking about this with John Cowan, he also mentioned that the
previous argument order (e.g. proc vec knil) is an error and it should
have been (vector-cumulate proc knil vec) from the beginning. This
should correct the issue in both the code and the main SRFI document.
  • Loading branch information
ThatGeoGuy committed Sep 2, 2016
1 parent 81bce0c commit 3f465fd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion srfi-133.html
Expand Up @@ -1464,7 +1464,7 @@ <h2><a name="Iteration">5.4. Iteration</a></h2>
<dl>
<dt class="proc-spec">
<a name="vector-cumulate">
(vector-cumulate <i>f vec knil</i>)
(vector-cumulate <i>f knil vec</i>)
-&gt; vector
</a>
</dt>
Expand Down
4 changes: 2 additions & 2 deletions vectors/vectors-impl.scm
Expand Up @@ -917,13 +917,13 @@
vector-count)
(cons vec vectors)))))

;;; (VECTOR-CUMULATE <f> <vector> <knil>)
;;; (VECTOR-CUMULATE <f> <knil> <vector>)
;;; -> vector
;;; Returns a <new>ly allocated vector <new> with the same length as
;;; <vec>. Each element <i> of <new> is set to the result of invoking <f> on
;;; <new>[i-1] and <vec>[i], except that for the first call on <f>, the first
;;; argument is <knil>. The <new> vector is returned.
(define (vector-cumulate f vec knil)
(define (vector-cumulate f knil vec)
(let* ((len (vector-length vec))
(result (make-vector len)))
(let loop ((i 0) (left knil))
Expand Down

0 comments on commit 3f465fd

Please sign in to comment.