#1301 Func.bind immutability

msl Tue 9 Nov 2010

Sorry if this has been brought up before - have searched around but can't find anything.

I'm trying to pass a reference to a method as a handler for an concurrent::Actor. Something like:

using concurrent
const class Sample {
  Void main() {
    actor := Actor(ActorPool(), #recv.func.bind([this]))
    echo(actor.send("sample").get)
  }
  Obj? recv(Obj? msg) { msg }
}

However, this results in a sys::NotImmutableErr. Looking at docLang::Functions.immutable, I'm reading:

Method functions are always immutable - see sys::Method.func

I might be interpreting this wrong - but is that not the case that I'm providing here?

Martin

brian Tue 9 Nov 2010

It is true that Method.func is immutable, but that does not hold true once you call bind. In this case since the bound parameter(s) is const, we could actually make the result of bind immutable too. I can take a look.

In the meantime, you should be able to use closure such:

|msg| { rcv(msg) }

brian Tue 9 Nov 2010

Renamed from Methods as immutable functions to Func.bind immutability

brian Tue 9 Nov 2010

Promoted to ticket #1301 and assigned to brian

brian Tue 9 Nov 2010

Ticket resolved in 1.0.56

I updated the Func.bind method such that functions created by sys::Func.bind are immutable if the original function is immutable and every bound argument is immutable.

changeset

Login or Signup to reply.