Hello :wave:, Is there a way to limit access of a ...
# announcements
a
Hello 👋, Is there a way to limit access of a block of code to only within a scope? For example, could I somehow have a lambda where assignments outside of scope are not allowed?
k
You want something like
fun foo(block: (Int) -> Int)
where
block
isn't allowed to access stuff from the scope where it was defined? I don't think that's possible.
a
Yes!
I think this is loosely similar to @DslMarker
Could be a very useful feature for limiting side effects
Worth bringing up in #C0B9K7EP2 ?
k
Maybe, although it's difficult to determine what a side effect is. You wouldn't be able to call any functions at all, or use any libraries.
a
I'm not really interested in a pure FP side effect free guarantee. More a simple check where if you assign a variable outside of the lambda scope you'll get a compiler error.
p
I guess you want to force lambda to be non-capturing, right?
a
Not necessarily non capturing. But you are not allowed to assign outside of your scope. I think if it is being executed on a different thread this could be a useful protective feature.