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

Demo: adding m[x] notation for indexing #9174

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

richcarl
Copy link
Contributor

This is just a proof of concept as a discussion point. We could easily have m[x] notation for looking up a value in a map (and possibly other data types), if we wanted to. It's no different grammatically from how it works in e.g. Python or Javascript.

f(X, Y) ->
    A=#{a => #{1=>a, 2=>b, 3=>c},
        b => #{1=>p, 2=>q, 3=>r},
        c => #{1=>x, 2=>y, 3=>z}},
    A[X][Y].

As people are using maps more and more, I see that there could be a case for adding this syntax now, as an alias for erlang:map_get/2, especially for accessing nested maps. Works in guards as well.

Copy link
Contributor

github-actions bot commented Dec 10, 2024

CT Test Results

    2 files     96 suites   1h 7m 50s ⏱️
2 172 tests 2 123 ✅ 48 💤 1 ❌
2 535 runs  2 484 ✅ 50 💤 1 ❌

For more details on these failures, see this check.

Results for commit 32cbe09.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

@bjorng bjorng added the team:LG Assigned to OTP language group label Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team:LG Assigned to OTP language group
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants