Ok, I'm not normally the one to come asking for help without slaving over it myself... but this has been driving me up the wall.
I am in the process of making my
TabSort.lsp program compatible with a multi-tab selection and have accomplished everything except for the "
up" and "
down" buttons - which have kept me puzzled all day...
If I focus on the "
Up" button, I can just reverse the process for the "
Down" button...
So here is my dilemma:
I need to pass the function an
index list of items to be moved, and for it to return a
new list with those items moved.
The items at the specific indexes need to be moved "
up" a position [to the
(n-1)th position], but there are some exceptions.
I'll provide a few examples:
Say we have a list:
(setq lst '[color=red](0 1 2 3 4 5)[/color])
(list_up '(2 3) lst) [color=navy]Returns:[/color] (0 [color=red]2 3[/color] 1 4 5)
(list_up '(0 3) lst) [color=navy] Returns:[/color] ([color=red]0[/color] 1 [color=red]3[/color] 2 4 5)
(list_up '(0 1 4 5) lst) [color=navy]Returns:[/color] ([color=red]0 1[/color] 2 [color=red]4 5[/color] 3)
As you can see from the examples, the elements need to move up, except when they are consecutively in positions 0 1 2 3... etc
I have had a stab at it, but I really am getting nowhere and its driving me
c r a z y :ugly:
Here is my attempt:
(defun List_up (ilst rlst)
(defun Remove_nth (i lst / j)
(setq j -1)
(vl-remove-if
(function
(lambda (x)
(eq i (setq j (1+ j))))) lst))
(defun Put_j_at_i (j i lst / r lst)
(setq r (nth j lst) i (1+ i))
(mapcar
(function
(lambda (x y)
(cond ((zerop (setq i (1- i))) r)
((minusp i) y) (x))))
lst (cons nil (remove_nth j lst))))
(foreach x ilst
(setq rlst
(if (zerop x) rlst
(cond ((vl-position (1- x) ilst) rlst)
(Put_j_at_i x (1- x) rlst)))))
rlst)
Any help/advice is appreciated,
Lee