[swift-evolution] Smart KeyPaths
Vladimir.S
svabox at gmail.com
Wed Mar 22 11:00:37 CDT 2017
On 22.03.2017 18:47, Matthew Johnson wrote:
>
>> On Mar 22, 2017, at 10:36 AM, Vladimir.S via swift-evolution
>> <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>
>> On 22.03.2017 17:37, Ricardo Parada wrote:
>>>
>>>
>>>> On Mar 22, 2017, at 9:30 AM, Vladimir.S <svabox at gmail.com
>>>> <mailto:svabox at gmail.com>> wrote:
>>>>
>>>> let path = @Bag.things[0].name
>>>>
>>>> bag at path
>>>> bag at .things[0].name
>>>> bag at Bag.things <mailto:bag at Bag.things>[0].name
>>>> bag.things[0]@.name
>>>> bag.things[0]@Thing.name
>>>
>>> It sounds like the @ character is serving two different purposes which
>>> confused me at first.
>>>
>>> If I understood correctly, you are using it to get the key path but also
>>> to apply the key path to the bag struct and get the corresponding value.
>>>
>>
>> Yes. And the initial proposal suggest the following syntax accordingly:
>>
>> let path = Bag.things[0].name
>> bag[path]
>> bag[.things[0].name]
>> bag[Bag.things[0].name]
>> bag.things[0][.name]
>> bag.things[0][Thing.name]
>
> # makes a lot more sense than @ as a sigil. It follows from #selector and
> #keyPath. These are the most similar language features right now where the
> compiler produces special values. I think it’s also worth noticing that
> values produced by #selector and #keyPath are /used/ in normal ways. There
> is no magic syntax for their use, just a typed value. If we’re going to
> make a change we should use # instead of `.` for accessing these special
> values but we should stick with subscript for use.
Could you clarify, what do you suggest? Something like this:
let path = Bag#things[0]#name
bag[#path]
bag[#things[0]#name]
bag[Bag#things[0]#name]
bag.things[0][#name]
bag.things[0][Thing#name]
,and so
let ref = Bag#foo()
?
In this case I feel like the following will be more clean syntax:
let path = #Bag.things[0].name
bag[#path]
bag[#.things[0].name]
bag[#Bag.things[0].name]
bag.things[0][#.name]
bag.things[0][#Thing.name]
let ref = #Bag.foo()
And why subscript is the only good candidate for use?
Actually, for me personally, any solution will be good as soon as it
contains some 'marker' which saying "hey, here key paths are used. be aware."
>
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>
More information about the swift-evolution
mailing list