Pitch: Scoped Functions

This is exact. But it goes beyond the with statement. Besides, the implicit context is chosen by the enclosing function (here the with function), not by the user.

It happens that the enclosing function injects a user value as the context. This is the case of with:

func with<T>(_ value: T, run: @scoped (T) -> Void) { run(value) }

with("Hello") {
     print(.count)        // prints "5"
     print(.lowercased()) // prints "hello"
}

But the enclosing function can choose to provide another context: see the database requests examples in the pitch.