Where is the syntax
defstruct ~w[..]a
defined ?
Where is the syntax
defstruct ~w[..]a
defined ?
Here ~w[foo bar]a
compiles to [:foo, :bar]
iex> ~w[foo bar]a
[:foo, :bar]
See docs for sigil_w/2
So the example from docs:
defmodule Post do
defstruct [:title, :content, :author]
end
could be written as
defmodule Post do
defstruct ~w[title content author]a
end
Thanks; just to double check, this actually has nothing to do with defstruct right? These ‘sigils’, they’re almost like reader macros, they transform the list/object that comes after it into another Elixir object ?
this actually has nothing to do with defstruct right?
right.
These ‘sigils’, they’re almost like reader macros
In fact they are macros for our convenience! =)
To be more correct: They transform the ast or string given into some elixir term, depending on if they’re implemented by a macro or by a function.