Had some time to play with this today. So here's my two cents worth, if anyone is still watching. Not sure if this is any faster.
(defun insert@ (lst item pos / tmp)
;; Insert item into lst at pos, zero based
(repeat pos
(setq tmp (cons (car lst) tmp)
lst (cdr lst)
)
)
(append (reverse tmp) (list item) lst)
)
(setq alst '(A B C (1 2 3) D E F G))
(length alst) -> 8
(insert@ alst '(X Y Z) 0) -> ((X Y Z) A B C (1 2 3) D E F G)
(insert@ alst '(X Y Z) 3) -> (A B C (X Y Z) (1 2 3) D E F G)
(insert@ alst '(X Y Z) 8) -> (A B C (1 2 3) D E F G (X Y Z))
(insert@ alst '(X Y Z) 10) -> (A B C (1 2 3) D E F G nil nil (X Y Z))
In the last example you can see that the value of the argument 'Pos was larger then the number of positions existing in the argument 'Lst. Hence, the function padded the result with nils in order to put Iitem at 'Pos.
I'm not sure if that's the best way to handle this "position overflow" condition. Perhaps the function should simply return nil under this condition.
Comments anyone?
Regards,
Steve Doman