Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

map(key, key, ...) on the left side of a pattern and in expressions/right side #156

Closed
kvakvs opened this issue Jul 12, 2017 · 5 comments
Closed
Assignees
Labels
enhancement hacktoberfest Great tickets for Hacktoberfest rule started
Milestone

Comments

@kvakvs
Copy link

kvakvs commented Jul 12, 2017

Having:
#{key := A, x := X, y := Y, key := B} = ZZZ,
on the left of a pattern is not an error but can be very confusing. It could be a warning.

Having it on the right side of a pattern, or in a free-standing expression — is not an error but most likely is a sign of a typo, or a copy-paste error.
ZZZ = #{key => A, x => xxx, y => yyy, key => B}

@paulo-ferraz-oliveira
Copy link
Collaborator

I don't see how #{key := A, x := X, y := Y, key := B} = ZZZ can "be very confusing". It's pattern-matching at its best.

If I understand your message well, there's some confusion here.

The first clause is pattern-matching. The second clause is single variable assignment.

@elbrujohalcon
Copy link
Member

@paulo-ferraz-oliveira it's related to this. Notice the repetition of key in the first pattern.

@paulo-ferraz-oliveira
Copy link
Collaborator

paulo-ferraz-oliveira commented Sep 11, 2020

@paulo-ferraz-oliveira it's related to this. Notice the repetition of key in the first pattern.

Oh, I got it. Them details...

In any case, what's so wrong about assigning to two different variables? You'll eventually either use both or only one (if using only one the compiler will already warn you). Is the confusion part the fact that they hold the same value for different names?

@paulo-ferraz-oliveira paulo-ferraz-oliveira self-assigned this Oct 9, 2020
@elbrujohalcon
Copy link
Member

Assigning the same value to 2 variables can be done like this…

#{key := A = B, x := X, y := Y} = ZZZ,

…which is, at least, more explicit.

@elbrujohalcon elbrujohalcon transferred this issue from inaka/elvis Jan 7, 2021
@elbrujohalcon elbrujohalcon added hacktoberfest Great tickets for Hacktoberfest rule labels Feb 3, 2022
@elbrujohalcon elbrujohalcon modified the milestones: 1.3.0, 1.4.0 May 26, 2022
@elbrujohalcon
Copy link
Member

This is already taken care of by the Erlang compiler. It emits warnings such as…

your_module.erl:9:60: Warning: key 'a' will be overridden in expression
%    9|     Other = NewMap#{even := using, different => accessors, a => "arrow", a := "not arrow"},
%     |                                                            ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement hacktoberfest Great tickets for Hacktoberfest rule started
Projects
None yet
Development

No branches or pull requests

3 participants