when与if唯一的不同点在于when的代码主体可以是多句:

when的相反是unless:它接受同样的阐述,但主体仅在测试表达式返回假时,才对主体求值。

CL-USER> (when (oddp that)
       (format t "Hmm,that's odd.")
       (+ that 1))
      
Hmm,that's odd.
6
CL-USER> (if (oddp that)
         (progn
           (format t "Hmm,that's odd.")
           (+ that 1)))
Hmm,that's odd.
6

CL-USER> (setf x 4)
4
CL-USER> x
4
CL-USER> (unless (oddp x)
        (format t "Hmm,x is even."))

Hmm,x is even.
NIL
CL-USER>

 

相关文章:

  • 2022-01-13
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2021-05-27
  • 2022-02-25
  • 2021-06-06
  • 2021-07-16
猜你喜欢
  • 2022-12-23
  • 2021-10-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-19
相关资源
相似解决方案