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

Support *dictionary literal* syntax #6162

Open
kazcw opened this issue Mar 31, 2023 · 2 comments
Open

Support *dictionary literal* syntax #6162

kazcw opened this issue Mar 31, 2023 · 2 comments
Assignees
Labels
-parser -syntax p-medium Should be completed in the next few sprints

Comments

@kazcw
Copy link
Contributor

kazcw commented Mar 31, 2023

E.g. foo = { x := 1, b := 2 }. This has also been referred to as "typeset literals".

@kazcw kazcw added p-medium Should be completed in the next few sprints -syntax -parser labels Mar 31, 2023
@kazcw kazcw self-assigned this Mar 31, 2023
@jdunkerley jdunkerley added this to the Beta Release milestone Apr 4, 2023
@wdanilo
Copy link
Member

wdanilo commented Apr 4, 2023

Please note that the syntax is not final and there is a discussion about what it should look like.

@jdunkerley jdunkerley removed this from the Beta Release milestone Jul 18, 2023
@JaroslavTulach JaroslavTulach changed the title Support *map literal* syntax Support *dictionary literal* syntax Jul 17, 2024
@JaroslavTulach
Copy link
Member

JaroslavTulach commented Jul 17, 2024

Following syntax is supported right now, without any changes to the parser:

main = Dictionary.empty <<
    [ "x"~~10, "y"~~20, "z"~~3 ]

prints out {'y'=20, 'z'=3, 'x'=10}. All that's needed is to define these extension methods:

Dictionary.<< self add:Pair|Vector = case add of
    pair:Pair -> self.insert pair.first pair.second
    vector -> vector.fold self m-> p->
        m << p

Any.~~ self second = Pair.new self second

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-parser -syntax p-medium Should be completed in the next few sprints
Projects
Status: 📤 Backlog
Development

No branches or pull requests

4 participants