(if (null nn)
(setq rtn listent)
(progn
(if (< nn (length listent))
(progn
(setq nn2 (- (length listent) nn))
(setq key (nth nn listent))
(setq list1(cdr (member key (reverse listent))))
(while (> (length list1) nn)
(setq list1 (cdr list1))
)
(setq list1 (reverse list1))
(setq list2(member key listent))
(while (>= (length list2) nn2)
(setq list2 (cdr list2))
)
(setq num (- (length list1) 1) )
(setq listaa list2)
(repeat (length list1)
(setq listaa (cons (nth num list1) listaa))
(setq num (- num 1))
)
(setq rtn listaa)
)
(setq rtn listent)
)
)
)
rtn
)
(defun ins_n_lst (atom1 nn lst openif / lst1 lst2 rtn)
;;在lst的nn处后插入atom1
;;假如atom1是一个表,用openif来控制是否打开openif = t or nil
(if (>= nn (length lst))
(progn
(setq lst1 lst)
(setq lst2 '())
)
(progn
(setq lst1 (Fnlst nn lst))
(setq lst2 (Bnlst (- (length lst) nn) lst))
)
)
(if (and openif (= (type atom1) 'LIST) )
(progn
(setq rtn (joinlst atom1 lst2))
(setq rtn (joinlst lst1 rtn))
)
(progn
(setq rtn (cons atom1 lst2))
(setq rtn (joinlst lst1 rtn))
)
)
rtn
)
(defun Fnlst(nn lst / n rtn)
;;;取lst的前nn部分
(setq rtn '())
(if (>= nn (length lst))
(setq rtn lst)
(progn
(setq n 0)
(repeat nn
(setq rtn (cons (nth n lst) rtn))
(setq n (1+ n))
)
(setq rtn (reverse rtn))
)
)
rtn
)
(defun Bnlst (nn lst / rtn)
;;;取lst的后nn部分
(setq lst (reverse lst))
(setq rtn (fnlst nn lst))
(setq rtn (reverse rtn))
rtn
)
(defun Joinlst(lst1 lst2 / nrtn)
;;;联接两个表
(setq lst1 (reverse lst1))
(setq rtn lst2)
(setq n 0)
(repeat (length lst1)
(setq rtn ( cons (nth n lst1) rtn ))
(setq n (1+ n))
)
rtn
) 这是我需要的函数,很实用 对表的处理相当有用,学习了 对表的处理相当有用,学习了:L 本帖最后由 77077 于 2015-4-16 20:26 编辑
代码太长了
;表的第N位置插入新表
;|
(setq lst '(1 2 3 4 5 6 7 8 9))
(list-insertitem '("A" "B" "C") 5 lst)=>(1 2 3 4 5 "A" "B" "C" 6 7 8 9)
(list-insertitem '("A" "B" "C") 1 lst)=>(1 "A" "B" "C" 2 3 4 5 6 7 8 9)
(list-insertitem '("A" "B" "C") 15 lst)=>(1 2 3 4 5 6 7 8 9 "A" "B" "C")
|;
(defun list-insertitem (item nnn lst / lout )
(if (< nnn (length lst))
(progn
(setq lout '())
(repeat nnn
(setq lout (cons (car lst) lout) lst (cdr lst))
)
(append (reverse lout) (append item lst))
)
(append lst item)
)
)
楼上的很强大啊!多谢二位分享了! 很好,多谢二位大侠了!!!! 楼主的函数呢? 好多大神来学习了
页:
[1]