3.16 Guarded Evaluation: when and unless
按条件作用:when 与 unless in Racket 指南 introduces when and unless.
语法
(when test-expr body ...+)
Evaluates test-expr. If the result is #f, then
the result of the when expression is
#<void>. Otherwise, the bodys are evaluated, and the
last body is in tail position with respect to the
when form.
Examples:
> (when (positive? -5) (display "hi"))
> (when (positive? 5) (display "hi") (display " there")) hi there
语法
(unless test-expr body ...+)
Examples: