tomchenri的个人空间 https://blog.eetop.cn/1768370 [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

以nil开头的非实体属性列表(a disembodied property list)

已有 425 次阅读| 2022-9-21 16:38 |系统分类:芯片设计


a disembodied property list:只能使用 -> 操作符,只能用 ' ,不能用list

Example: 

myDPL= '(nil rePart 2 imPart 10) 
foreach(Part reverse(myDPL->?)
   println(list("Part:" Part, "Value:" get(myDPL Part) ))
)

Output: 

("Part:" rePart "Value:" 2)
("Part:" imPart "Value:" 10)
(rePart imPart)

Another approach could be like;

foreach( Part reverse(myDPL->?)
    val = evalstring(strcat("myDPL->" sprintf(nil "%s" Part) ))
   printf("Part: %L, Value: %L\n" Part val )
);foreach

  => Part: rePart, Value: 2
  => Part: imPart, Value: 10
  => (rePart imPart)


hand1='(nil name "Albert" card1 '(nil suit "clubs" value "ace") card2 '(nil suit "diamond" value "king"))

hand2=copy(hand1),copy这个非实体属性列表,然后给hand2赋值之后,依然相互链接相互关联。比如:

  hand2->name="George"
  hand2->card1->suit="hearts"
  hand2->card1->value="jack"
  hand2->card2->suit="spades"
  hand2->card2->value="9"

hand1的值随着hand2的改变而改变!


用下面这个函数hand2=CCSdeepCopy(hand1),即可解决!

procedure(CCSdeepCopy(l1)
  foreach(mapcar elem l1
    if(listp(elem) then
      CCSdeepCopy(elem)
    else
      elem
    )
  )
)




点赞

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 5

    总排名
  • 4

    关注
  • 64

    粉丝
  • 9

    好友
  • 159

    获赞
  • 21

    评论
  • 294

    访问数
关闭

站长推荐 上一条 /2 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-4-24 08:39 , Processed in 0.013717 second(s), 7 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部