at:tutorial:actors
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:actors [2007/04/01 11:46] – added tvcutsem | at:tutorial:actors [2007/04/01 12:21] – added tvcutsem | ||
---|---|---|---|
Line 22: | Line 22: | ||
< | < | ||
- | def a := actor: { | + | >def a := actor: { |
def sayHello() { | def sayHello() { | ||
system.println(" | system.println(" | ||
}; | }; | ||
}; | }; | ||
+ | >>< | ||
</ | </ | ||
+ | |||
+ | As you can see, actors are created similar to objects. The '' | ||
+ | |||
+ | So what exactly is a far reference to an object? The terminology stems from the E language: it is an object reference that refers to an object hosted by another actor. The main difference between regular object references and far references is that regular references allow direct, synchronous access to an object, while far references disallow such access. This is enforced by the kind of messages that these references can carry, as will be explained below. | ||
=== Asynchronous Message Sending === | === Asynchronous Message Sending === | ||
+ | |||
+ | AmbientTalk, | ||
+ | |||
+ | Far references, like the reference stored in the variable '' | ||
+ | |||
+ | Hence, given the example above, the method '' | ||
+ | |||
+ | < | ||
+ | > | ||
+ | >>nil | ||
+ | </ | ||
+ | |||
+ | The above code is simple enough to understand: the '' | ||
+ | |||
+ | But what happens when the method to invoke asynchronously has parameters that need to be passed. How does parameter passing work in the context of inter-actor message sending? The rules are simple enough: | ||
+ | - Objects are always passed **by reference** | ||
+ | - Native data types like numbers, | ||
+ | |||
+ | When an object is passed by reference, we mean that the formal parameter of a method will be bound to a far reference to the original object. When it is passed by copy, the formal parameter will be bound to a local copy of the object. For example, consider the following '' | ||
+ | |||
+ | < | ||
+ | >>def calculator := actor: { | ||
+ | def add(x, | ||
+ | customer< | ||
+ | }; | ||
+ | }; | ||
+ | ><far ref to:< | ||
+ | </ | ||
+ | |||
+ | The '' | ||
+ | |||
+ | < | ||
+ | >> | ||
+ | def result(sum) { | ||
+ | system.println(" | ||
+ | }; | ||
+ | }; | ||
+ | >nil | ||
+ | </ | ||
+ | |||
+ | Because of the parameter passing rules described above, the '' | ||
+ | |||
+ | < | ||
+ | sum = 3 | ||
+ | </ | ||
+ | |||
+ | futures | ||
=== Isolates === | === Isolates === | ||
+ | |||
+ | isolate stripe, by-copy, scoping rules, no external method defs | ||
=== Actor Mirrors === | === Actor Mirrors === | ||
+ | |||
+ | explain: mirror factory, message creation, message sending, install | ||
+ | |||
+ | === Nesting Actors === | ||
+ | |||
+ | lexical scoping rules for nested actors |
at/tutorial/actors.txt · Last modified: 2020/02/05 21:26 by elisag