at:tutorial:reflection
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:reflection [2008/06/23 15:08] – * tvcutsem | at:tutorial:reflection [2008/09/15 17:25] – updated tvcutsem | ||
---|---|---|---|
Line 3: | Line 3: | ||
[[wp> | [[wp> | ||
- | The reflective model of AmbientTalk is based on [[http:// | + | The reflective model of AmbientTalk is based on [[http:// |
===== Mirrors ===== | ===== Mirrors ===== | ||
- | As we have already | + | |
+ | As we have mentioned in the introduction, | ||
+ | |||
+ | A convenience primitive exists that allows AmbientTalk programmers to acquire a mirror on an object without explicitly having to consult the mirror | ||
+ | |||
+ | Once a mirror has been created, it can be used to inspect | ||
< | < | ||
- | > | + | def Point := object: { |
+ | def x := 0; | ||
+ | def y := 0; | ||
+ | def distanceToOrigin() { (x*x + y*y).sqrt }; | ||
+ | }; | ||
+ | def p := Point.new(2, | ||
+ | // request a mirror on p via the mirror factory | ||
+ | > def mirrorOnP | ||
>>< | >>< | ||
- | > | ||
- | >> | ||
- | < | ||
- | </ | ||
- | The code excerpt presented above uses the mirror to // | + | > |
+ | >> | ||
+ | </ | ||
- | When reflecting upon a user-defined | + | The code excerpt presented above uses the mirror to // |
< | < | ||
>def inspectable := object: { | >def inspectable := object: { | ||
def map(arg1, @restArgs) { restArgs.map(arg1); | def map(arg1, @restArgs) { restArgs.map(arg1); | ||
- | >>< | + | >>< |
>def mirrorOnInspectable := reflect: inspectable; | >def mirrorOnInspectable := reflect: inspectable; | ||
- | >>< | + | >>< |
> | > | ||
>> | >> |
at/tutorial/reflection.txt · Last modified: 2010/11/16 16:32 by tvcutsem