[Proposal] Bare lists with module attributes

49 views
Skip to first unread message

Brian Cardarella

unread,
Aug 21, 2016, 8:53:34 AM8/21/16
to elixir-lang-core
Currently module attributes require explicit syntax to be passed. For example:

```
@foobar [:a, :b, c: true]
```

It might be cleaner if we could get implied lists, keyword lists:

```
@foobar :a, :b, c: true
```

This comes into play when using module attributes for functionality purposes rather than just value storage.
For example, with ecto_fixtures I am working on an API relying upon the test module attributes:

```
@fixtures :user_1, :user_2, :user_3
@serialize only: [:user_1]
```

I suspect would be more idiomatic than

```
@fixtures [:user_1, :user_2, :user_3]
@serialize [only: [:user_1]]
```

If there is a desire for this I can handle implementation. I would just need to be pointed in the right direction. (I suspect starting with the tokenizer)

Andrea Leopardi

unread,
Aug 21, 2016, 1:16:44 PM8/21/16
to elixir-l...@googlegroups.com
Thanks for the proposal Brain,

I am -1 on this feature as I don't really see the benefit (just a very slight aesthetics thing) but I surely see the downside of having this "magic" going on. I prefer the explicitness of brackets if something is a list :P

Also, this may create confusion because then maybe  function arguments are just a list without brackets for syntactic sugar? This is a question I see myself asking as a newcomer.
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/f4fd785e-ab39-40b6-855d-adc2602988ff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

Andrea Leopardi

Eric Meadows-Jönsson

unread,
Aug 23, 2016, 9:46:14 AM8/23/16
to elixir-l...@googlegroups.com
Brian, keep in mind that `@serialize only: [:user_1]` already works because it's only one argument. But you cannot pass multiple arguments as for example `@fixtures :user_1, :user_2, :user_3`.


For more options, visit https://groups.google.com/d/optout.



--
Eric Meadows-Jönsson
Reply all
Reply to author
Forward
0 new messages