乐筑天下

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

[编程交流] “如果”

[复制链接]

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 15:42:11 | 显示全部楼层
 
芬德兰奇接受零!美好的
 
简化版-不支持nil(最低测试)
  1. (defun foo (n l)
  2. (eval
  3.    (cons 'cond
  4.   (append (mapcar '(lambda (x)
  5.                      (list (cons '<= (list 200. n x)) [color="green"];(<= 200. n x) [/color]
  6.                            (list 'princ (strcat "i am more than 200 and less than " (vl-princ-to-string x)))
  7.                            )
  8.                      )
  9.                   l
  10.                   )
  11.           '((t
  12.              (if
  13.               (< n 200.)
  14.               (princ "\nI am less than 200.")
  15.               (princ "i am not any of the above..")
  16.               )
  17.              )
  18.             )
  19.           )
  20.   )
  21.    )
  22. )
  23. ([color="blue"]foo[/color] (setq dist1 (- dist1 40)) '(400 600 800 1000 1500 2000 2500 3000) )
回复

使用道具 举报

58

主题

3353

帖子

33

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1761
发表于 2022-7-5 15:45:05 | 显示全部楼层
谢谢大家的帮助。
“cond”现在工作正常
 
我对命令“copym”感到困惑,它可以在命令行上工作,但不能在lisp中工作。
有谁知道为什么会这样,因为这个命令完全符合我的目的。
 
  1. (setq d (- dist1 40))
  2. (or (vl-some '(lambda ( x ) (if (< d x) (princ (strcat "\nI am less than " (rtos x))))) '(200 400 600 800 1000))
  3.    (princ "\nI am greater than 1000.")
  4. )
回复

使用道具 举报

5

主题

956

帖子

963

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 15:49:00 | 显示全部楼层
 
1.IMO,你的情况不需要条件,建议
2.(c:copym);express tool的命令不是常见命令吗
3.(dtr 0)=0
 
  1. (or (and (setq p (vl-position t (mapcar '(lambda (x) (< (- dist1 40) x)) (setq l '(200 400 600 800 1000)))))
  2.           (princ (strcat "\nI am less than " (itoa (nth p l))))
  3.           )
  4.      (princ "\nI am greater than 1000.")
  5.      )

 
备注:我不熟悉“命令”调用,“\u non”而不是(setvar'osmode 0)未测试。我更喜欢vla arrayrectangular
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 15:52:17 | 显示全部楼层
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

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

铜币
358
发表于 2022-7-5 15:55:12 | 显示全部楼层
Another.
  1. (or (and (setq p (vl-position t (mapcar '(lambda (x) (< (- dist1 40) x)) (setq l '(200 400 600 800 1000)))))          (princ (strcat "\nI am less than " (itoa (nth p l))))          )     (princ "\nI am greater than 1000.")     )
回复

使用道具 举报

5

主题

956

帖子

963

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 15:58:17 | 显示全部楼层
 
findrange  accepts nil ! nice
 
simplified version - it does not support nil (minimal tested)

[code](cadar (vl-remove-if-not '(lambda (x) (= 1 (vl-position 0 (vl-sort-i (cons n (car x)) '
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

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

铜币
358
发表于 2022-7-5 16:02:43 | 显示全部楼层
 
Thank you.
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

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

铜币
325
发表于 2022-7-5 16:04:32 | 显示全部楼层
 
Thanks han,
you can provide arguments like
  1. '( ((nil 30) "I'm below or equal to thirty")  ((40 nil) "I'm above or equal to forty")  (nil "I'm something else, in this case between 30-40 (exclusive)"))
回复

使用道具 举报

26

主题

81

帖子

55

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
130
发表于 2022-7-5 16:08:37 | 显示全部楼层
Thank you all for the help.
The "cond" now works fine
 
I'm puzzled with the command "copym" It works on the command line but not in lisp.
Does anyone know why this may be because this command suits my purpose perfectly.
 
  1. (defun c:ww (/ P1 P2 P3 P4 Ang1 Dist1 Dist2 hole1a hole1b Copies)    (savevartoold)     (setq P1 (getpoint "\n Select a Point  : "))     (setq P2 (getpoint P1 "\n Select a Point  : "))     (setq Dist1 (distance P1 P2))     (setq Dist2 (- Dist1 40.0))     (setq Ang1 (angle P1 P2))     (setq P3 (polar P1 (dtr 0) 20))     (setq P4 (polar P3 (dtr 0) Dist2))   (cond     ((and (> Dist2  1)      (< Dist2 200))  (setq Copies 1))      ((and (> Dist2  200)  (< Dist2 400))  (setq Copies 2))     ((and (> Dist2  200)  (< Dist2 600))  (setq Copies 3))     ((and (> Dist2  200)  (< Dist2 800))  (setq Copies 4))     ((and (> Dist2  200)  (< Dist2 1000)) (setq Copies 5))     ((and (> Dist2  200)  (< Dist2 1200)) (setq Copies 6))   )                     (setvar "osmode" 0)     (command "_.circle" (polar P1 (+ ang1 (dtr 0)) 20.0) "D" 3.2 "" )      (setq hole1a (entlast))     (command "copym" hole1a "" P3 "d" P4 Copies "")
回复

使用道具 举报

5

主题

956

帖子

963

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 16:10:57 | 显示全部楼层
 
1. IMO, in your case no needs cond , suggestions colored
2. (c:copym) ; is a command of express tool not a common command
3. (dtr 0) = 0
 
  1. (defun c:ww (/ P1 P2 P3 P4 Ang1 Dist1 Dist2 hole1a hole1b Copies)(savevartoold) (if (and (setq P1 (getpoint "\n Select a Point  : "))      (setq P2 (getpoint P1 "\n Select a Point  : "))      (setq Dist1  (distance P1 P2)   Dist2  (- Dist1 40.0)   Ang1          (angle P1 P2)   P3          (polar P1 [color="red"]0.0[/color] 20.)   P4          (polar P3 [color="red"]0.0[/color] Dist2)   [b]Copies[/b] [color="red"](if (< 0.0 Dist2 1200.)            (1+ (fix (/ Dist2 200.)))            ) [/color]   )       [color="red"](setq hole1a (entmakex (list '(0 . "CIRCLE") (cons 10 (polar P1 (+ ang1 0.) 20.0)) '(40 . 3.2))))[/color]      )[color="red"]          (vl-cmdf "-array" "_non" hole1a "" "r" 1 Copies (/ (distance p3 p4) Copies)) [/color][color="green"]; like this??[/color]      [color="green"];;;     (acet-copym-divide (ssadd hole1a) p3 p4 copies) ;express tool [/color] (alert [color="purple"]"\nLimits! 0 < x < 1200 !!"[/color]) ) (princ) )
 
p/s: im not familiar with 'command' call , "_non" instead of (setvar 'osmode 0) not tested. i prefer vla-arrayrectangular
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-14 23:32 , Processed in 1.573724 second(s), 70 queries .

© 2020-2025 乐筑天下

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