From: Slobodan Blazeski on 3 Apr 2010 03:51 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 3 Apr 2010 04:59 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__
|
Pages: 1 Prev: Cheap wholesale brand coat Next: What should I do to interacting lisp with pyqt? |