qq229918602 发表于 2012-5-28 21:56:53

initget的用法

本帖最后由 qq229918602 于 2012-5-28 21:59 编辑

(initget 1 "1.1 0.7 0.55 0.4")
(setq ldhd (getkword "the lcd's thickness is: "))

请问怎么输入1时还是有效的?不是控制了只能输入"1.1 0.7 0.55 0.4“么?

万分感谢。

caoyin 发表于 2012-5-28 22:23:50

只要输入不造成歧义。假如关键字里面有1.2,输入1就不行了

qq229918602 发表于 2012-5-28 22:28:59

caoyin 发表于 2012-5-28 22:23 static/image/common/back.gif
只要输入不造成歧义。假如关键字里面有1.2,输入1就不行了

但是我就是想控制输入这几个数字。因为是一个规格来的。怪不得输入0.5也是有效,请问版主有无好的解决方法??谢谢

caoyin 发表于 2012-5-28 23:57:32

(while (not K)
(setq K (getstring "\nthe lcd's thickness is: "))
(or (member K '("1.1" "0.7" "0.55" "0.4"))
      (setq K nil)
      (princ "\n**无效的输入**")
)
)

qq229918602 发表于 2012-5-29 19:32:11

caoyin 发表于 2012-5-28 23:57 static/image/common/back.gif
(while (not K)
(setq K (getstring "\nthe lcd's thickness is: "))
(or (member K '("1.1" "0.7" " ...

感谢版主,我的解决方法。
(setq lst '(1.1 0.7 0.55 0.4))
(while
    (not
      (member (setq
                ldhd (getreal "\nthe lcd's thickness is: ")
              )
              Lst
      )
    )
)

caoyin 发表于 2012-5-29 19:36:51

看似差不多,但你的在少数的情况下可能行不通,因为实数存在精度的问题

qq229918602 发表于 2012-5-29 20:51:19

caoyin 发表于 2012-5-29 19:36 static/image/common/back.gif
看似差不多,但你的在少数的情况下可能行不通,因为实数存在精度的问题

感谢版主。。能举例说一下什么情况下的实数精度问题行不通呢?
页: [1]
查看完整版本: initget的用法