#Sugar for keyword list as options in `defmacro __using__`

15 messages · Page 1 of 1 (latest)

thorny marsh
#

Wondering if something is missing here. The following works fine:

  use Project.Base, [
    no_header?: true,
    no_footer?: true
  ]

But this does not:

  use Project.Base,
    no_header?: true,
    no_footer?: true

The module defining the macro looks like:

defmodule Project.Base do
  defmacro __using__(opts \\ []) do
    # ...
  end
end
white lily
#

id also suggest considering header: false, footer: false instead

thorny marsh
#

Huh, I had hoped between the comma and the arity it would figure it out, but fair enough.

#

Yeah the naming was just an example. ^^

white lily
#

basically elixir use Project.Base, no_header?: true, no_footer?: true is the same as elixir use(Project.Base, [no_header?: true], [no_footer?: true])

thorny marsh
#

Right on, makes sense. Thanks!

white lily
bold sorrel
#
iex(1)> quote do
...(1)> use Foo, 
...(1)>   no_header?: true,
...(1)>   no_footer?: true
...(1)> end
{:use, [context: Elixir, imports: [{1, Kernel}, {2, Kernel}]],
 [{:__aliases__, [alias: false], [:Foo]}, [no_header?: true, no_footer?: true]]}
iex(2)> Macro.to_string(v(1))
"use Foo, no_header?: true, no_footer?: true"
#

Works for me, so @thorny marsh this should work without [] as well

white lily
#

cause it appears we have agreement on behaviour between a .ex file and the code executed in livebook in regards to outcome and interpretation of arguments

bold sorrel
#

I do not get what you are asking for there