Introductory Programming Fall 2004 For next time you should: 1) Finish Homework 3 2) Prepare for an evaluation covering Chapters 1-3 of "How to think..." I'll probably ask you to write some functions that compute and print values. Comment on pace --------------- This class is meant to be as self-paced as possible, with some limitations. In class, we will do one chapter per week, one homework per week and one evaluation per week. If you can't do a homework or an evaluation, you have a choice: 1) You can wait until you get it before going on. 2) You can forge on and try to get it on the way. The problem with (1) is that time in class will become less useful. The problem with (2) is that it's hard to do! Stack diagrams -------------- A stack diagram is: 1) a model of execution good for understanding functions 2) a graphical representation of the state of a program good for debugging 3) a standard graphical language that many programmers understand UML = unified modeling language good for communicating about programs Here's how it works: 0) Initially, the stack has a frame called __main__ that contains global variables. 1) Whenever a function is called, Python puts a new frame on the stack. 2) Function frames contain parameters and local variables. Draw a stack frame for the following program: def a(x, y): z = x + y b(z) def b(n): x = 2 * n c(x + 7) def c(n): y = 17 print n m = 3 n = 2 a(m, n) Some things to remember: 1) arguments are expressions 2) parameters are variables 3) parameter passing works by evaluating the arguments and assigning them to the parameters 4) parameters and local variables are local