Skip to content

Commit

Permalink
define setf for elt
Browse files Browse the repository at this point in the history
  • Loading branch information
VitoVan authored and davazp committed May 18, 2023
1 parent 735cce9 commit 25e0341
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/sequence.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,16 @@
(error "The index ~D is too large for ~A of length ~D." index 'vector length))
(aref sequence index)))))

(define-setf-expander elt (sequence index)
(let ((g!sequence (gensym))
(g!index (gensym))
(g!value (gensym)))
(values (list g!sequence g!index)
(list sequence index)
(list g!value)
`(jscl::aset ,g!sequence ,g!index ,g!value)
`(aref ,g!sequence ,g!index))))

(defun zero-args-reduce (function initial-value initial-value-p)
(if initial-value-p
(funcall function initial-value)
Expand Down
7 changes: 7 additions & 0 deletions tests/seq.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -311,5 +311,12 @@
(list t t t t t)))


;;; SETF with ELT
;;; TODO: Rewrite this test when EQUALP exists and works on vectors
;;; https://github.com/jscl-project/jscl/issues/479
(test (equal '(42 0 0)
(let ((vec (vector 0 0 0)))
(setf (elt vec 0) 42)
(jscl::vector-to-list vec))))

;;; EOF

0 comments on commit 25e0341

Please sign in to comment.