Chapter 4 - Teach Yourself Scheme in Fixnum Days[Go to...

Info icon This preview shows pages 1–3. Sign up to view the full content.

Teach Yourself Scheme in Fixnum Days [Go to first , previous , next page; contents ; index ] Chapter 4 Conditionals Like all languages, Scheme provides conditionals . The basic form is the if : (if test-expression then-branch else-branch) If test-expression evaluates to true (ie, any value other than #f ), the ``then'' branch is evaluated. If not, the ``else'' branch is evaluated. The ``else'' branch is optional. (define p 80) (if (> p 70) 'safe 'unsafe) => safe (if (< p 90) 'low-pressure) ;no ``else'' branch => low-pressure Scheme provides some other conditional forms for convenience. They can all be defined as macros (chap 8 ) that expand into if -expressions. 4.1 when and unless when and unless are convenient conditionals to use when only one branch (the ``then'' or the ``else'' branch) of the basic conditional is needed. (when (< (pressure tube) 60) (open-valve tube) (attach floor-pump tube) (1 of 4) [2/6/2008 11:39:24 AM]
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.