summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2020-09-29 11:30:11 -0400
committerDavid Thompson <dthompson2@worcester.edu>2020-09-29 11:30:11 -0400
commit3bb57f3982c8f73c5a5a44d2b3ac03e8d7913bf8 (patch)
treee69433189a4151027345573219ab9e2a05a9e103
parent95be967547cdaad47e2eb1e375d7dda68aa34659 (diff)
array-list: Add array-list-fold procedure.
-rw-r--r--chickadee/array-list.scm12
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))))