at:tutorial:reflection
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
at:tutorial:reflection [2007/04/27 12:58] – Added stijnm | at:tutorial:reflection [2007/04/27 14:47] – Added stijnm | ||
---|---|---|---|
Line 33: | Line 33: | ||
This part of the tutorial has provided a basic feeling of how AmbientTalk' | This part of the tutorial has provided a basic feeling of how AmbientTalk' | ||
+ | |||
+ | ===== Mirages ===== | ||
+ | Extending the AmbientTalk core language involves adding objects which have a different implementation for some of the default meta-operations. In this part of the tutorial we describe how a programmer could define objects which allow for the dynamic addition of unknown methods and fields. First of all, we need to create a mirror instance which we can use to create new objects from. This can be performed using the '' | ||
+ | |||
+ | < | ||
+ | def dynamicExtensionMirror := mirror: { | ||
+ | def doesNotUnderstand(selector) { | ||
+ | system.println(" | ||
+ | system.println(" | ||
+ | def input := system.readln(); | ||
+ | if: !( "" | ||
+ | def definition := read: input; | ||
+ | eval: definition in: base; | ||
+ | } else: { | ||
+ | super^doesNotUnderstand(selector); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | This mirror overrides the default implementation of the meta-operation '' | ||
+ | |||
+ | < | ||
+ | def mirage := object: { | ||
+ | def m() { self.x }; | ||
+ | } mirroredBy: dynamicExtensionMirror; | ||
+ | </ | ||
+ | |||
+ | When invoking the method '' | ||
+ | |||
+ | < | ||
+ | Note that the use of '' | ||
+ | </ | ||
+ | |||
+ | Whereas the example provided above may seem a little contrived, the reflective capabilities of AmbientTalk allow it to be extended with many abstraction relating to distributed computing for mobile ad hoc networks (AmbientTalk' | ||
+ |
at/tutorial/reflection.txt · Last modified: 2010/11/16 16:32 by tvcutsem