3.16 Guarded Evaluation: when and unless (original) (raw)
top contents [← prev](begin.html "backward to "3.15 Sequencing: begin, begin0, and begin-for-syntax"") [up](syntax.html "up to "3 Syntactic Forms"") [next →](set%5F.html "forward to "3.17 Assignment: set! and set!-values"")
3.16 Guarded Evaluation: when and unless🔗ℹ
Effects If...: when and unless in The Racket Guide introduces when and unless.
syntax
(when test-expr body ...+)
Evaluates test-expr. If the result is #f, then the result of the when expression is#. Otherwise, the bodys are evaluated, and the last body is in tail position with respect to thewhen form.
Examples:
> (when (positive? -5) (display "hi")) > (when (positive? 5) (display "hi") (display " there")) hi there
syntax
(unless test-expr body ...+)
Equivalent to (when (not test-expr) body ...+).
Examples:
> (unless (positive? 5) (display "hi")) > (unless (positive? -5) (display "hi") (display " there")) hi there
top contents [← prev](begin.html "backward to "3.15 Sequencing: begin, begin0, and begin-for-syntax"") [up](syntax.html "up to "3 Syntactic Forms"") [next →](set%5F.html "forward to "3.17 Assignment: set! and set!-values"")