[swift-evolution] Apply for closure

James Campbell james at supmenow.com
Thu Jan 28 12:28:28 CST 2016


I think making functions first class citizens would be mega cool

Sent from my iPhone

> On 28 Jan 2016, at 13:07, Tino Heth <2th at gmx.de> wrote:
> 
> I have no obvious use case, but I like the concept of "functions having functions":
> It is most likely not that relevant for Swift 3, but as soon as the macro-system becomes concrete, it could be valuable for meta-programming…
> 
> Besides "apply", we could have introspection ("f.parametersByIndex[0].type") and a revival of currying
> let twice: (Double) -> Double = *.curry(parameterIndex: 0, value: 2.0)
> 
> It could even be possible to do meta-programming without leaving the language, e.g.
> 
> class Snitch: SomeClass {
>    for f in super.overridableMethods {
>        self.implementation[f] = { (args: f.argumentTuple) in
>            print("Function \(f.name) has been called with \(args)")
>            return f.apply(args)
>        }
>    }
> }
> 
> I probably would hate anyone actually using such a feature (unless the debugger is really great ;-), but it would be freaking cool nonetheless ;-)
> 
> Tino


More information about the swift-evolution mailing list