# Lecture: Functional Programming and Operational Semantics of Scheme

### Background Material

• Lecture on functional programming and scheme.
• Binding and free variables

• Chapter 10 (sec. 1-5) of the text
• Chapter 1 (sec. 1.1.2-1.1.5) of SICP
• Chapter 3 (sec. 3.1, 3.2, and 3.5) SICP
• Chapter 4 (sec. 4.1 and 4.2) SICP

### Theme

In Introduction to Scheme we informally provided the semantics for scheme expressions: To evaluate (E1 E2 ... En), recursively evaluate E1, E2,...,En - E1 should evaluate to a function - and then apply the function value of E1 to the arguments given by the values of E2,...,En. In the base case, there are self evaluating expressions (e.g. numbers and symbols). In addition, various special forms such as quote and if must be handled separately.

In this lecture we will further discuss the semantics of scheme expressions. We will begin with a simple model, called the substitution model, where a function application corresponds to substituting the argument expressions into the formal parameters of the function body. The substitution process can proceed in different orders - scheme uses applicative order, where the arguments are fully evaluated prior to substitution. Other possibilities exist - for example, the arguments can be immediately substituted and then only further expanded when needed (normal order). The substitution model of function application is formally investigated using the lambda calculus, which will be discussed later in the course.

When assignment is introduced the substitution model falls apart and a different model, more complicated model, must be used. In the lecture material on streams, we introduce the environment model of function evaluation, which are used to lookup and modify variables. Environments can be nested to handle nested scope, and the nesting can be established at the time of function definition (static scoping) or at the time of function application (dynamic scoping). The semantics of scheme using environments can be described operationally using an interpreter

### Lecture Slides

1. funprog.ppt or funprog.pdf - overview slides for lecture.
Created: April 22, 2008 (revised April 19, 2012) by jjohnson AT cs DOT drexel DOT DOT edu