乐筑天下

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

[编程交流] 请帮我理解

[复制链接]

6

主题

44

帖子

38

银币

初来乍到

Rank: 1

铜币
31
发表于 2022-7-6 12:15:49 | 显示全部楼层 |阅读模式
您好,我有一段代码,几年前我请别人给我写的,我甚至不记得我在哪里通过网络与他联系过
 
我知道如何使用它以及一些单独的部件是如何工作的。
 
它列出了多段线的顶点。
 
有人能给我详细解释一下它到底做什么吗?
 
  1. (defun cdrs (key lst / pair rtn)
  2.     (while (setq pair (assoc key lst)) (setq rtn (cons (cdr pair) rtn) lst (cdr (member pair lst)) ) ) (reverse rtn) )

 
谢谢!
回复

使用道具 举报

4

主题

327

帖子

324

银币

初来乍到

Rank: 1

铜币
19
发表于 2022-7-6 12:28:05 | 显示全部楼层
  1. ;;; its a sub-function for the bigger program
  2. ;;; when it is called you need to pass it 2 variables example: (cdrs 10 and the polyline list from the autolisp entget function)
  3. ;;; the variable KEY  is the first item in a dotted pair like (10 100.500 200.600)
  4. ;;; the variable LST is the list of entity information like if you use (entget(entlast))
  5. (defun cdrs (key lst / pair rtn)
  6.   ;_while pair is not nil loop.
  7.      (while (setq pair (assoc key lst)); pair = the first occurrence of the key item in the list
  8.      (setq rtn (cons (cdr pair) rtn);_a list of the items are being made
  9.              lst (cdr (member pair lst));_remaking the list to be passed back on the next loop
  10.              ;;;with out the previous (assoc key lst) so it will get thew next item in the list
  11.        );_setq
  12.      );_while
  13.   (reverse rtn);_flip the list so the fitst item the while loop retrives is now the first in the list
  14. );_defun
  15. ;;; this sub-function can be tested by the following call
  16. ;;; first draw a polyline then make the call
  17. (cdrs 10 (entget(entlast)))
回复

使用道具 举报

6

主题

44

帖子

38

银币

初来乍到

Rank: 1

铜币
31
发表于 2022-7-6 12:47:06 | 显示全部楼层
非常感谢,我要读了
回复

使用道具 举报

6

主题

44

帖子

38

银币

初来乍到

Rank: 1

铜币
31
发表于 2022-7-6 13:03:27 | 显示全部楼层
我仍然不明白循环是如何从一个代码10转到下一个代码10的
 
很抱歉
回复

使用道具 举报

VVA

1

主题

308

帖子

308

银币

初来乍到

Rank: 1

铜币
8
发表于 2022-7-6 13:11:10 | 显示全部楼层
  1. ;;; its a sub-function for the bigger program
  2. ;;; when it is called you need to pass it 2 variables example: (cdrs 10 and the polyline list from the autolisp entget function)
  3. ;;; the variable KEY  is the first item in a dotted pair like (10 100.500 200.600)
  4. ;;; the variable LST is the list of entity information like if you use (entget(entlast))
  5. (defun cdrs (key lst / pair rtn)
  6.   ;_while pair is not nil loop.
  7.      (while (setq pair (assoc key lst)); pair = the first occurrence of the key item in the list
  8.      (setq rtn (cons (cdr pair) rtn);_a list of the items are being made
  9.              lst (cdr                     ;_[color="Red"]2. Cdr find in 1. And save in lst variable
  10.                                             ;_Next pass member find next code 10[/color]
  11.                     (member pair lst) ;[color="Red"]_1. Find first code 10[/color]
  12.                   )
  13. ;_remaking the list to be passed back on the next loop
  14.              ;;;with out the previous (assoc key lst) so it will get thew next item in the list
  15.        );_setq
  16.      );_while
  17.   (reverse rtn);_flip the list so the fitst item the while loop retrives is now the first in the list
  18. );_defun
  19. ;;; this sub-function can be tested by the following call
  20. ;;; first draw a polyline then make the call
  21. (cdrs 10 (entget(entlast)))

此功能的另一个变体
  1. (defun pl-list-massoc (key alist)
  2. (mapcar 'cdr (vl-remove-if-not (function (lambda (x) (= key (car x)))) alist))) ;_ end of defun

使用
  1. (vl-load-com)(pl-list-massoc 10 (entget(car(entsel "\nSelect a polyline:"))))
回复

使用道具 举报

6

主题

44

帖子

38

银币

初来乍到

Rank: 1

铜币
31
发表于 2022-7-6 13:17:57 | 显示全部楼层
好的,非常感谢!我现在能理解了
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-5 05:57 , Processed in 0.758327 second(s), 76 queries .

© 2020-2025 乐筑天下

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