[External] : Re: Scope Locals
Brian Goetz
brian.goetz at oracle.com
Tue Apr 27 17:18:35 UTC 2021
I think what Jack is getting at is that the case where there is only one
scope variable will be common, and is worth optimizing both the
expression and implementation of this. So something like:
interface ScopeLocal<T> {
void runWith(T t, Runnable r);
static<T> ScopeLocalBuilder with(ScopeLocal<T> sl, T expr) {
return new ScopeLocalBuilder().with(sl, expr);
}
}
class ScopeLocalBuilder {
ScopeLocalBuilder() { }
<T> ScopeLocalBuilder with(ScopeLocal<T> sl, T expr) { ... }
void run(Runnable r);
}
This admits the easy (and possibly more optimizable) locution
x.runWith(expr1, r)
for the one-variable case, and
ScopeLocal.with(x, expr1)
.with(y, expr2)
.run(r)
for the fancy case.
On 4/27/2021 11:59 AM, Andrew Haley wrote:
> On 4/20/21 2:20 AM, Jack Firth wrote:
>> It seems strange that where() is both a static method on ScopeLocal and an
>> instance method on the carrier. Maybe have a separate parameter-less static
>> method for starting the chain?
>>
>> scope()
>> .where(x, expr1)
>> .where(y, expr2)
>> .run(() -> ...);
> The method scope() still has to be a member of some class, and you'd
> have to specify that somehow. Whatever we do will be slightly strange,
> I think.
>
More information about the loom-dev
mailing list