Lecture overview -- Keyboard shortcut: 'u'  Previous page: Examples with <kbd>if</kbd> -- Keyboard shortcut: 'p'  Next page: Example with cond: <kbd>american-time</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 12 : 42
Functional Programming in Scheme
Name binding, Recursion, Iteration, and Continuations
Example with cond: leap-year?

(define (leap-year? y)
  (cond ((= (modulo y 400) 0) #t)
        ((= (modulo y 100) 0) #f)
        ((= (modulo y 4) 0) #t)
        (else #f)))

The function leap-year?. The function returns whether a year y is a leap year. For clarity we have programmed the function with a conditional. In this case, we can express the leap year condition as a simple boolean expression using and and or. We refer to this variation below, and we leave it to you to decide which version you prefer.

y:/Kurt/Files/courses/prog3/prog3-03/sources/notes/includes/leap-year-or.scmThe function leap year programmed without a conditional.

To ease comparison, the original version is shown below the new version.

Go to elucidatorA complete program for handling of time
A complete program for handling of time