明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 719|回复: 5

[提问] 表内数据替换的问题!

[复制链接]
发表于 2015-12-15 16:48:42 | 显示全部楼层 |阅读模式


这是我运行一段代码时的监视窗口,里面的DIC1是一个二维数据。
DIC1=(("command3" 1) ("command7" 1) ("command6" 1) ("command5" 1) ("command4" 1) ("command2" 1) ("command" 1))
NEWLIST1=("command3" 2)
OLDLIST1=("command3" 1)


现在,我想将DIC1表里的("command3" 1)替换成("command3" 2)。于是我用下面语句:
(subst newlist1 oldlist1 dic1),发现完全替换不了,感觉此语句完全没有反应。

请问我要完成上述的替换行为,需要怎么做啊?求指点。。。


该贴已经同步到 羊渔蛋的微博

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2015-12-15 18:27:11 | 显示全部楼层
本帖最后由 xiaolong1487 于 2015-12-15 18:32 编辑

原文 http://www.mjtd.com/function/info-129-423.html
subst-n 置换表中指定位置的元素
2006-12-31 09:28:16   来源:晓东空间   评论:0 点击:2990
函数:
subst-n
功能:
置换表中指定位置的元素
函数代码:
;; 用 a 置換表 l 中 第 n 个元素(可以是子表);
(defun subst-n (n a l)
  (cond
    ((numberp n)
     (if (zerop n)
       (append (list a) (cdr l))
       (cons (car l) (subst-n (1- n) a (cdr l)))
     )
    )
    ((listp n)
     (cond
       ((equal (length n) 1)
(if (zerop (car n))
  (append (list a) (cdr l))
  (cons (car l) (subst-n (1- (car n)) a (cdr l)))
)
       )
       ((> (length n) 1)
(if (zerop (car n))
  (cons (subst-n (cdr n) a (car l)) (cdr l))
  (cons (car l)
(subst-n (append (list (1- (car n))) (cdr n)) a (cdr l))
  )
)
       )
     )
    )
  )
)
语法:
(subst-n n a l)
参数:
n:如果为两个元素的表,则代表第几个子表的第几项,项目均以0开始计数。如果为数字,则代表替换的表中的元素位置。
a:要替换为的子表。
l:要进行替换的表。
返回值:
替换后的表
示例:
(SUBST-N '(0 2) '(99 22) '((1 2 3) 2 55 99 66)) ;替换第一个子表第三项
返回:((1 2 (99 22)) 2 55 99 66)
(SUBST-N '(2 1) '(99) '(1 2 (55) 99 66))   ;替换第三个子表第二项
返回:(1 2 (55 ((99))) 99 66)
(SUBST-N 2.0 '(99) '(1 2 55 99 66)) ;替换第三个原素
返回:(1 2 (99) 99 66)









发表于 2015-12-15 18:29:49 | 显示全部楼层
(subst-n '(0 1) 2 '(("command3" 1) ("command7" 1) ("command6" 1) ("command5" 1) ("command4" 1) ("command2" 1) ))
-> (("command3" 2) ("command7" 1) ("command6" 1) ("command5" 1) ("command4" 1) ("command2" 1))
发表于 2015-12-15 18:30:14 | 显示全部楼层
表写成 '("command3" 2)或(list "command3" 2)
 楼主| 发表于 2015-12-16 13:58:56 | 显示全部楼层
xiaolong1487 发表于 2015-12-15 18:27
原文 http://www.mjtd.com/function/info-129-423.html
subst-n 置换表中指定位置的元素
2006-12-31 09:2 ...

谢谢你的代码,虽然我的提问后来我自己发现的了问题所在,也已经解决的问题,但你发的这个代码也很有用途,谢谢!
发表于 2015-12-16 16:13:13 | 显示全部楼层
推荐我的签名中的《认识自定义函数》,或许对你能有帮助。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-5-21 01:06 , Processed in 0.194153 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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