# Structure andInterpretationof ComputerPrograms

Fall 2021
##### site -->

# Thursday Sep 9

## review

Discuss the main ideas from section 1.1 of the textbook, "elements of programming"

• evaluation & special forms
• substitution model for procedure application
• ... do an example by hand
• cond vs if ... which one should you use?
• recursion !

## homework

Discuss the homework exercises. I've created a folder where I'll put my solutions ... and go over some of them. (We'll see how long that takes and how much detail we want to go into.)

Check out the "Jim's exercises" link over on the right. I'll go over some of them, and invite you to study the rest. And I'll post more as we go along, after you've had a chance to try them first.

Class exercise :

A) Use the "substitution model" to work out by hand what happens in 1.5 .

B) Use scheme's ,trace to try this.

C) Add a print statement as a "poor man's debugger."

(To see how to do trace in racket, Google "racket trace" to find https://docs.racket-lang.org/reference/debugging.html )

## coming next

This week: section 1.2.

Some of this material should be familiar to those of you who've had an algorithms course : the O() notation describes the time it takes (or space it takes) to run an algorithm on a problem of size n.

The common cases are things like

• O(n) i.e. linear time
• O(log(n)) i.e. log time ; divide-and-conquer approaches
• O(n**2) i.e. a loop-with-in-loop for a list of numbers
• O(2**n) i.e. doing n things all both True & False .

This section makes heavy use of recursive algorithms.

It makes a distinction between two different types of programs which are both self-referential (which the text calls "a recursive procedure"), breaking them into two types : a "recursive process" as opposed to an "iterative process". This last idea is also known as "tail recursion", and is a heavily used in lisp coding. Understanding that distinction is the key idea of this section.