I have this modules where I'm trying to define a struct:
defmodule A do
defmodule B do
defstruct :id, :name
end
end
Why error?
undefined function defstruct/2
Why is this error?
Just check the official documentation in that matter.
You can use notation without square brackets, but you have be explicit and provide a keyword list. In example there are default values provided.
In your case :id, :name won't be keyword list and that's why compiler throw an error that you put there two arguments.
If you would do:
defmodule A do
defstruct id: nil, name: nil
end
It would works perfectly fine.
Otherwise use explicitly list.