Lecture overview -- Keyboard shortcut: 'u'  Previous page: Function objects -- Keyboard shortcut: 'p'  Next page: Anonymous functions -- 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 2 - Page 37 : 46
Functional Programming in Scheme
Expressions, Types, and Functions
Functions as first class values

A function object is a first class citizen

A first class citizen is an entity which can be passed as parameter to functions, returned as a result from a function, and organized as parts of data structures

1> (define toplevel-html-elements (list html frameset))

2> overall-html-elements
(#<procedure> #<procedure>)

3> ((cadr toplevel-html-elements) (frame 'src "sss"))
(ast "frameset" ((ast "frame" () (src "sss") single)) () double)

4> (xml-render ((cadr toplevel-html-elements) (frame 'src "sss")))
"<frameset><frame src = \"sss\"></frameset>"

A few interactions which illustrate the first class properties of function objects. We bind the variable toplevel-html-elements to the list of the two functions html and frameset. Both are HTML mirror functions defined in the LAML general library. We illustrate next that the value of the variable indeed is a list of two functions. Thus, we have seen that we can organized functions as elements in lists. The function cadr returns the second element of a list. It is equivalent to (compose car cdr), where compose is functional composition. In the third evaluation we apply the mirror function frameset on a single frame. The last interaction shows the HTML rendering of the this. xml-render is a function defined in the LAML general library.