Chapter 4

Chapter 4 - Teach Yourself Scheme in Fixnum Days[Go to first previous next page contents index Chapter 4 Conditionals Like all languages Scheme

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
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) file:///C|/Documents%20and%20Settings/Linda%20Grauer. ..otes/Teach%20Yourself%20Scheme/t-y-scheme-Z-H-6.html (1 of 4) [2/6/2008 11:39:24 AM]
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This test prep was uploaded on 02/06/2008 for the course CS 4536 taught by Professor Fisler during the Winter '08 term at WPI.

Page1 / 4

Chapter 4 - Teach Yourself Scheme in Fixnum Days[Go to first previous next page contents index Chapter 4 Conditionals Like all languages Scheme

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online