Lee Mac 发表于 2022-7-6 10:13:58

这是一种更通用的格式:
 
(((25736.0 8902.08) (28627.0 8902.08) (22425.0 8902.08) (25316.0 8902.08))
((28627.0 11781.1) (25736.0 11781.1) (25316.0 11781.1) (22425.0 11781.1))
((25736.0 12201.1) (28627.0 12201.1) (22425.0 12201.1) (25316.0 12201.1))
((28627.0 15080.1) (25736.0 15080.1) (25316.0 15080.1) (22425.0 15080.1)))

(defun test ( l / sub )

(defun sub ( l )
   (if l
   (cons
       (cons (car l)
         (vl-remove-if-not
         (function
             (lambda ( x ) (equal (cadar l) (cadr x)))
         )
         (cdr l)
         )
       )
       (sub
         (vl-remove-if
         (function
             (lambda ( x ) (equal (cadar l) (cadr x)))
         )
         (cdr l)
         )
       )
   )
   )
)

(vl-sort (sub l) '(lambda ( a b ) (< (cadar a) (cadar b))))
)

yajis_narif 发表于 2022-7-6 10:14:09

非常感谢你

Lee Mac 发表于 2022-7-6 10:21:23

yajis_narif 发表于 2022-7-6 10:25:41

thank you so much it worked i called the function leeMac (l / sub) lol

Lee Mac 发表于 2022-7-6 10:26:52

This is a more generic format:
 

(defun test ( l ) (vl-sort   (LM:GroupByFoo l   (lambda ( a b ) (equal (cadr a) (cadr b)))   )'(lambda ( a b ) (< (cadar a) (cadar b))) ))(defun LM:GroupByFoo ( lst foo ) (if lst   (cons   (cons (car lst)       (vl-remove-if-not '(lambda ( x ) (foo (car lst) x)) (cdr lst))   )   (LM:GroupByFoo (vl-remove-if '(lambda ( x ) (foo (car lst) x)) (cdr lst)) foo)   ) ))
_$ (test '((1 2) (3 2) (5 2) (2 4) (3 5) (5 3) (2 3) (6 3) (9 4) (2 4) (7 5) (2 5)))( ((1 2) (3 2) (5 2))((5 3) (2 3) (6 3)) ((2 4) (9 4) (2 4))((3 5) (7 5) (2 5)))

yajis_narif 发表于 2022-7-6 10:33:51

thank you so much
页: 1 [2]
查看完整版本: 从最小值开始组织列表