I ended up pitching this as part of a larger strategy to recast closures as syntactic sugar over protocols. The thread is here.
I really want to be able to create anonymous types that conform to protocols or are subclasses of a class, and that close over their context, like this:
protocol MyProtocol {
func doThis()
}
func doSomething(aLocal: Int) {
let anonymous = struct: MyProtocol {
func doThis() { print("Look at my capture! \(aLocal)")
}
}
Since I have a growing list ideas for language features and I want to be more helpful than just talking about them excessively, and I want to get more familiar with compilers, I'm planning on trying to implement one of them in the near future. This feature, at least a minimal form of it (that doesn't deal with escape, so that all anonymous types are "escaping" the same way nominal types are, I do want the MVP to support closure though), is on the top of my list for what to start with.