我会试着用英语输入我从示例代码中读到的内容,如果我错了,你会告诉我,好吗?然后,我想我的怀疑会更清楚。
- (cond ;if any of the following conditions is true, here's what will happen
- ((= s "Y") 1) ;if s equals "Y", then it'll return 1
- ((= s "y") 1) ;if s equals "y", then it'll return 1
- ((= s "N") 0) ;if s equals "N", then it'll return 1
- ((= s "n") 0) ;if s equals "n", then it'll return 1
- (t nil); if none of the above is true I'll test if "true" is true (it'll be) and return "nil"
- )
您可以看到,在提供的示例中,第二个括号用于测试条件。当我读到这篇文章时,我可以让一个全局变量为true或nil,然后写下如下内容:
- (cond
- (*givenvar* returnVal) ;if the variable is a valid value, return "returnVal"
- (t defaulReturnVal) ;otherwise, return "defaulReturnVal"
- )
现在,对于您的代码,如果条件为true,则没有设置值,并且在默认条件下没有测试(即使在“true”为true时进行测试)。它更简洁,看起来更聪明。我想了解它是如何工作的。 |