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 4ConditionalsLike all languages, Scheme provides conditionals. The basic form is the if:(if test-expressionthen-branchelse-branch)If test-expressionevaluates 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 whenand unlesswhenand unlessare 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]
has intentionally blurred sections.
Sign up to view the full version.