Lecture overview -- Keyboard shortcut: 'u'  Previous page: The equivalent meaning of <kbd>let</kbd> -- Keyboard shortcut: 'p'  Next page: The <kbd>let*</kbd> name binding 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 4 : 42
Functional Programming in Scheme
Name binding, Recursion, Iteration, and Continuations
Examples with let name binding

Expression

Value after rendering

(let ((anchor "An anchor text")
      (url "http://www.cs.auc.dk")
      (tag a)
     )
  (tag 'href url anchor))
An anchor text
(let ((f b))
  (let ((f em)
        (g f))
    (p (f "Text 1") (g "Text 2"))))

Text 1 Text 2

(let ((phrase-elements 
        (list em strong dfn code samp
              kbd var cite abbr acronym))
     )
  (ul 
   (map 
    (lambda (f) (li (f "foo")))
    phrase-elements)))
  • foo
  • foo
  • foo
  • foo
  • foo
  • foo
  • foo
  • foo
  • foo
  • foo

Examples of namebindings with let. The first example shows that all constituents of a function call can be bound to local names - in the example both the function object referred to by a, and two string parameters. The second example illustrates that alternative names, aliases, can be defined for a couple of functions. Notice in particular that g is bound to b (the bold face function), not em (the emphasis function). This can also be seen in the second column. The third example is a little more advanced, and it can first be understood fully on the ground of the material in the lecture about higher-order functions. We bind the name phrase-elements to a list of ten functions. Via mapping, we apply each function to foo, and we present the results in an ul list.