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}"

As opposed to

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

Any thoughts?

It’s been proposed many times, there’s a couple libraries on Hex for it. This is a good read about it:


Sorry, did not know that. Thanks!

TANSTAAFL I’m afraid.


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:'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