Skip to content

Commit

Permalink
Merge pull request #581 from jpellegrini/srfi-43
Browse files Browse the repository at this point in the history
Fix behavior of `vector-copy` in SRFI 43
  • Loading branch information
egallesio authored Aug 30, 2023
2 parents 14c15e0 + c94a735 commit 3d40322
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/srfi/43.stk
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
vector?
vector-empty?
vector=

;;; Selectors
vector-ref
vector-length
Expand All @@ -38,7 +38,7 @@
vector-index-right vector-skip-right
vector-binary-search
vector-any vector-every

;;; Mutators
vector-set!
vector-swap!
Expand Down Expand Up @@ -120,7 +120,7 @@
length)
callee)))))
loop))

;; Constructors

(from-scheme make-vector)
Expand All @@ -129,9 +129,9 @@
(from-133 vector-unfold-right)

(define r7rs-vector-copy (symbol-value 'vector-copy scheme))
(define (vector-copy v :optional (start 0) stop (fill #f fill?))
(define (vector-copy v :optional (start 0) stop (fill #void fill?))
(let ((stop (if stop stop (vector-length v))))
(if (not fill?)
(if (<= stop (vector-length v))
(r7rs-vector-copy v start stop)
(let ((w (make-vector (- stop start))))
(dotimes (i (- (vector-length v) start))
Expand All @@ -140,7 +140,6 @@
(vector-set! w (+ i (- (vector-length v) start)) fill))
w))))



(from-133 vector-reverse-copy)
(from-scheme vector-append)
Expand Down
5 changes: 5 additions & 0 deletions tests/srfis/43.stk
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,11 @@
(reverse-list->vector '(0 1 2 3) 2 1))
))

(test "vector-copy, no fill"
#(-1 -1 -1 -1 -1 #void #void #void)
(let ((v (make-vector 5 -1)))
(vector-copy v 0 8)))

) ;; run-srfi-43-test

) ;; module
Expand Down

0 comments on commit 3d40322

Please sign in to comment.