diff options
author | David Thompson <dthompson2@worcester.edu> | 2020-09-29 11:30:11 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2020-09-29 11:30:11 -0400 |
commit | 3bb57f3982c8f73c5a5a44d2b3ac03e8d7913bf8 (patch) | |
tree | e69433189a4151027345573219ab9e2a05a9e103 | |
parent | 95be967547cdaad47e2eb1e375d7dda68aa34659 (diff) |
array-list: Add array-list-fold procedure.
-rw-r--r-- | chickadee/array-list.scm | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/chickadee/array-list.scm b/chickadee/array-list.scm index 3b11ec1..5e2174c 100644 --- a/chickadee/array-list.scm +++ b/chickadee/array-list.scm @@ -30,7 +30,8 @@ array-list-push! array-list-pop! array-list-clear! - array-list-for-each)) + array-list-for-each + array-list-fold)) (define-record-type <array-list> (%make-array-list vector size) @@ -116,3 +117,12 @@ (when (< i size) (proc i (vector-ref vec i)) (loop (1+ i)))))) + +(define (array-list-fold proc init array-list) + (let ((size (array-list-size array-list)) + (vec (array-list-vector array-list))) + (let loop ((i 0) + (prev init)) + (if (< i size) + (loop (1+ i) (proc i (vector-ref vec i) prev)) + prev)))) |