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 [2007/06/29 11:14] – Added stijnm | at:tutorial:reflection [2007/07/18 16:32] – jorge | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Reflective Programming ====== | ====== Reflective Programming ====== | ||
- | Reflection is an integral part of the AmbientTalk programming language. Through the use of reflection, the core language can be extended with both programming support as well as new language constructs. Both examples require a different kind of reflective access. The introduction of programming support (e.g. to visualise AmbientTalk objects) relies on **introspection**, | + | [[wp> |
- | The reflective model of AmbientTalk is based on **mirrors**, meta-level objects which allow one to reflect on an objects state and behaviour. How to create such mirrors and how they can be used is demonstrated in the first part of the tutorial. The second part of the tutorial showcases how to construct mirages, objects which override the default meta-level operations with custom behaviour. This tutorial concludes with a brief overview of the meta-level operations which are offered by AmbientTalk mirrors. | + | The reflective model of AmbientTalk is based on [[http:// |
===== Mirrors ===== | ===== Mirrors ===== | ||
- | As we have already mentioned in the introduction, | + | AmbientTalk uses a mirror-based architecture to provide reflective access to its objects. The basic principle of a mirror-based architecture is that all reflective facilities are encapsulated in a mirror object which provides reflective access to precisely one object, its reflectee. Moreover, the mirror of the object is not directly accessible as a slot of the object. Instead, a separate factory must be used to create mirrors, which allows the program to hand out different mirrors according to the dynamic call chain, the requesting object etc. The factory can be used implicitly using the '' |
< | < | ||
def baseObject := object: { | def baseObject := object: { | ||
def field := nil; | def field := nil; | ||
- | def canonicalMethod() { nil } | + | def canonicalMethod() { nil }; |
- | def keyworded: arg1 method: arg2 { nil } | + | def keyworded: arg1 method: arg2 { nil }; |
}; | }; | ||
def mirror := reflect: baseObject; | def mirror := reflect: baseObject; | ||
def slots := mirror.listSlots(); | def slots := mirror.listSlots(); | ||
- | slots.each: { | slot | system.println() }; | + | slots.each: { | slot | system.println(slot) }; |
</ | </ | ||
Line 34: | Line 34: | ||
===== Mirages ===== | ===== 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 '' | + | 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 '' |
< | < | ||
Line 47: | Line 47: | ||
} else: { | } else: { | ||
super^doesNotUnderstand(selector); | super^doesNotUnderstand(selector); | ||
- | } | + | }; |
- | } | + | }; |
} | } | ||
</ | </ | ||
- | This mirror overrides the default implementation of the meta-operation '' | + | This mirror overrides the default implementation of the meta-operation '' |
< | < | ||
Line 68: | Line 68: | ||
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' | 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' | ||
- | ===== Meta-Object | + | ===== The Metaobject |
The Meta-Object Protocol of AmbientTalk can be divided into a series of independent protocols. Whereas the full semantics and signature of the meta-methods can be found in the [[http:// | The Meta-Object Protocol of AmbientTalk can be divided into a series of independent protocols. Whereas the full semantics and signature of the meta-methods can be found in the [[http:// |
at/tutorial/reflection.txt · Last modified: 2010/11/16 16:32 by tvcutsem