Version 16 by komaz
on Nov 25, 2010 21:13.

compared with
Current by komaz
on Nov 25, 2010 21:46.

Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (4)

View Page History
{toc}

h3. Brief intro to DSLs
[Fandoc|http://fantom.org/doc/docLang/DSLs.html] says:
# Changes getter and setter to AST equivalents of this code:
{noformat}
get { Actor.locals.containsKey("fieldName") ? Actor.locals["fieldName"] : (initExpr ?: fieldType.defVal) }
get
{
Actor.locals.containsKey("fieldName") ?
Actor.locals["fieldName"] :
(initExpr ?: fieldType.defVal)
}
set { Actor.locals["fieldName"] = it }
{noformat}

Voila!

There's one problem with this code, imagine the case like this:
{noformat}
const class Foo
{
@Magic { kind = ActorLocal<||> }
Str s
}
const class MyActor
{
const Foo foo1
const Foo foo2
...
override Obj? receive(Obj? msg)
{
foo1.s = "str" //now foo2.s equals to "str" too
}
}
{noformat}
And I don't really know if this can be fixed correctly. In theory, we could store map {{\[Foo:FieldType\]}} in {{Actor.locals}}, but there are two obstacles:
# We won't know when to remove values from this map, probably weak keys could help
# Foo must be const - only const objects can be used as map keys

However, I don't think it is a big deal, since typically such fields can be declared in actors itself and used only from {{receive}} method, so they'll act as normal instance fields.

h3. Conclusion