Lecture overview -- Keyboard shortcut: 'u'  Previous page: Expressions, values, and types -- Keyboard shortcut: 'p'  Next page: Evaluation of parenthesized expressions -- 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 6 : 46
Functional Programming in Scheme
Expressions, Types, and Functions
Examples of expressions and their values

  • Let us assume that x has the value 3

  • Simple expressions

    • 7    has the value 7

    • (+ x 5)    has the value 8

  • Conditional expressions

    • (if (even? x) 7 (+ x 5))    has the value 8

The conditional expression is evaluated in two steps. First the boolean expression (even? x) is evaluated. If x is even, the boolean expression (even? x) evaluates to true and the trivial expression 7 is evaluated. Because x is 3 and therefore odd, the other expression (+ x 5) is evaluated, giving us the final value 8. It is important to realize that an if form does not evaluate all three constituent expressions at the outset. It first evaluates the boolean expression, and based on the outcome, it either evaluates the 'then part' or the 'else part'. Not both! We have much more to say about the order of evaluation of an if form in a later part of this material

  • Lambda expressions

    • (lambda (x) (+ x 1))    has the value 'the function that adds one to its parameter'

Regarding the lambda expression, the x in parentheses after lambda is the formal parameter of the function. the expression (+ x 1) is the body. In functions, the body is an expression - not a command.

  • HTML mirror expressions

    • (html
       (head 
        (title "PP"))
       (body 
        (p "A body paragraph"))
      )

    • The value of this expression can be rendered as a string in HTML which can be presented in an Internet browser.

The HTML mirror expressions stem from the LAML libraries.

The functions html, body, title, head, and p correspond to the HTML elements of the same names. In the LAML software, the HTML elements are mirrored as functions in Scheme.

Go to side trackLAML and HTML mirror functions
This material includes a lecture that explains the important and relevant details about LAML. Not least, this lecture explains the calling conventions of the so-called HTML mirror functions.