good question #2: redefinition
free variables and redefinition (david, recitation 2)
- (define i 3)
- (define (f j) (+ i j)
- (f 4)
- (define i 5)
- (f 4)
answer
- define is not assignment: it is used to associate names with values
- in a program, redefinition is bad style, and is forbidden by some Scheme systems
- when interacting live, it’s useful to be able to redefine names
- so after (define i 5), i now names 5, and (f 4) evaluates to 9
- we’ll be able to understand this more deeply later,when we look at code in which time-ordering matters
- for now, when the program executes, variables don’t vary:the value named by a variable is fixed, and does not change