From: Slobodan Blazeski on
I have an one dimensional array with fill pointer, and I want to
insert element in it by index.
Currently I'm using this:

(defun insert-nth (i array val)
(progn
(vector-push val array)
(replace array array :start1 (1+ i) :start2 i)
(setf (aref array i) val)
array))

; foo (0 1 2 3)
>(insert-nth 2 foo 4)
#(0 1 4 23 44)

Is there more idiomatic way like the one suggested for deleting
element by its index http://bit.ly/dA3eD3
?

Slobodan
From: Pascal J. Bourguignon on
Slobodan Blazeski <slobodan.blazeski(a)gmail.com> writes:

> I have an one dimensional array with fill pointer, and I want to
> insert element in it by index.
> Currently I'm using this:
>
> (defun insert-nth (i array val)
> (progn
> (vector-push val array)

I would use (incf (fill-pointer array)) here to avoid one memory read
and one memory write, but it shouldn't make a lot of difference given
the following:

> (replace array array :start1 (1+ i) :start2 i)
> (setf (aref array i) val)
> array))
>
> ; foo (0 1 2 3)
>>(insert-nth 2 foo 4)
> #(0 1 4 23 44)
>
> Is there more idiomatic way like the one suggested for deleting
> element by its index http://bit.ly/dA3eD3
> ?
>
> Slobodan

--
__Pascal Bourguignon__