<div dir="ltr">Found this year-old question while looking for any leads on the maps comprehension status..<div><br></div><div>LYSE does have a "PS" chapter, that seems to suggest the work wasn't finished yet at the time of writing (R17):</div><div><a href="http://learnyousomeerlang.com/maps#what-maps-shall-be">http://learnyousomeerlang.com/maps#what-maps-shall-be</a><br></div><div><br></div><div>...and the EEP-43 linked is status 'draft'.</div><div><br></div><div>The code in LYSE fails with a syntax error, too. Though that's not a map but a list comprehension, it seems to be related to using the map as a data source for the generator expression:</div><br>9> Weather = #{toronto => rain, montreal => storms, london => fog, paris => sun, boston => fog, vancouver => snow}.<div>10> FoggyPlaces = [X || X := fog <- Weather].<br></div><div>
<p class="gmail-p1"><span class="gmail-s1">* 1: syntax error before: ':='</span></p><p class="gmail-p1"><span class="gmail-s1">- the best I can infer from it is the usage of ":=" operator is illegal in this context (which would imply map comprehensions aren't supported).</span></p><p class="gmail-p1">This wasn't entirely unexpected, I did run in something similar with maps examples presented in PE 2ed, which were supposed to work very soon, but still don't, and they also had to do with map de-structuring/pattern matching.<br></p><p class="gmail-p1">(I ended up getting the expected result this way: 15> FoggyPlaces = [X || {X, Y} <- maps:to_list(Weather), Y == fog].)</p><p class="gmail-p1">
</p><p class="gmail-p1">Creating a map with a comprehension isn't yet possible, too, it seems:<br></p><p class="gmail-p1"><span class="gmail-s1">43> #{X => foggy || X <- [london,boston]}.</span></p><p class="gmail-p1">
</p><p class="gmail-p1"><span class="gmail-s1">* 1: syntax error before: '||'</span></p><p class="gmail-p1">Again, this seems to suggest that "=>" isn't legal in this syntactic context.</p><p class="gmail-p1">So, while the answer to the old question below remains correct - the person asking was trying to create a very esoteric map =) but even without that issue, things don't work as it was hinted they will in the near future. Anyone can provide any insight on the state of maps?<br></p><p class="gmail-p1">The reason I am interested in getting to the bottom of this is, I want to know if the problem is with Erlang syntax, or is it due to some issues related to the runtime system itself; in the former case, I could explore Elixir or LFE, but in the latter, I just need to wait for EEP to move forward =)</p><p class="gmail-p1">Thank you.<br></p></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jun 22, 2016 at 8:59 PM, Richard A. O'Keefe <span dir="ltr"><<a href="mailto:ok@cs.otago.ac.nz" target="_blank">ok@cs.otago.ac.nz</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-"><br>
<br>
On 23/06/16 7:22 AM, Sachin Panemangalore wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Hi<br>
A question on comprehension in erlang in general.<br>
<br>
[{X,Y} || X<-[1,2,3], Y<-[a,b,c]]. works<br>
<br>
but<br>
<br>
#{X=>Y || X<-[1,2,3], Y<-[a,b,c] } does not<br>
<br>
any specific reason why this was not implemented ( since Erlang is relative mature my guess is its a design choice by the creators of Erlang ).<br>
<br>
</blockquote></span>
What is it supposed to mean? Expanding the generators out,<br>
#{ 1 => a, 1 => b, 1 => c, 2 => a, 2 => b, 2 => c, 3 => a, 3 => b, 3 => c }<br>
is not really a meaningful map.<br>
______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/list<wbr>info/erlang-questions</a><br>
</blockquote></div><br></div></div>