基于标志的程序
你好我想知道旗子驱动的脚本流是什么。我写道:
(defun C:TEST ()
(setq door nil;_T is open, nil is closed
window nil ;_T is open, nil is closed
driving T;_T is driving nil is not
)
(if (not door)
(if (not window)
(if driving
(princ "\nYour door and window are closed, drive saftly!")
(princ "\nYour door and window are closed, you might start driving")
)
(princ "your window is open, and you are not driving, such a waste!")
)
(princ "the car cant start until you close the door")
)
(princ)
)
现在,我最好不要在门开着的时候开车,但如果用户选择我必须自费开车怎么办?
谢谢
谢伊
谢谢 对不起,有什么问题? 你可以这样写:
(defun C:TEST ()
(setq door nil;_T is open, nil is closed
window nil ;_T is open, nil is closed
driving T;_T is driving nil is not
)
(if door
(if window
(if driving
(princ "\nStop it right now, you #$@*")
(princ "\nPut your belt!Don't forget the door!!")
)
(if driving
(princ "\nSami, one day you'll die!")
(princ "\nClose the door and start your engine!!!")
)
)
(if window
(if driving
(princ "\nYou know, this car has air conditioning...")
(princ "\nFinaly, we can go! Just close the window, please")
)
(if driving
(princ "\nYour door and window are closed, drive saftly!")
(princ "\nYour door and window are closed, you might start driving")
)
)
)
(princ)
)但每增加一个选项,代码的大小就会翻倍。
这可能是另一种选择:
(defun C:TEST ()
;driving 1
;open door 2
;open window 4
(if
(setq i (getint "\nEnter a number: "))
(if (<= 0 i 7)
(princ
(strcat "\nYour car is "
(if (= 1 (logand i 1)) " " "not ")
"moving. The door is "
(if (= 2 (logand i 2)) "open " "closed ")
"and the window is "
(if (= 4 (logand i 4)) "open!" "closed!")
)
)
)
)
(princ)
)
谢谢
谢伊
页:
[1]