日記
暇すぎる.
今日書いたコード
struct CallableStruct { var value: Int func callAsFunction(_ number: Int, scale: Int) { print(scale * (number + value)) } func callAsFunction() { print("nothing") } } let callable = CallableStruct(value: 1) callable(2, scale: 3) callable() callable.callAsFunction(2, scale: 3) callable.callAsFunction()
感想
これ知らなかった.
プロポーザルはこれで,こういうのに便利だよねと書いてある.
- Values that represent functions: mathematical functions, function expressions, etc.
- Values that have one main use and want to provide a simple call-syntax interface: neural network layers, parsers, efficient bound closures, etc.