Is this right? Because the only way round it (that I can find) is to manually serialise my const Objs (whatever they may be) into a Str, send the msg and then de-serialise on the next line!
Future biteMe(Obj food) {
Str s := writeObj(food)
send |->| {
Obj f := s.in.read
echo("I like to eat $f")
}
}
Ouch!
brianWed 29 Feb 2012
Well I would highly recommend you stick with simple immutable objects for messages and return values. That is super fast and super simple.
You cannot serialize functions (although you can send type and slot literals). But sometimes functions are immutable in which case it will work. If you really want to try to pass functions, then you might want to take look at this document which describes when functions are immutable and when they aren't docLang::Functions#immutable.
SlimerDudeWed 29 Feb 2012
Hi Brain,
The point I was trying to make was, I am sending simple immutable objects though the closure. In the example above, it was a Str. But when the Str is declared as Obj it throws an Err.
Closure which capture non-final variables which aren't known to be immutable until runtime (such as Obj or List) will return false for isImmutable, but will provide a toImmutable method which attempts to bind to the current variables by calling toImmutable on each one
So that should work right? As Str is immutable.
brianWed 29 Feb 2012
You might have to call toImmutable explictly then - actor library only checks isImmutable and otherwise tries to seralize
SlimerDude Wed 29 Feb 2012
Whilst refactoring my Actor code I find some funcs can be passed as msgs and others throw Errs... It's driving me bonkers!
Here's a simple example that throws an IOErr:
throws
But if change
biteMe()
to:I get
Is this right? Because the only way round it (that I can find) is to manually serialise my const Objs (whatever they may be) into a Str, send the msg and then de-serialise on the next line!
Ouch!
brian Wed 29 Feb 2012
Well I would highly recommend you stick with simple immutable objects for messages and return values. That is super fast and super simple.
You cannot serialize functions (although you can send type and slot literals). But sometimes functions are immutable in which case it will work. If you really want to try to pass functions, then you might want to take look at this document which describes when functions are immutable and when they aren't docLang::Functions#immutable.
SlimerDude Wed 29 Feb 2012
Hi Brain,
The point I was trying to make was, I am sending simple immutable objects though the closure. In the example above, it was a
Str
. But when theStr
is declared asObj
it throws an Err.From docLang::Functions#immutable
So that should work right? As
Str
is immutable.brian Wed 29 Feb 2012
You might have to call
toImmutable
explictly then - actor library only checksisImmutable
and otherwise tries to seralize