vector.scm 414 B

1234567891011121314151617
  1. (define (vector->list v)
  2. (let ((l (vector-length v)))
  3. (let loop ((i 0))
  4. (if (= i l)
  5. '()
  6. (cons (vector-ref v i)
  7. (loop (+ i 1)))))))
  8. (define (list->vector l)
  9. (let ((len (length l)))
  10. (let ((v (make-vector len #f)))
  11. (let loop ((i 0) (l l))
  12. (if (= i len)
  13. v
  14. (begin (vector-set! v i (car l))
  15. (loop (+ i 1) (cdr l))))))))