Sorry wasn’t aware of that...

Le ven. 19 janv. 2018 à 17:43, Ben Wilson <[email protected]> a écrit :

> Notably, this mailing list is for proposals for the development of the
> language. General questions are better suited for the forums, slack, irc,
> or other more general discussion areas.
>
>
> On Wednesday, January 17, 2018 at 5:11:01 AM UTC-5, mG S wrote:
>>
>> Any exemple about "avoid bugs but to allow potential optimizations" ?
>> just curious actually...
>>
>> Le mardi 16 janvier 2018 17:58:47 UTC+1, [email protected] a écrit :
>>>
>>> as a side note, you can note that erlang has :maps.put (inserts/replace
>>> a k/v) and :maps.update (only replaces an existing kv),
>>>
>>> elixir mimics this by having Map.put for insert/replace and %{x | atom:
>>> :atom} for replace (note that Map.update/4 has a different behaviour and is
>>> too complex for this case where you simply want to set an specific value to
>>> a map that should have the expected key)
>>>
>>> On Tuesday, January 16, 2018 at 2:56:10 PM UTC-2, [email protected]
>>> wrote:
>>>>
>>>> The syntax for updating maps (ie: `%{x | foo: :bar}`) assumes the key
>>>> is already set on the map, this is to, not only, avoid bugs but to allow
>>>> potential optimizations
>>>>
>>>> In https://hexdocs.pm/elixir/Map.html you can see that this is an
>>>> expected behaviour
>>>>
>>>> > Maps also support a specific update syntax to update the value
>>>> stored under *existing* atom keys:
>>>>
>>>> On Tuesday, January 16, 2018 at 2:16:24 PM UTC-2, mG S wrote:
>>>>>
>>>>> Hi everyone,
>>>>>
>>>>> Well the whole question fits in the subject...
>>>>> I was wondering why the pipe operator used in a map was sugar for
>>>>> Map.update and not Map.put
>>>>>
>>>>> iex(1)> m=%{foo: 1}
>>>>> %{foo: 1}
>>>>> iex(2)> %{m | bar: 2}
>>>>> ** (KeyError) key :bar not found in: %{foo: 1}
>>>>>     (stdlib) :maps.update(:bar, 2, %{foo: 1})
>>>>>     (stdlib) erl_eval.erl:255: anonymous fn/2 in :erl_eval.expr/5
>>>>>     (stdlib) lists.erl:1262: :lists.foldl/3
>>>>> iex(2)> %{m | foo: 2}
>>>>> %{foo: 2}
>>>>>
>>>>>
>>>>> I'm sure it has good reasons, but I'm a little puzzled on why ?
>>>>>
>>>>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "elixir-lang-core" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/elixir-lang-core/HCHiY9ctjrg/unsubscribe
> .
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elixir-lang-core/ef39ecfc-8e92-4bfa-8272-b78e354b3528%40googlegroups.com
> <https://groups.google.com/d/msgid/elixir-lang-core/ef39ecfc-8e92-4bfa-8272-b78e354b3528%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
-- 
Morgan SEGALIS

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/CA%2BRjH_rU-T24VGvkFzzpHJqOCwfNiUABzKY2K343k8p92WNTsQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to