Lee Mac 发表于 2022-7-5 15:42:11

 
芬德兰奇接受零!美好的
 
简化版-不支持nil(最低测试)


(defun foo (n l)
(eval
   (cons 'cond
(append (mapcar '(lambda (x)
                     (list (cons '<= (list 200. n x)) ;(<= 200. n x)
                           (list 'princ (strcat "i am more than 200 and less than " (vl-princ-to-string x)))
                           )
                     )
                  l
                  )
          '((t
             (if
              (< n 200.)
              (princ "\nI am less than 200.")
              (princ "i am not any of the above..")
              )
             )
          )
          )
)
   )
)

(foo (setq dist1 (- dist1 40)) '(400 600 800 1000 1500 2000 2500 3000) )

ronjonp 发表于 2022-7-5 15:45:05

谢谢大家的帮助。
“cond”现在工作正常
 
我对命令“copym”感到困惑,它可以在命令行上工作,但不能在lisp中工作。
有谁知道为什么会这样,因为这个命令完全符合我的目的。
 
(setq d (- dist1 40))
(or (vl-some '(lambda ( x ) (if (< d x) (princ (strcat "\nI am less than " (rtos x))))) '(200 400 600 800 1000))
   (princ "\nI am greater than 1000.")
)

hanhphuc 发表于 2022-7-5 15:49:00

 
1.IMO,你的情况不需要条件,建议
2.(c:copym);express tool的命令不是常见命令吗
3.(dtr 0)=0
 

(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.")
   )

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

Lee Mac 发表于 2022-7-5 15:52:17

Tharwat 发表于 2022-7-5 15:55:12

Another.

(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.")   )

hanhphuc 发表于 2022-7-5 15:58:17

 
findrangeaccepts nil ! nice
 
simplified version - it does not support nil (minimal tested)

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

Tharwat 发表于 2022-7-5 16:02:43

 
Thank you.

Grrr 发表于 2022-7-5 16:04:32

 
Thanks han,
you can provide arguments like

'( ((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)"))

TunzaGibbo 发表于 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.
 

(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 (> Dist21)      (< Dist2 200))(setq Copies 1))      ((and (> Dist2200)(< Dist2 400))(setq Copies 2))   ((and (> Dist2200)(< Dist2 600))(setq Copies 3))   ((and (> Dist2200)(< Dist2 800))(setq Copies 4))   ((and (> Dist2200)(< Dist2 1000)) (setq Copies 5))   ((and (> Dist2200)(< 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 "")

hanhphuc 发表于 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
 

(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 0.0 20.)   P4          (polar P3 0.0 Dist2)   Copies (if (< 0.0 Dist2 1200.)          (1+ (fix (/ Dist2 200.)))          )    )       (setq hole1a (entmakex (list '(0 . "CIRCLE") (cons 10 (polar P1 (+ ang1 0.) 20.0)) '(40 . 3.2))))      )          (vl-cmdf "-array" "_non" hole1a "" "r" 1 Copies (/ (distance p3 p4) Copies)) ; like this??      ;;;   (acet-copym-divide (ssadd hole1a) p3 p4 copies) ;express tool (alert "\nLimits! 0 < x < 1200 !!") ) (princ) )
 
p/s: im not familiar with 'command' call , "_non" instead of (setvar 'osmode 0) not tested. i prefer vla-arrayrectangular
页: 1 [2]
查看完整版本: “如果”