defrequired and defoptional instead of @enforce_keys and defstruct

33 views
Skip to first unread message

Juan Jose Lopez Tugores

unread,
Dec 24, 2017, 4:59:21 PM12/24/17
to elixir-lang-core
For example instead of

defmodule Foo do
    @enforce_keys [:foo1, :foo2] 
    defstruct [:foo1, :foo2, :foo3] 
 end

I write

defmodule Foo do 
    @required_keys [:foo1, :foo2] 
    @optional_keys [:foo3] 
    @enforce_keys @required_keys 
    defstruct @required_keys ++ @optional_keys 
 end

But I think it could better be
 
defmodule Foo do 
    defrequired [:foo1, :foo2]
    defoptional [:foo3] 
 end 

José Valim

unread,
Dec 24, 2017, 5:07:58 PM12/24/17
to elixir-l...@googlegroups.com
Hi!

If you would like to propose features to the language, you need to *argue* why those changes are beneficial. Changes to existing language features can cause a huge impact in the community and we need strong reasons for them.

Thanks.


José Valim
Founder and 
Director of R&D

--
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/f84f2f1a-e04b-4673-a88b-b35c9f9fa482%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Louis Pilfold

unread,
Dec 24, 2017, 5:13:05 PM12/24/17
to elixir-l...@googlegroups.com

Hi there

Perhaps this could be implemented in a library as a macro, rather than introducing a breaking change into the core language :)

Cheers,
Louis


To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.

--
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-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4LOQBw9SmfHHf21Cvmd%2BOjLtS3p0892Of7u-kmUaqxtXw%40mail.gmail.com.
Message has been deleted

Juan Jose Lopez Tugores

unread,
Dec 24, 2017, 5:48:51 PM12/24/17
to elixir-lang-core
Hi José the main reason I see is merely estetic and is to avoid retyping the "@enforced_keys" in "defstruct" but you're right: I have not measured the impact on the ecosystem. For that reason, as Louis said,  it could better fit in a library.

Thank you for your feedback guys :)
Reply all
Reply to author
Forward
0 new messages