You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you want to add this we should probably make it return the same type of sequence it was passed, rather than always returning a list. class-of seems to work although I'm not 100% sure it works for all sequence types or is the correct way to do it. type-of doesn't work as then with (remove-nth 1 #(0 1 2 3)) I get the error that the length (3) doesn't match the type (simple-vector 4)
(defun remove-nth (n seq)
"Remove element with index N from SEQ."
(concatenate (class-of seq)
(subseq seq 0 n)
(subseq seq (1+ n))))
The text was updated successfully, but these errors were encountered:
Looks interesting but it's SBCL only. SBCL defines implementation for list and vector and otherwise errors unimplemented. concatenate (class-of seq) works portably for list and vector, including subtypes like '(vector double-float). I am not sure of any libraries that implement custom sbcl sequence types to test with but I think they would work also as concatenate will end up calling (make-sequence (class-of seq) ...
Actually, now that I think about it, this could be defined in terms of splice-seq already, although splice-seq doesn't support extensible sequences (yet).
For advent of code this year I used the following utility function:
It seems this is a fairly common utility function:
If you want to add this we should probably make it return the same type of sequence it was passed, rather than always returning a list.
class-of
seems to work although I'm not 100% sure it works for all sequence types or is the correct way to do it.type-of
doesn't work as then with(remove-nth 1 #(0 1 2 3))
I get the error that the length (3) doesn't match the type(simple-vector 4)
The text was updated successfully, but these errors were encountered: