[erlang-questions] [erlang-question][maps][comprehension]

Alexandre Karpov alexakarpov@REDACTED
Thu Nov 23 22:09:46 CET 2017

Found this year-old question while looking for any leads on the maps
comprehension status..

LYSE does have a "PS" chapter, that seems to suggest the work wasn't
finished yet at the time of writing (R17):

...and the EEP-43 linked is status 'draft'.

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:

9> Weather = #{toronto => rain, montreal => storms, london => fog, paris =>
sun, boston => fog, vancouver => snow}.
10> FoggyPlaces = [X || X := fog <- Weather].

* 1: syntax error before: ':='

- 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).

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

(I ended up getting the expected result this way: 15> FoggyPlaces = [X ||
{X, Y} <- maps:to_list(Weather), Y == fog].)

Creating a map with a comprehension isn't yet possible, too, it seems:

43> #{X => foggy || X <- [london,boston]}.

* 1: syntax error before: '||'

Again, this seems to suggest that "=>" isn't legal in this syntactic

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?

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 =)

Thank you.

On Wed, Jun 22, 2016 at 8:59 PM, Richard A. O'Keefe <ok@REDACTED>

> On 23/06/16 7:22 AM, Sachin Panemangalore wrote:
>> Hi
>> A question on comprehension in erlang in general.
>> [{X,Y} || X<-[1,2,3], Y<-[a,b,c]].   works
>> but
>> #{X=>Y || X<-[1,2,3], Y<-[a,b,c] }  does not
>> 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 ).
>> What is it supposed to mean?  Expanding the generators out,
> #{ 1 => a, 1 => b, 1 => c, 2 => a, 2 => b, 2 => c, 3 => a, 3 => b, 3 => c }
> is not really a meaningful map.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20171123/0987957b/attachment.htm>

More information about the erlang-questions mailing list