Lecture overview -- Keyboard shortcut: 'u'  Previous page: The <kbd>let*</kbd> name binding construct -- Keyboard shortcut: 'p'  Next page: The <kbd>letrec</kbd> namebinding construct -- 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 6 : 42
Functional Programming in Scheme
Name binding, Recursion, Iteration, and Continuations
An example with let*

(define (how-many-days-hours-minutes-seconds n)
  (let* ((days     (quotient n seconds-in-a-day))
         (n-rest-1 (modulo n seconds-in-a-day))
         (hours    (quotient n-rest-1 seconds-in-an-hour))
         (n-rest-2 (modulo n-rest-1 seconds-in-an-hour))
         (minutes  (quotient n-rest-2 60))
         (seconds  (modulo n-rest-2 60))
    (list days hours minutes seconds)))

A typical example using sequential name binding. The task is to calculate the number of days, hours, minutes, and seconds given a number of seconds. We subsequently calculate a number of quotients and rest. While doing so we find the desired results. In this example we would not be able to use let; let* is essential because a given calculation depends on previous name bindings. The full example, including the definition of the constants, can be found in the accompanying elucidative program. The function is part of the LAML time library in lib/time.scm of the LAML distribution. The time library is used whenever we need to display time information, such as 'the time of generation' of some HTML files.

Go to elucidatorA set of functions for handling of time.
A set of functions for handling of time. The set of functions elucidated here is only a subset of the LAML time library.