本帖最后由 自贡黄明儒 于 2013-2-26 08:20 编辑

- ;;递归经典用法回眸 自贡黄明儒 2013年2月19日
- ;;[1] n的阶乘
- ;;例如(setq n 4),则返回结果为(* n (w1 (1- n)))的值
- (defun w1 (n)
- (if (= n 0)
- 1
- (* n (w1 (1- n)))
- )
- )
- ;;[2] 字条串列表=>字符串 By Lee Mac
- ;;(BAtte:lst->str (list "A" "B") ",")返回"A,B"
- (defun BAtte:lst->str (lst del)
- (if (cdr lst)
- (strcat (car lst) del (BAtte:lst->str (cdr lst) del))
- (car lst)
- )
- )
- ;;[3] 字符串=>字条串列表 By Lee Mac
- ;;(BAtte:str->lst "A,B" ",")返回("A" "B")
- (defun BAtte:str->lst (str del / pos)
- (if (setq pos (vl-string-search del str))
- (cons (substr str 1 pos)
- (BAtte:str->lst (substr str (+ pos 1 (strlen del))) del)
- )
- (list str)
- )
- )
- ;;[4] 自定义max 由yjr111程序改编 自贡黄明儒 2013年2月19日
- ;;示例(max1 '("asd" "dfd" "hgrt"))返回"hgrt";(max1 '(4 7 10 3))返回10
- (defun max1 (lst / A B)
- (if (setq b (cdr lst))
- (progn (setq a (car lst))
- (setq b (max1 b))
- (cond ((> a b) a)
- (T b)
- )
- )
- (car lst)
- )
- )
- ;;[5] 去除表中相同图元 by Gu_xl
- ;;(vl-sort '(5 2 2 3 3 3 4 5) '<)返回(2 3 4 5)
- (defun gxl-delsame (l)
- (if L
- (cons (car L) (gxl-delsame (vl-remove (car L) (cdr L))))
- )
- )
- ;;[6] 爆破块中块
- ;;(ExplodeBInB (car (entsel)))
- (defun ExplodeBInB (EN / ENAME SS1)
- (command "_.explode" EN)
- (If (setq ss1 (ssget "_p" '((0 . "INSERT"))))
- (Repeat (SsLength SS1)
- (Setq ENAME (SsName SS1 0))
- (SsDel ENAME SS1)
- (ExplodeBInB ENAME)
- )
- )
- )
|