at:tutorial:objects
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
at:tutorial:objects [2007/06/27 11:40] – jorge | at:tutorial:objects [2007/06/29 08:14] – jorge | ||
---|---|---|---|
Line 12: | Line 12: | ||
def x := 0; | def x := 0; | ||
def y := 0; | def y := 0; | ||
- | def init(m,n) { | + | def init(aX,aY) { |
- | x := m; | + | x := aX; |
- | y := n; | + | y := aY; |
- | } | + | }; |
- | def sumofsquares() { x*x + y*y }; | + | def sumOfSquares() { x*x + y*y }; |
} | } | ||
>>< | >>< | ||
</ | </ | ||
- | This object can be instantiated to create new points as follows: | + | As all definitions in AmbientTalk, |
+ | |||
+ | <note important> | ||
+ | AmbientTalk not only supports traditional canonical syntax (e.g. '' | ||
+ | </ | ||
+ | |||
+ | In the example above, the state of the '' | ||
< | < | ||
- | > def initialPoint | + | > def aPoint |
+ | >>< | ||
</ | </ | ||
+ | |||
+ | Every object understands the message '' | ||
===== Sending messages ===== | ===== Sending messages ===== | ||
- | In AmbientTalk, | + | In AmbientTalk, |
+ | |||
+ | < | ||
+ | > aPoint.x | ||
+ | >>2 | ||
+ | > aPoint.sumOfSquares() | ||
+ | >> | ||
+ | </ | ||
+ | |||
+ | This code shows two messages sent to the '' | ||
===== Cloning and instantiation ===== | ===== Cloning and instantiation ===== |
at/tutorial/objects.txt · Last modified: 2013/05/17 20:23 by tvcutsem