[Swift-devel] Associative arrays: foreach index issue.
Yadu Nand
yadudoc1729 at gmail.com
Fri Jun 24 14:49:15 CDT 2011
On Sat, Jun 25, 2011 at 1:00 AM, Ben Clifford <benc at hawaga.org.uk> wrote:
>
> On Jun 24, 2011, at 8:51 PM, Mihael Hategan wrote:
>
>> Ok, so slow down a bit.
>>
>> On Sat, 2011-06-25 at 00:09 +0530, Yadu Nand wrote:
>>> Hi,
>>>
>>> After discussing with Justin I used java.util.UUIDs as indices for
>>> cases in which we need something close to appending the value
>>> associated with a particular key.
>>
>> We've established that any random id is as bad as a sequential id. So
>> use the thread index instead if you really want this.
>
> agree.
Okay, I'll try to put in the index as the thread index. If this happens to be
and int, we don't need to make changes anywhere else.
I'm not sure what the type the thread index is.
>> But I think we
>> also established that we don't really need implicit indices.
>>
>
> disagree. I think they can make coding simpler by allowing Swift to figure out stuff for you rather than you having to express boilerplate indices that you can get wrong.
>
> I think the ["!"] syntax is awful - I suggested it only for the purposes of my original message for the sake of having *something*.
I tried the ["!"] because it was easy to implement.
int array[ ][ ];
append ( array["key"] , <value> )
Or we'll have to try what Mihael said which is,
array["key"] += <value>
>>>
>>> 1. We may try using a different declaration style to denote non-int
>>> subscripts.
>>> int array [$] [$] ( where $ represents strings )
>>
>> That's random an ugly. We should use the exact type for declarations:
>>
>> int array[string].
>
> agree.
>
> (Part of my justification: conceptually (even if it is never implemented) any data type that has a sensible equality relation can be used as an index. Other examples are booleans, and structs composed of other types with equality.)
>
>>
>>> 2. Or simply modify the foreach syntax to accommodate string
>>> indices. Leaving the following style
>>> foreach value, string:index in array["key"] {
>>> // do work
>>> }
>>
>> And what happens if there is a mismatch between the foreach index type
>> and the array type?
>>
>> Point being that we can use type inference to figure out the type of the
>> index since we know the type of the array key.
>
> agree. originally foreach had a type spec for 'value' too, which was replaced by inference - it could never contain any useful information.
So, I'll have to look into handling type inference which handling the foreach
indices.
--
Thanks and Regards,
Yadu Nand B
More information about the Swift-devel
mailing list