乐筑天下

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

[编程交流] 限制对跑步的访问

[复制链接]

54

主题

3755

帖子

3583

银币

后起之秀

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

铜币
438
发表于 2022-7-6 07:13:11 | 显示全部楼层
 
  1. (= "AJR" (strcase (getvar "loginname")))
回复

使用道具 举报

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 2022-7-6 07:16:16 | 显示全部楼层
 
  1. ; error: too many arguments: (IF (= "ajr" (GETVAR "loginname")) (PROGN (INITGET 1 "Yes No") (SETQ ANSR (GETKWORD "\nIs this a UT Job? [Yes/No]:"))) (COND ((EQ ANSR "No")) ((EQ ANSR "Yes"))) (PRINC "\n Are you sure you should be using this?\n Access Denied."))
  2. _$

 
 
 
我可能会这样做:
 
  1. (defun c:FOO (/ option)
  2. (if (= "AJR" (strcase (getvar 'loginname)))
  3.    (progn
  4.      (initget "Yes No")
  5.      (cond
  6.        ((or (setq option
  7.                       (getkword "\nIs this a "UT" Job [Yes/No]<Yes>: ")
  8.                )
  9.             (setq option "Yes")
  10.         )
  11.         ;;<-- user entered yes, or right clicked / hit enter
  12.        )
  13.        ((= option "No")
  14.         ;;<-- user entered no
  15.        )
  16.      )
  17.    )
  18.    (prompt "\n** Access Denied **")
  19. )
  20. (princ)
  21. )
将始终返回T。
当然,只有当该部分有多行时才需要这种方式(progn)。
 
  1. (or (setq option
  2.           (getkword "\nIs this a "UT" Job [Yes/No] <Yes>: ")
  3.    )
  4.    (setq option "Yes")
  5. )
回复

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

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

铜币
438
发表于 2022-7-6 07:18:55 | 显示全部楼层
 
太有趣了。。。我从另一个例程的IF语句(然后有条件地执行,允许Yes/Nil或No)中删除了它。。。不太清楚为什么我把它嵌套在COND语句中。
 
剔除的原始片段:
  1. (initget 0 "Yes No")
  2. (if (eq (setq option (getkword "\nIs this a "UT" Job [Yes/No] <Yes>: ")) "No")
  3. (progn
  4.   ;; blah blah for NO
  5. )
  6. (progn
  7.   ;; blah blah for nil or YES
  8. )
  9. )

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

使用道具 举报

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 2022-7-6 07:20:53 | 显示全部楼层
顺便说一句,FWIW,我喜欢cond语句,因为你可以这样做:
 
  1. ;; snip
  2.      (initget "Yes No")
  3.      (if (or (setq option
  4.                        (getkword "\nAre bowties cool [Yes/No]<Yes>: ")
  5.                 )
  6.              (setq option "Yes")
  7.          )
  8.        (cond
  9.          ((= option "Yes")
  10.           ;;<-- user entered yes, or right clicked / hit enter
  11.          )
  12.          ((= option "No")
  13.           ;;<-- user entered no, fire them
  14.          )
  15.        )
  16.      )
  17. ;; snip
回复

使用道具 举报

2

主题

9

帖子

7

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 07:24:39 | 显示全部楼层
回复

使用道具 举报

2

主题

9

帖子

7

银币

初来乍到

Rank: 1

铜币
10
发表于 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
 

[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 [Yes/No]: ")               );;; set q            (setq option "NO")                ;;
回复

使用道具 举报

2

主题

389

帖子

387

银币

初来乍到

Rank: 1

铜币
10
发表于 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"), because  is 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.
回复

使用道具 举报

2

主题

9

帖子

7

银币

初来乍到

Rank: 1

铜币
10
发表于 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
  1. ; 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
回复

使用道具 举报

2

主题

389

帖子

387

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 07:38:04 | 显示全部楼层
BTW, FWIW, I like cond statements because you can do things like this:
 
  
  1. (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 [Yes/No] : "))                                   ; Do YES stuff    )                               ; check hard value first   (T                              ; only thing left is “No”/nil, both=NO                                   ; Do NO stuff   ) )
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-10 15:53 , Processed in 0.458027 second(s), 68 queries .

© 2020-2025 乐筑天下

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