at:tutorial:actors
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
at:tutorial:actors [2007/04/01 12:05] – added tvcutsem | at:tutorial:actors [2007/04/01 12:21] – added tvcutsem | ||
---|---|---|---|
Line 38: | Line 38: | ||
AmbientTalk, | AmbientTalk, | ||
- | Far references, like the reference stored in the variable '' | + | Far references, like the reference stored in the variable '' |
Hence, given the example above, the method '' | Hence, given the example above, the method '' | ||
Line 47: | Line 47: | ||
</ | </ | ||
- | async messages, parameter passing, futures | + | 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,text,tables are always passed **by copy** | ||
+ | |||
+ | 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 | ||
+ | |||
+ | < | ||
+ | sum = 3 | ||
+ | </ | ||
+ | |||
+ | futures | ||
=== Isolates === | === Isolates === |
at/tutorial/actors.txt · Last modified: 2020/02/05 21:26 by elisag