We kind of discussed this, but I just want to clarify things. My original proposal specified lazy it-blocks and immediate it-blocks. But then we talked about a with method which would be your hook for handling immediate it-blocks (and potentially turning them lazy).
Now that I'm in the thick of implementing them, I think all it-blocks are just lazy closures. If the target call doesn't accept a closure, then it routes to Obj.with:
virtual This with(|This| f)
{
f(this)
return this
}
So the compiler doesn't ever do anything but create the closure and pass it somewhere. If the target doesn't accept a closure, then we just route to Obj.with. So the notion of "immediate" is really just because that is the default implementation of with.
Technically the compiler could detect that with wasn't overridden, and generate the code inline, but I am not going to do that right now. It severely complicates how the compiler manages closures and local variables used by closures.
And yes const immutable classes might have a different/special version of with that returns a new instance - but that is really a feature built on top of this feature.
jodastephenMon 6 Apr 2009
The only problem I see is performance, as there will be a lot of small classes. But that should be optimised later if at all possible, so lets go for full lazy closures now.
brian Mon 6 Apr 2009
We kind of discussed this, but I just want to clarify things. My original proposal specified lazy it-blocks and immediate it-blocks. But then we talked about a
with
method which would be your hook for handling immediate it-blocks (and potentially turning them lazy).Now that I'm in the thick of implementing them, I think all it-blocks are just lazy closures. If the target call doesn't accept a closure, then it routes to
Obj.with
:So the compiler doesn't ever do anything but create the closure and pass it somewhere. If the target doesn't accept a closure, then we just route to
Obj.with
. So the notion of "immediate" is really just because that is the default implementation ofwith
.Technically the compiler could detect that
with
wasn't overridden, and generate the code inline, but I am not going to do that right now. It severely complicates how the compiler manages closures and local variables used by closures.And yes const immutable classes might have a different/special version of
with
that returns a new instance - but that is really a feature built on top of this feature.jodastephen Mon 6 Apr 2009
The only problem I see is performance, as there will be a lot of small classes. But that should be optimised later if at all possible, so lets go for full lazy closures now.
JohnDG Mon 6 Apr 2009
Looks good to me.