乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 104|回复: 5

[编程交流] Assoc list - questions

[复制链接]

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-5 17:46:30 | 显示全部楼层 |阅读模式
Hi guys,
I was practicing with lists and I have few questions regarding association lists.
So what is the definition of association list?
As far I understand is that each item from the list has its 2 associations (with dotted pair), Example:
  1.         (setq mylistA        '(                ("TAG1" . "VALUE1A")                ("TAG2" . "VALUE2A")                ("TAG3" . "VALUE3A")                ("TAG4" . "VALUE4A")                ("TAG5" . "VALUE5A")                ("TAG6" . "VALUE6A")        ))
But is it possible to create more (than 2) associations for an item like this:
  1. ("TAG1" "VALUE1A" "XVALUE1A")
Or dotted:
  1. ("TAG1" . "VALUE1A" . "XVALUE1A")
With cons function I could achieve this:
  1. (("TAG1" . "VALUE1A") . "XVALUE1A")
I didn't find anything about manipulating association lists - to see what forms it could have (only 2 associations per item or more? /dotted or not?/ ).
The only example for assoc list I could have is with (entget (car (entsel))).
 
The real question is for their usage, I mean is it possible to display items associated with their "tagname", but work with their "associated value", for example this attempt:
  1. ;Match portion(items) from list A to list B(defun C:test (/ mylistA chosenlst mylistB)(setq mylistA        '(                ("TAG1" . "VALUE1A")                ("TAG2" . "VALUE2A")                ("TAG3" . "VALUE3A")                ("TAG4" . "VALUE4A")                ("TAG5" . "VALUE5A")                ("TAG6" . "VALUE6A")        ))(setq chosenlst (LM:FiltListBox "Select items" (mapcar 'car mylistA) t))(setq mylistB        '(                ("TAG1" . "VALUE1B")                ("TAG2" . "VALUE2B")                ("TAG3" . "VALUE3B")                ("TAG4" . "VALUE4B")                ("TAG5" . "VALUE5B")                ("TAG6" . "VALUE6B")        ))(princ "\n**************************************************************************\n")(LM:princl mylistA f)(princ "\n**************************************************************************\n")(LM:princl mylistB f)(princ))
Where I try to apply the values from mylistA to mylistB, from the chosen TAG associations.(its not done because I don't know how)
回复

使用道具 举报

0

主题

301

帖子

301

银币

初来乍到

Rank: 1

铜币
0
发表于 2022-7-5 18:09:13 | 显示全部楼层
grrr,
 
Association list are not necessarily dotted.
 
You can do :
 
  1. (setq mylistA       '(  ("TAG1"  "VALUE1A" "VALUE1B" "VALUE1C" "VALUE1D")         ("TAG2"  "VALUE2A" "VALUE2B" "VALUE2C" "VALUE2D")  ("TAG3"  "VALUE3A" "VALUE3B" "VALUE3C" "VALUE3D")         ("TAG4"  "VALUE4A" "VALUE4B" "VALUE4C" "VALUE4D")  ("TAG5"  "VALUE5A" "VALUE5B" "VALUE5C" "VALUE5D")  ("TAG6"  "VALUE6A" "VALUE6B" "VALUE6C" "VALUE6D") ))(("TAG1" "VALUE1A" "VALUE1B" "VALUE1C" "VALUE1D") ("TAG2" "VALUE2A" "VALUE2B" "VALUE2C" "VALUE2D") ("TAG3" "VALUE3A" "VALUE3B" "VALUE3C" "VALUE3D") ("TAG4" "VALUE4A" "VALUE4B" "VALUE4C" "VALUE4D") ("TAG5" "VALUE5A" "VALUE5B" "VALUE5C" "VALUE5D") ("TAG6" "VALUE6A" "VALUE6B" "VALUE6C" "VALUE6D"))_$ (assoc "TAG3" MYLISTA)("TAG3" "VALUE3A" "VALUE3B" "VALUE3C" "VALUE3D")_$ (nth 3 (assoc "TAG3" mylista))"VALUE3C"_$(cdr (assoc "TAG4" mylista))("VALUE4A" "VALUE4B" "VALUE4C" "VALUE4D")
 
The only restriction is that you search on the first item of each sublist
in the association list.
 
With dotted pair as the name implies you are restricted to 2 items
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-5 18:19:06 | 显示全部楼层
Hi,
 
The first element of any list is considered the KEY that you can find your desired list with, and you can not have two dotted pairs like ("A" . "B" . "C") and that can not be found by Assoc function. But to have these fore-said example in one list without dots it should found the list if the KEY is found of course.
 
READ THIS
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 18:24:07 | 显示全部楼层
You may wish to read this section of my tutorial on Building Association Lists.
 
An important point to note is that dotted pairs are very different to standard lists (linked lists) in AutoLISP in the way in which they are stored in memory. Where every item in a linked list occupies two memory registers (one allocated to the item value, the other storing a pointer to the memory address of the next list item), the two data items represented by a dotted pair are stored in two adjacent memory registers, which is why the (cdr) of a dotted pair yields the associated value, and not the remaining list.
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-5 18:39:06 | 显示全部楼层
Thanks alot guys,
Still I wanted to ask:
  1. (setq alist  '(       ("Item 1" . "Value 1")       ("Item 2" . "Value 2")       ("Item 3" . "Value 3")   ))
Does each item also appears to be a list? I mean, is this a list also? :
  1.         ("Item 2" . "Value 2")
The reason I'm asking is because I have constructed a custom association list like this:
  1. ((entname . ) (entitytype . LWPOLYLINE) (entitylayer . VLD_ТОПЛОИЗОЛАЦИЯ))((entname . ) (entitytype . INSERT) (entitylayer . VLD_ПРОЗОРЦИ) (blockname . VLD_Отвор-За-Дограма))
And I'm trying to display some of the associations in a listbox, and others to use within ssadd.
Still its a mind-blowing idea for me, since I except user to choose "memory registers for each list item" and use other "memory registers".
(Damn, its hard to describe what I'm trying to do - in simplier words: I'm trying to build a simple listbox filter routine)
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-5 18:51:21 | 显示全部楼层
 
Yes it is.
Few tests for you if you would like:
 
  1. _$ (setq alist '(("Item 1" . "Value 1")([color="red"]"Item 2"[/color] . "Value 2")([color="blue"]"Item 3"[/color] . "Value 3")))(("Item 1" . "Value 1") ("Item 2" . "Value 2") ("Item 3" . "Value 3"))_$ (assoc [color="red"]"Item 2"[/color] alist)([color="red"]"Item 2"[/color] . "Value 2")_$ (assoc [color="blue"]"Item 3"[/color] alist)([color="blue"]"Item 3"[/color] . "Value 3")
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-7-6 14:37 , Processed in 0.391005 second(s), 65 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表