Home Segments Index Top Previous Next

178: Sidetrip

In Smalltalk methods, local variables act as though they were parameters with nil values. However, although you can change the value of a local variable using an assignment statement, you cannot change the value of a parameter using an assignment statement. For example, you cannot amend the convertToCaloriesWith: method, defined in Segment 121, as follows:

Integer method definition • instance 
convertToCaloriesWith: x 
  "The following assignment statement does not work" 
  x := self * x. 
  ^ x