Skip to content

Commit

Permalink
instantiate RandomAccess (Vector :t) :t
Browse files Browse the repository at this point in the history
  • Loading branch information
stylewarning committed Jan 21, 2024
1 parent 875ec68 commit 27574d1
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion library/vector.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
(#:types #:coalton-library/types)
(#:list #:coalton-library/list)
(#:cell #:coalton-library/cell)
(#:iter #:coalton-library/iterator))
(#:iter #:coalton-library/iterator)
(#:ram #:coalton-library/randomaccess))
(:export
#:Vector
#:new
Expand Down Expand Up @@ -286,6 +287,20 @@
:initial-value init
:from-end cl:t))))

(define-instance (ram:RandomAccess (Vector :t) :t)
(define (ram:make n x)
(with-initial-element n x))
(define (ram:length a)
(length a))
(define (ram:readable? _)
True)
(define (ram:writable? _)
True)
(define (ram:unsafe-aref a n)
(index-unsafe n a))
(define (ram:unsafe-set! a n x)
(set! n x a)))

(define-instance (Into (List :a) (Vector :a))
(define (into lst)
(let ((out (with-capacity (list:length lst)))
Expand Down

0 comments on commit 27574d1

Please sign in to comment.