1 Evaluation Model
2 Syntax Model
3 Core Syntactic Forms
4 Core Datatypes
5 Structures
6 Classes and Objects
7 Units
8 Contracts
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
Index
On this page:
when
unless

contents

 index

← prev  up  next →

 

3.11 Guarded Evaluation: when and unless

Effects If...: when and unless in A Guide to 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

 

contents

 index

← prev  up  next →