Skip to content

Commit

Permalink
util: remove for-each-index procedure
Browse files Browse the repository at this point in the history
Now unused.
  • Loading branch information
nmeum committed Aug 17, 2024
1 parent 9f1ab37 commit 912c137
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 56 deletions.
21 changes: 0 additions & 21 deletions lib/util.scm
Original file line number Diff line number Diff line change
Expand Up @@ -154,27 +154,6 @@
(define (ascii-printable? integer)
(and (>= integer #x20) (<= integer #x7e)))

;;> Call `proc` for each element in `lst` starting at the `start` index.
;;> For each element, the procedure `proc` is passed both the index as
;;> well as the element value itself as a procedure parameter.

(define (for-each-index proc cont-proc lst start)
(define (%for-each-index vector index rem)
(unless (zero? rem)
(proc index (vector-ref vector index))
(%for-each-index
vector
(modulo (cont-proc index) (vector-length vector))
(dec rem))))

(unless (null? lst)
(let* ((vec (list->vector lst))
(len (vector-length vec)))
(if (and (>= start 0)
(< start len))
(%for-each-index vec start len)
(error "invalid start index")))))

;;> Return path to home directory of current user.
;;> This procedure emits an error if the environment variable `HOME` is unset.

Expand Down
4 changes: 2 additions & 2 deletions lib/util.sld
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
(chicken io))

(export inc dec id alist-values fprintln println empty-string?
pad-string string->human-readable for-each-index path-join
user-home count-bytes lines->port port->lines)
pad-string string->human-readable path-join user-home
count-bytes lines->port port->lines)

(include "util.scm"))
33 changes: 0 additions & 33 deletions tests/util.scm
Original file line number Diff line number Diff line change
@@ -1,38 +1,5 @@
(import (edward util))

(test-group "for-each-index"
(test "increment index from start"
'((0 . "foo") (1 . "bar") (2 . "baz"))
(let ((ret '()))
(for-each-index
(lambda (idx elem)
(set! ret (append ret (list (cons idx elem)))))
inc '("foo" "bar" "baz") 0)
ret))

(test "decrement index from middle"
'((1 . "bar") (0 . "foo") (2 . "baz"))
(let ((ret '()))
(for-each-index
(lambda (idx elem)
(set! ret (append ret (list (cons idx elem)))))
dec '("foo" "bar" "baz") 1)
ret))

(test "zero list"
'()
(let ((ret '()))
(for-each-index
(lambda (idx elem)
(set! ret idx))
inc '() 0)
ret))

(test-error "invalid start index"
(for-each-index
(lambda (idx elem) elem)
inc '(1 2 3) 3)))

(test-group "ports->lines"
(test "multiple"
'(("foo" "bar" "baz") . 12)
Expand Down

0 comments on commit 912c137

Please sign in to comment.