yanguangfei 发表于 2012-12-15 00:31:00

移除表中重复项(适用于任何表)【能否在简化】

;测试(vl-removes '((2162.48 1434.06 0.0) (2433.05 1163.76 0.0) (2433.05 1163.76 0.0) (2433.05 1163.76 0.0)))
;测试(vl-removes (list 1 2 1 2 3))
;;;移除表中重复项

(defun vl-removes (lst)
    (foreachX lst
      (setq lst (append (vl-remove X lst) (list X)))
    )
)

能否在简化或其他方法写更简单

Gu_xl 发表于 2012-12-15 11:36:12

(defun delsame (l)
(if l
   (cons (car l) (delsame (vl-remove (car l) (cdr l)))
)
)

yanguangfei 发表于 2012-12-15 12:59:02

Gu_xl 发表于 2012-12-15 11:36 static/image/common/back.gif
(defun delsame (l)
(if l
   (cons (car l) (delsame (vl-remove (car l) (cdr l)))


好像没这个函数的说明啊delsame

ll_j 发表于 2012-12-15 13:01:55

yanguangfei 发表于 2012-12-15 12:59 static/image/common/back.gif
好像没这个函数的说明啊delsame

这是函数调用自身完成循环。有点绕。

wowan1314 发表于 2012-12-15 13:10:50

我的简单易懂
(defun T1 (Lst / LstNew)
(SETQ LstNew '())
(foreach _LstItem Lst
    (if (not (member _LstItem LstNew))
      (setq LstNew (CONS _LstItem LstNew))
    )
)
LstNew
)

cable2004 发表于 2012-12-15 13:19:23

坐标点位就不好用!

Gu_xl 发表于 2012-12-15 13:34:07

本帖最后由 Gu_xl 于 2012-12-15 13:34 编辑

cable2004 发表于 2012-12-15 13:19 static/image/common/back.gif
坐标点位就不好用!

   (defun DumpPt (l fuzz )
(if l
    (cons (car l)
          (DumpPt
            (vl-remove-if '(lambda (x) (equal (car l) x fuzz)) (cdr l))
            fuzz
          )
    )
)
)

cable2004 发表于 2012-12-15 14:20:00

拜读G的强大,套内套子程序不好理解。不过比我的简单!

x_s_s_1 发表于 2012-12-15 15:37:32

递归啊,我什么时候可以明白你的心

zdqwy19 发表于 2012-12-15 16:09:45

如果处理数据量过大的化,过于简化和递归会让你的内存快速耗尽。
页: [1]
查看完整版本: 移除表中重复项(适用于任何表)【能否在简化】