__struct__/0,1 is not meant to return an AST. Using
Macro.to_string/1 might lead to incorrect error messages:
defmodule MyStruct do
def __struct__, do: {:ok, :one, :two}
def __struct__(_), do: {:ok, :one, :two}
end
iex> %MyStruct{}
** (CompileError) iex:2: expected MyStruct.__struct__/1 to
return a map with a :__struct__ key that holds the name
of the struct (atom), got: ok
Avoid splitting words that contain a hyphen into two lines,
since a space is added when docs are rendered in IEx and ExDoc.
Command used to detect this bug:
$ ag -- "\w-\n"
In a number of places in the docs (`!/`, `&&/2`, `Enum.all?`) the
concept of a truthy/falsy value is mentioned and briefly explained.
Let's have single place for that explanation and point to it
from those other places.
This commit adds the System.fetch_env/1 and System.fetch_env!/1
functions as per the discussion in
https://groups.google.com/forum/#!topic/elixir-lang-core/QGxEibK4y7Q.
I chose to keep using the same underlying implementation for fetch_env/1
as the one for get_env/1 because the number of lines would have been the
same but we would have added one function call.
I added a bodyless clause so that arguments are clearly named in the
documentation. I also added a is_atom/1 guard to the first function
clause so that we consistently check that the context is an atom.
And vice-versa.
Overriding a macro as a function (and vice-versa) might produce
undesired effects.
For example, it's not clear if the following code should or
should not raise:
defmodule Foo do
def foo, do: bar()
defmacro bar, do: :ok
defoverridable bar: 0
def bar, do: :ok
end
On top of that, `super` does not currently work for such cases.
This is part of an ongoing effort to forbid overriding macros
with functions and vice-versa. New checks will require the
overridable information to be stored more efficiently.
The current doc first describes in detail the _deprecated_ way to create a custom guard. Only after that's complete is there a small note saying that this isn't recommended, and instead to use `defguard`. This commit changes that order around to lead with the current recommended practice.