(defun sort ( l1 l2 )
(
(lambda ( l3 )
(mapcar
(function
(lambda ( a )
(mapcar
(function
(lambda ( b ) (nth b a))
)
l3
)
)
)
l2
)
)
(mapcar
(function
(lambda ( x )
(vl-position x '("ONE" "TWO" "THREE" "FOUR" "FIVE" "SIX"))
)
)
l1
)
)
)
(sort
'("TWO" "ONE" "THREE" "FOUR" "SIX" "FIVE")
'(
("item1a" "item2a" "item3a" "item4a" "item5a" "item6a")
("item1b" "item2b" "item3b" "item4b" "item5b" "item6b")
)
)
Returns:
(
("item2a" "item1a" "item3a" "item4a" "item6a" "item5a")
("item2b" "item1b" "item3b" "item4b" "item6b" "item5b")
)
Thanks Lee! I just can't believe you can create something like this so fast.
I haven't it working stable yet because in my data the length of the lists seems to differ and also the content of the reference list is not always the same as l1. Right now the code will crash on that but I'll try to find out how to make it handle inconsistent data.
What is the purpose of "function" in your code? Does it make it run faster?
Command: !ll1m
("two" "three" "one")
Command: !ll1
("one" "two" "three")
Command: !ll2
(("a1" "a2" "a3") ("b1" "b2" "b3"))
Command: (sort ll1 ll2 ll1m)
(("a2" "a3" "a1") ("b2" "b3" "b1"))
("one" "two" "three" "four")
("two" "one" "four")
(f c (setq d (apply (function mapcar) (cons (function list) (cons a b))))
(f c (apply (function mapcar) (cons (function list) (cons a b))))
Command: (sort '("one" "two" "three")
(_> '(
('(_> ("a1" "a2" "a3")
('(_> ("b1" "b2" "b3")
('(_> ("c1" "c2" "c3")
('(_> ("d1" "d2" "d3")
('(_> )
(_> '("three" "one" "two")
(_> )
(("a3" "a1" "a2") ("b3" "b1" "b2") ("c3" "c1" "c2") ("d3" "d1" "d2"))
Amazing code.
What if the reference list can beCode: [Select]("one" "two" "three" "four")
And the sortlistCode: [Select]("two" "one" "four")
?
And am I right thatCode: [Select](f c (setq d (apply (function mapcar) (cons (function list) (cons a b))))
Can also beCode: [Select](f c (apply (function mapcar) (cons (function list) (cons a b))))
in the recursive one? (I cannot find the recursion though, must be me)
_$ (Rearrange-Nested '("One" "Two" "Three") '(("a1" "a2" "a3") ("b1" "b2" "b3")) '("Three" "One" "Two"))
(("a3" "a1" "a2") ("b3" "b1" "b2"))
recursion way:Code - Auto/Visual Lisp: [Select]
) ) )Code - Auto/Visual Lisp: [Select]
(sort '("one" "two" "three") '(("a1" "a2" "a3") ("b1" "b2" "b3")) '("two" "three" "one"))