[swift-evolution] [Pitch] Introduce User-defined "Dynamic Member Lookup" Types

Chris Lattner sabre at nondot.org
Mon Nov 20 20:22:39 CST 2017


> On Nov 16, 2017, at 4:49 AM, Michel Fortin via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I think this protocol and its subscript need a better name. From a user of the class point of view, the subscript looks like you can retrieve the members of the class, whereas in reality you'll only get the ones you have manually implemented. Even methods and properties having the `dynamic` attribute won't be available, even though the subscript name would suggest that.
> 
> I would propose adding the word `supplemental`to the subscript name and the name of the protocol to make it clearer that this is only for adding members that are not declared in the class (including the `dynamic` ones).
> 
> As in `SupplementalDynamicMemberLookupProtocol` and `supplementalDynamicMember` for the subscript.

I’m totally open to suggestions for a better name, but I don’t see what “Supplemental” is adding here.  Recall that this protocol is compiler “magic” that is part of an implementation of a type, it isn’t really part of the user-exposed API of the type.  I wouldn’t expect a user to ever write:

   pyVal[dynamicMember: “foo”]

Even though they could.  Maybe we need to add private conformances to Swift or something :-)

-Chris


> 
> 
>> Le 15 nov. 2017 à 2:29, Chris Lattner via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> a écrit :
>> 
>> protocol DynamicMemberLookupProtocol {
>>   associatedtype DynamicMemberLookupValue
>> 
>>   subscript(dynamicMember name: String) -> DynamicMemberLookupValue { get set }
>> }
>> 
> 
> -- 
> Michel Fortin
> https://michelf.ca <https://michelf.ca/>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171120/0e1d56e5/attachment.html>


More information about the swift-evolution mailing list