I suspect it's an elementary question, but it's been hard to find a succinct, canonical answer online.
From what little I understand;
Can anyone clarify?
12.3) A keyword list is a list that consists exclusively of two-element tuples. The first element of these tuples is known as the key, and it must be an atom. The second element, known as the value, can be any term.
here's a lightweight explanation of 'use' in elixir as I currently understand it. Use is a tool to reuse code just like require, import, and alias. Use simply calls the __using__ macro defined in another module. The __using__ macro allows you to inject code into another module.
12.3) Macros are compile-time constructs that are invoked with Elixir's AST as input and a superset of Elixir's AST as output. Let's see a simple example that shows the difference between functions and macros: defmodule Example do defmacro macro_inspect(value) do IO.
Adding Elixir to existing Erlang programs Elixir compiles into BEAM byte code (via Erlang Abstract Format). This means that Elixir code can be called from Erlang and vice versa, without the need to write any bindings. All Elixir modules start with the Elixir.
It require
s the given module and then calls the __using__/1
callback on it allowing the module to inject some code into the current context. See https://elixir-lang.org/getting-started/alias-require-and-import.html#use.
Example:
defmodule Test do
use Utility, argument: :value
end
is about the same as
defmodule Test do
require Utility
Utility.__using__(argument: :value)
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With