<div dir="ltr">2013/5/14 Loïc Hoguin <span dir="ltr"><<a href="mailto:essen@ninenines.eu" target="_blank">essen@ninenines.eu</a>></span><br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
On 05/14/2013 08:21 PM, Björn-Egil Dahlberg wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
2013/5/14 Loďc Hoguin <<a href="mailto:essen@ninenines.eu" target="_blank">essen@ninenines.eu</a> <mailto:<a href="mailto:essen@ninenines.eu" target="_blank">essen@ninenines.eu</a>>><div><div class="h5"><br>
    I personally would prefer a more powerful:<br>
       M#{ K #{ DK => DV }}<br>
<br>
    Because it allows you to write things like:<br>
       M#{ K #{ DK => DV }, K2 => V2 }<br>
<br>
    And update multiple levels at once.<br>
<br>
    I know K can be a map, but deep update only works on values, the<br>
    same way normal update only works on values, so no confusion is<br>
    possible, we're only updating values, not K itself. If you feel an<br>
    operator is needed it can be introduced between K and # in the two<br>
    examples above.<br>
<br>
    Programmatically this would translate as extracting the map found at<br>
    key K, and ensuring it's a map, updating this map with DK => DV,<br>
    then placing this map back into the key K in map M along with<br>
    setting V2 in key K2.<br>
<br>
    It doesn't sound hard to implement in the compiler, it's just<br>
    unrolling things for access and rolling back again for the actual<br>
    update. Exactly what we do manually today.<br>
<br>
    It should also be easy to compile to an optimized deep update with<br>
    this syntax as you got everything in a single expression.<br>
<br>
    Note: If you are not interested in it despite how simple it is<br>
    please at least ensure it can be done with a parse transform.<br>
<br>
    Thoughts?<br>
<br>
<br>
I think we want to be explicit here. Meaning using an operator and<br>
"seeing" the value in action. (I have bad memories of perl).<br>
<br>
Just some first thoughts on deep updates here to see if I get the<br>
intention right. What I think we need is someway to use an associated<br>
value within the map. I figure, something like "escaping" the key which<br>
would fetch the associated value. Let's use '~' in this example.<br>
<br>
Say I have a nested map like above, M = #{ a => #{ b => 1 }} and I would<br>
like to update the inner b value with it self plus four. I could write<br>
it like this:<br>
<br>
3> M#{ a := ~a#{ b := ~b + 4 }}.<br>
#{ a => #{ b => 5 }}<br>
<br>
Another possibility would perhaps be to bind values first (wrapped in {<br>
.. } )and then use them in updates, say<br>
<br>
M#{ a := M }{ a := M#{ b := V }{ b := V + 4 } }<br>
<br>
.. that looks even more horrible .. =)<br>
<br>
I haven't given this much thought but I'm trying to get a sense of it.<br>
Something like this?<br>
</div></div></blockquote>
<br>
That's taking it even further than I thought. I would be perfectly fine with binding separately from updating, especially because:<div class="im"><br>
<br>
  M#{ a := ~a#{ b := ~b + 4 }}.<br>
<br></div>
isn't so pretty when done with some key types like:<br>
<br>
  M#{ <<"a">> := ~<<"a">>#{ <<"b">> := ~<<"b">> + 4 }}. </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<br>
Now most of what I would be using would be atoms and integers, but this still would be the ugliest allowed syntax ever.<br></blockquote><div><br></div><div><div>I totally agree with you, it certainly lacks beauty.</div></div>
<div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
It works fine if done in two steps (with the first step most likely done in the function clause itself).<br>
<br>
doit(M=#{ a := A=#{ b := B }}) -><br>
  M#{ a := A#{ b := B + 4 }}.<br>
<br>
Writing this I realize it's quite possible that you can already do it with the current EEP. Am I right?<br></blockquote><div><br></div><div style>Yes.</div><div style> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<br>
And it also fits:<br>
<br>
doit(M=#{ a := A=#{ b := B }, aa := yes_do_it}) -><br>
  M#{ a := A#{ b := B + 4 }, aa := done}.<br>
<br>
You can already do this with records. Can we do this with maps too? This + any type as key + dynamic is all I need.<br></blockquote><div><br></div><div style>Yes. I had similar examples in the EEP but didn't nest the Maps.</div>
<div style> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
It would be cool if that could also be optimized at compile time, though that's more of an edge case so understandable if that comes later.</blockquote><div><br></div><div style>What was it you said to me? "Make it work, make it pretty, make it fast." =) Still on step oneish.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class=""><font color="#888888"><br>
<br>
-- <br>
Loďc Hoguin</font></span><div class=""><div class="h5"><br>
Erlang Cowboy<br>
Nine Nines<br>
<a href="http://ninenines.eu" target="_blank">http://ninenines.eu</a><br>
</div></div></blockquote></div><br></div></div>