明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1301|回复: 5

谁有替换表中第N个元素的函数,谢谢

[复制链接]
发表于 2009-6-8 11:33:00 | 显示全部楼层 |阅读模式
提示: 作者被禁止或删除 内容自动屏蔽
"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2009-6-8 12:30:00 | 显示全部楼层
(defun lt:list-subst-n (lst n new / it lst2 le)
  (setq it (nth n lst) lst2 (reverse lst) le (- (length lst) n 1))
  (while (/= (length (setq lst2 (cdr (member it lst2)))) n))
  (while (/= (length (setq lst (cdr (member it lst)))) le))
  (append (reverse lst2) (list new) lst)
)
;;test
(lt:list-subst-n '("A" "B" "C" "D" "E" "F" "G") 4 "NEW")->("A" "B" "C" "D" "NEW" "F" "G")
 楼主| 发表于 2009-6-8 13:54:00 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2009-6-8 14:19:00 | 显示全部楼层
  1. (defun hao-lst-repl (lst pos new)
  2.   (setq pos (1+ pos))
  3.   (mapcar
  4.     '(lambda (x)
  5.        (if (zerop (setq pos (1- pos)))
  6.   new
  7.   x
  8.        )
  9.      )
  10.     lst
  11.   )
  12. )
  13. (defun t2-lst-repl (lst pos new / i)
  14.   (setq i -1)
  15.   (mapcar
  16.     '(lambda (x)
  17.        (if (= (setq i (1+ i))
  18.        pos
  19.     )
  20.   new
  21.   x
  22.        )
  23.      )
  24.     lst
  25.   )
  26. )
发表于 2009-6-8 17:27:00 | 显示全部楼层

回复:(TANER)[CODE](defun hao-lst-repl (lst pos ...

看似简单,但对于长的表不快
 楼主| 发表于 2009-6-8 17:59:00 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-10-1 05:30 , Processed in 0.196422 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表