at:tutorial:multiparadigm
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
at:tutorial:multiparadigm [2007/07/27 10:23] – added tvcutsem | at:tutorial:multiparadigm [2011/06/07 18:29] (current) – *minor tvcutsem | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== On Scoping, Closures, Methods and Messages ====== | ====== On Scoping, Closures, Methods and Messages ====== | ||
- | This tutorial chapter goes into a bit more detail on the subtle | + | This tutorial chapter goes into a bit more detail on the interplay between AmbientTalk' |
===== Lexical Scope vs Object Scope ===== | ===== Lexical Scope vs Object Scope ===== | ||
Line 13: | Line 13: | ||
- Qualified access to a variable, e.g. '' | - Qualified access to a variable, e.g. '' | ||
- | These rules also hold for method invocation: the invocation '' | + | These rules also hold for method invocation: the invocation '' |
- | Probably the most important | + | The most important |
< | < | ||
Line 48: | Line 48: | ||
<note important> | <note important> | ||
- | For many object-oriented programmers, | + | For many object-oriented programmers, |
+ | |||
+ | The confusion stems from the fact that many OO languages -- like Java -- make no distinction between both access forms. | ||
</ | </ | ||
Line 67: | Line 69: | ||
It is important that '' | It is important that '' | ||
- | ==== Nesting Objects ==== | + | ===== Nesting Objects |
AmbientTalk exploits its lexical scoping rules to the fullest extent by allowing as much program elements as possible to be nested. For example, it is possible to lexically nest objects within other objects, or even to nest functions within other functions. In this section, we describe how nested objects interact with the scoping rules presented above. | AmbientTalk exploits its lexical scoping rules to the fullest extent by allowing as much program elements as possible to be nested. For example, it is possible to lexically nest objects within other objects, or even to nest functions within other functions. In this section, we describe how nested objects interact with the scoping rules presented above. | ||
- | === Facets === | + | ==== Facets |
One of the most appealing use cases for nesting objects is that it allows a very secure kind of //sharing// between objects: all objects that are nested within another object have the privilege of all sharing the same lexical scope. This form of sharing is much more secure that sharing data via delegation, because the set of objects sharing the scope is statically fixed. In the E language, such nested objects are called [[http:// | One of the most appealing use cases for nesting objects is that it allows a very secure kind of //sharing// between objects: all objects that are nested within another object have the privilege of all sharing the same lexical scope. This form of sharing is much more secure that sharing data via delegation, because the set of objects sharing the scope is statically fixed. In the E language, such nested objects are called [[http:// | ||
Line 97: | Line 99: | ||
The '' | The '' | ||
- | === Nesting and Delegation === | + | ==== Nesting and Delegation |
Thanks to AmbientTalk' | Thanks to AmbientTalk' | ||
Line 129: | Line 131: | ||
In the example above, writing '' | In the example above, writing '' | ||
- | ==== Methods vs Closures ==== | + | ===== Methods vs Closures |
As mentioned previously, AmbientTalk not only allows objects to be nested within other objects, but also allows functions to be nested within other functions. At this point, it becomes important to distinguish between // | As mentioned previously, AmbientTalk not only allows objects to be nested within other objects, but also allows functions to be nested within other functions. At this point, it becomes important to distinguish between // | ||
Line 152: | Line 154: | ||
In the above example, '' | In the above example, '' | ||
- | === Top-level Functions === | + | ==== Top-level Functions |
Top-level functions are actually methods in AmbientTalk. This is because all top-level code is treated as the initialization code of that file's module object. Hence, it is legal to use '' | Top-level functions are actually methods in AmbientTalk. This is because all top-level code is treated as the initialization code of that file's module object. Hence, it is legal to use '' | ||
- | === Block closures === | + | ==== Block closures |
Block closures, as created by means of the syntax '' | Block closures, as created by means of the syntax '' | ||
- | ==== External Methods ==== | + | ===== External Methods |
- | It is possible to define methods externally on an object. For example: | + | It is possible to define methods |
< | < | ||
Line 180: | Line 182: | ||
The rationale behind this decision is that '' | The rationale behind this decision is that '' | ||
+ | </ | ||
+ | |||
+ | <note warning> | ||
+ | External methods, while powerful, introduce many subtle issues in the language. Therefore, this feature may disappear from later releases of AmbientTalk. It is therefore wise to stay clear from using this feature. For an overview of the problem introduced by external field or method declarations, | ||
</ | </ | ||
at/tutorial/multiparadigm.1185524609.txt.gz · Last modified: 2007/08/22 11:40 (external edit)