Examples
deposit:50
|
Examples of method invocation:
deposit: 50 and withdraw: 20 Sending deposit: 50 to the bank account causes a lookup for a slot named deposit:. This locates the method of the same name. Execution of the method begins by binding the formal argument, d, to the actual argument, 50, and by binding the name self to the bank account object. The deposit: method can be read as follows (we will explain the syntax and semantics of Self in detail later):
self balance: ((self balance) + d) Sending withdraw: 20 is similar, except that before the final balance: message is sent, the result of balance-w is passed as an argument to the max: message, which is sent to 0. Here, the receiver of the message is explicit. Max: sent to a number with another number as argument returns the larger of the numbers. Fully parenthesized with explicit messages to self, withdraw: would be like this:
self balance: (0 max: ((self balance) - w)) |