;; -*-theme-*-

;; Copyright (C) 2015, 2021  Tommi Höynälänmaa
;; Distributed under GNU Lesser General Public License version 3,
;; see file doc/LGPL-3.

(define-body (examples sequence-vector-impl)


  (define-static-param-virtual-method sequence-ref (%element)
    (((l (:mutable-vector %element)) (i <integer>))
     %element pure)
    (mutable-vector-ref l i))


  (define-static-param-virtual-method sequence-length (%element)
    (((l (:mutable-vector %element)))
     <integer> pure)
    (mutable-vector-length l))


  (define-static-param-virtual-method sequence-map (%element)
    (((proc (:procedure (%element) %element pure))
      (v (:mutable-vector %element)))
     (:mutable-vector %element) pure)
    (let* ((len (mutable-vector-length v))
	   (result (make-mutable-vector (:maybe %element) len null)))
      (do ((i <integer> 0 (+ i 1)))
	  ((>= i len) (cast-mutable-vector %element result))
	(let ((element (vector-ref v i)))
	  (mutable-vector-set!
	   result i
	   (proc element)))))))
