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/07 20:10] – tvcutsem | at:tutorial:actors [2007/04/07 20:22] – * tvcutsem | ||
---|---|---|---|
Line 332: | Line 332: | ||
==== Nesting Actors ==== | ==== Nesting Actors ==== | ||
- | lexical scoping rules for nested actors | + | In AmbientTalk, |
+ | |||
+ | < | ||
+ | def outer := actor: { | ||
+ | def x := 1; | ||
+ | def get() { x }; | ||
+ | def set(v) { x := v }; | ||
+ | |||
+ | def inner := actor: { | ||
+ | def get() { x }; | ||
+ | def set(v) { x := v }; | ||
+ | }; | ||
+ | }; | ||
+ | </ | ||
+ | |||
+ | If both the '' | ||
+ | |||
+ | Recall that isolates could be given selective access to their enclosing lexical scope by specifying accessed variables as formal parameters to their initializing closure, which gave rise to copying the variable into the isolate. We allow actors to do the same. Hence, the above example can be written properly as: | ||
+ | |||
+ | < | ||
+ | def outer := actor: { | ||
+ | def x := 1; | ||
+ | def get() { x }; | ||
+ | def set(v) { x := v }; | ||
+ | |||
+ | def inner := actor: { |x| | ||
+ | def get() { x }; | ||
+ | def set(v) { x := v }; | ||
+ | }; | ||
+ | }; | ||
+ | </ | ||
+ | |||
+ | It still makes sense to nest actors, but each actor will have its own local copy of lexically shared variables. Furthermore, |
at/tutorial/actors.txt · Last modified: 2020/02/05 21:26 by elisag