Syntactic sugar map idea

Just a random idea that keeps popping up in my head whenever I am pattern matching on maps. In Javascript es6 notation, there is this concept of a shorthand format to create objects, which I find very concise:

// pre es6
const someObject = {cat: cat, dog: dog, bird: bird}

// es6
const someObject = {cat, dog, bird}

Whenever I am pattern matching in Elixir I wonder how handy this would be to have, say:

def decorate_name(%{id, firstname, lastname}) do
  "Hi, #{firstname} #{lastname}"
end 

As opposed to

def decorate_name(%{id: id, firstname: firstname, lastname: lastname}) do
  "Hi, #{firstname} #{lastname}"
end 

Any thoughts?

It’s been proposed many times, there’s a couple libraries on Hex for it. This is a good read about it: https://andrealeopardi.com/posts/a-story-of-regret-and-retiring-a-library-from-hex/.

9 Likes

Sorry, did not know that. Thanks!

TANSTAAFL I’m afraid.

2 Likes

Thanks for the link… It was interesting to read.

Hello co-creator of Erlang!! It’s a pleasure!

Just googled that acronym… What are the “cost” you are implying?

I got a result… A German Wikipediapage, which linked to this: https://en.wikipedia.org/wiki/There_ain't_no_such_thing_as_a_free_lunch

1 Like

I think the paper referenced by @wojtekmach gives a good example of a “cost” of a feature.

1 Like