> On 28 Nov 2017, at 22:06, Jean-Daniel <mail...@xenonium.com> wrote: > > While I perfectly understand why subscript is the best way to represent > dynamic property, I don’t get how it help to abuse it to implement dynamic > methods. Methods are not l-value, so why do you want to use a subscript for > them ?
First, I tried overloading `subscript(dynamicMember:)` by return type. subscript(dynamicMember name: String) -> (_ arguments: Any...) -> JSValue subscript(dynamicMember name: String) -> JSValue It allows for method calls without the DynamicCallable proposal. context[dynamicMember: "Math"][dynamicMember: "pow"](2, 53) //-> 9007199254740992 context[dynamicMember: "Math"][dynamicMember: "PI"] as JSValue //-> 3.1415926535897931 context[dynamicMember: "Math"][dynamicMember: "PI"] //ERROR: Ambiguous use of 'subscript(dynamicMember:)' This evolved into the differently labelled subscripts, to avoid having to disambiguate by return type. But you're right, a function might be better than a subscript. -- Ben _______________________________________________ swift-evolution mailing list swift-evolution@swift.org https://lists.swift.org/mailman/listinfo/swift-evolution