On a mutable associative it is valid to execute the following ( where x is 
associative )

x = Dict()
y = x[:a] = 1.23 



y has the value 1.23 

on an immutable collection what does the following mean ? 

x = @NT( )
y = x[:a] = 1.23 


Do I get a new version of x with the key :a and the value 1.23 ? 


On Wednesday, May 13, 2015 at 5:31:27 PM UTC-4, David Gold wrote:
>
> It also brings up an asymmetry between the overloaded [] operator for 
> immutable collections, where y = x[:a] is valid but x' = x[:b] = 1.23 is 
> not. I'm ok with this, but it does  lead to some confusion. 
>
> Would you please elaborate on this? I'm not sure I understand (I'm 
> confident the issue is on my end).
>
> On Wednesday, May 13, 2015 at 3:03:11 PM UTC-4, Michael Francis wrote:
>>
>> A little bit of both, I have defined what I would consider common verbs, 
>> they happen to not exist in Base today. So either they get added to 
>> Base, which in this instance may be the right thing or at some point in 
>> the future they will conflict and breakage will ensue.
>>
>> It also brings up an asymmetry between the overloaded [] operator for 
>> immutable collections, where y = x[:a] is valid but x' = x[:b] = 1.23 is 
>> not. I'm ok with this, but it does  lead to some confusion. 
>>
>> Most languages sidestep this by not having the ! annotation for mutation 
>> and rely on the type/number of arguments to define the behavior. I'm not 
>> necessarily advocating for this, but I would like some input from others on 
>> this. 
>>
>>
>> On Wednesday, May 13, 2015 at 2:51:47 PM UTC-4, Josh Langsfeld wrote:
>>>
>>> Is your concern that some other package might also export non-mutating 
>>> setindex and delete, thereby conflicting with yours? Or just that they 
>>> should exist in Base?
>>>
>>> On Wednesday, May 13, 2015 at 2:35:44 PM UTC-4, Michael Francis wrote:
>>>>
>>>> I added methods to NamedTuples.jl to support merge, set and delete. 
>>>> Since NamedTuples are essentially immutable dictionaries it seems 
>>>> incorrect 
>>>> to use the ! forms of setindex and delete. I now have an issue that these 
>>>> are not defined in base. How best to solve this? This is indirectly 
>>>> related 
>>>> to the thread on function name collapse, but any suggestions ?  
>>>>
>>>> nt = @NT( a=>1, b=>2, c=>3 )
>>>> x = NamedTuples.setindex( nt, :x, 123 )
>>>> NamedTuples.delete( x, :a) # (b=>2,c=>3,x=>123)
>>>> merge( nt, @NT( d => "hello", e => "world")) # ( 
>>>> a=>1,b=>2,c=>3,d=>"hello",e=>"world")
>>>>
>>>>
>>>>
>>>>

Reply via email to