alanjt 发表于 2022-7-6 07:13:11

 
(= "AJR" (strcase (getvar "loginname")))

BlackBox 发表于 2022-7-6 07:16:16

 
; error: too many arguments: (IF (= "ajr" (GETVAR "loginname")) (PROGN (INITGET 1 "Yes No") (SETQ ANSR (GETKWORD "\nIs this a UT Job? :"))) (COND ((EQ ANSR "No")) ((EQ ANSR "Yes"))) (PRINC "\n Are you sure you should be using this?\n Access Denied."))
_$
 
 
 
我可能会这样做:
 

(defun c:FOO (/ option)
(if (= "AJR" (strcase (getvar 'loginname)))
   (progn
   (initget "Yes No")
   (cond
       ((or (setq option
                      (getkword "\nIs this a \"UT\" Job <Yes>: ")
               )
            (setq option "Yes")
      )
      ;;<-- user entered yes, or right clicked / hit enter
       )
       ((= option "No")
      ;;<-- user entered no
       )
   )
   )
   (prompt "\n** Access Denied **")
)
(princ)
)
将始终返回T。
当然,只有当该部分有多行时才需要这种方式(progn)。
 
(or (setq option
          (getkword "\nIs this a \"UT\" Job <Yes>: ")
   )
   (setq option "Yes")
)

alanjt 发表于 2022-7-6 07:18:55

 
太有趣了。。。我从另一个例程的IF语句(然后有条件地执行,允许Yes/Nil或No)中删除了它。。。不太清楚为什么我把它嵌套在COND语句中。
 
剔除的原始片段:
(initget 0 "Yes No")
(if (eq (setq option (getkword "\nIs this a \"UT\" Job <Yes>: ")) "No")
(progn
;; blah blah for NO
)

(progn
;; blah blah for nil or YES
)
)
 
 
再说一次,你是对的。我需要从yes条件中删除最后两个调用。
 
 
不,我不知道是这样的。我想这就是我在学习LISP的同时学习一些过时的教程所得到的。感谢您的澄清

BlackBox 发表于 2022-7-6 07:20:53

顺便说一句,FWIW,我喜欢cond语句,因为你可以这样做:
 

;; snip
   (initget "Yes No")
   (if (or (setq option
                     (getkword "\nAre bowties cool <Yes>: ")
                )
             (setq option "Yes")
         )
       (cond
         ((= option "Yes")
          ;;<-- user entered yes, or right clicked / hit enter
         )
         ((= option "No")
          ;;<-- user entered no, fire them
         )
       )
   )
;; snip

AJRight 发表于 2022-7-6 07:24:39

AJRight 发表于 2022-7-6 07:28:29

It works! Thanks guys for all your help. Now I just need to build a list of user initials that are allowed that can be updated externally from this routine. Perhaps I can make another routine that this routine we have been working on will load and check the passed value. Here's the working code
 

(setvar "CMDECHO" 0)(setvar "BINDTYPE" 0)(defun c:lolwat (/ X blk ansr )(if (= "TLD" (strcase (getvar 'loginname)))   (progn   (initget "Yes No yes no YES NO")   (cond       ((or (setq option                      (getkword "\nIs this a \"UT\" Job : ")               );;; set q            (setq option "NO")                ;;

neophoible 发表于 2022-7-6 07:30:37

Are you sure it works the way you intend?It looks to me like you will always fulfill the OR condition for "NO" (and never get to "YES"), becauseis always non-nil. 
Also, even if you had your parentheses different for the or, it looks like you would be doing the following in either case, YES or NO:
 
And is there some language reason that you don't just use the much simpler "Yes No" version in the initget like was shown above?It would cover the entire gambit of full & partial Yes & No entries, but always return only "Yes", "No" or nil.

AJRight 发表于 2022-7-6 07:35:48

 
I haven't messed with it today but I should take that setq out and just put another conditional statement like
; snip((= option "NO" ) ; do something);snip
 
 
Again, you're right. I need to remove those last two calls from the yes condition.
 
 
No, I had no idea that was the case. I guess that is what I get for following somewhat dated tutorials while learning LISP. Thanks for clarifying

neophoible 发表于 2022-7-6 07:38:04

BTW, FWIW, I like cond statements because you can do things like this:
 

(cond   ( (not (member (strcase (getvar 'loginname)) list_of_valid_names))      (prompt "\n Are you sure you should be using this?\n **Access Denied **")   )                               ; handle invalid user first   ( (initget “Yes No”) )    ; always returns nil   ( (= “Yes” (getkword "\nIs this a \"UT\" Job : "))                                 ; Do YES stuff    )                               ; check hard value first   (T                              ; only thing left is “No”/nil, both=NO                                 ; Do NO stuff   ) )
页: 1 [2]
查看完整版本: 限制对跑步的访问