1 Language Model
2 Syntactic Forms
3 Datatypes
4 Structures
5 Classes and Objects
6 Units
7 Contracts
8 Pattern Matching
9 Control Flow
10 Concurrency
11 Macros
12 Input and Output
13 Reflection and Security
14 Operating System
15 Memory Management
16 Running PLT Scheme
Bibliography
Index
On this page:
when
unless
Version: 4.0.2

 

2.16 Guarded Evaluation: when and unless

Effects If...: when and unless in Guide: PLT Scheme introduces when and unless.

(when test-expr expr ...)

Evaluates the text-expr. If the result is any value other than #f, the exprs are evaluated, and the results are ignored. No expr 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 expr ...)

Equivalent to (when (not test-expr) expr ...).

Examples:

  > (unless (positive? 5)

      (display "hi"))

  > (unless (positive? -5)

      (display "hi")

      (display " there"))

  hi there