本帖最后由 llsheng_73 于 2018-4-12 12:10 编辑
 - (defun subtotals(lst m ns / myfun a b c);;对lst以子表第m项为关键字进行分类,ns为整数时记录第ns项、为表(2 3)记录表中指定的项、为空或者其它记录关键字以外所有项
- (cond((=(type ns)'LIST)(defun myfun(x)(list(mapcar'(lambda(y)(nth y x))ns))))
- ((=(type ns)'INT)(defun myfun(x)(list(nth ns x))))
- (t(defun myfun(x)(List(vl-remove c x)))))
- (foreach x lst
- (setq a(if(setq c(nth m x)b(assoc c a))
- (subst(append b(myfun x))b a)
- (append a(list(append(list c)(myfun x))))))))
$ (mapcar'(lambda(x)(list(apply'max(cdr x))(car x)))(subtotals (list'(100.0 100.0)'(115.0 100.0)'(115.0 115.0)'(115.022 115.0)'(100.0 120.834)'(130.0 130.0)'(140.0 130.0)'(160.0 155.0)'(190.0 180.0)'(180.0 180.0)'(190.0 190.0)'(200.0 190.0)'(179.559 200.0)'(200.0 200.0)) 1 0))
((115.0 100.0) (115.022 115.0) (100.0 120.834) (140.0 130.0) (160.0 155.0) (190.0 180.0) (200.0 190.0) (200.0 200.0))
用了一个与排序无关的函数,不知道能不能满足楼主的要求
|