Lecture overview -- Keyboard shortcut: 'u'  Previous page: Conditional expressions [Section] -- Keyboard shortcut: 'p'  Next page: Examples with <kbd>if</kbd> -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home    Lecture 3 - Page 10 : 42
Functional Programming in Scheme
Name binding, Recursion, Iteration, and Continuations
Conditional expressions

if and cond are special forms which evaluate their expressions according to the value of one or more boolean selectors

if and cond are not control structures when applied in the functional paradigm

Control structures belong to the imperative paradigm. In the functional paradigm, if and cond are used in conditional expressions. By that we mean expressions, of which subexpressions are selected for evaluation based on one or or more boolean selectors.


(if bool-expr expr1 expr2)


(cond (bool-expr1 expr1)
      ...
      (bool-exprk exprk)
      (else exprk+1))

  • if evaluates expr1 if bool-expr is true, and expr2 if bool-expr is false

  • cond evaluates the first expression expri whose guarding bool-expri is true. If bool-expr1, ..., bool-exprkare all false, the value of cond becomes the value of exprk+1

Go to exerciseHTML Header functions