Add ~w(str0 str1 str2) equivalent for symbols.

62 views
Skip to first unread message

yuy...@gmail.com

unread,
May 24, 2016, 6:13:02 PM5/24/16
to elixir-lang-core
When using ecto-2.0, required fields must be a list of symbols therefore the code will look like this:
fields ~w(email password encrypted_password)
required [:email, password]

And in my humble opinion, it would be better if we can write it like:
fields ~w(email password encrypted_password)
required ~s(email password)

I know ~s is used for string right now, but I believe it's better if we can follow the Ruby's convention where s is used for symbols and w is q(quoted) is used for strings.

Any thought?

Ben Wilson

unread,
May 24, 2016, 6:21:51 PM5/24/16
to elixir-lang-core
~w(foo bar baz)a creates a list of atoms.

Ben Wilson

unread,
May 24, 2016, 6:22:30 PM5/24/16
to elixir-lang-core
You'll find documentation about what modifiers are supported in the docs http://elixir-lang.org/docs/master/elixir/Kernel.html#sigil_w/2

Definitely a good idea, that's why we can do it :)

José Valim

unread,
May 24, 2016, 6:38:35 PM5/24/16
to elixir-l...@googlegroups.com
As Ben said, you can use ~w(foo bar)a.
 
I know ~s is used for string right now, but I believe it's better if we can follow the Ruby's convention where s is used for symbols and w is q(quoted) is used for strings.

Elixir is not Ruby. Elixir doesn't have "symbols". It has atoms. Using s for symbols in Elixir does not make sense. 

yuy...@gmail.com

unread,
May 24, 2016, 8:52:15 PM5/24/16
to elixir-lang-core, jose....@plataformatec.com.br
Thanks for the reference. I should have searched more before asking. 
~w(foo bar)a is very understandable and cool.
Reply all
Reply to author
Forward
0 new messages