We have a few on our blog: https://cultivatehq.com/posts/tag/elixir/ . Some (especially the Phoenix/Elm ones) are a little out of date.
Ok, so trying to follow @AstonJ’s instructions on posting about blogs and here I am.
I mainly wanted to say that I just published something on nested modules, https://cultivatehq.com/posts/elixir-nested-modules-imports-and-aliases/ because I just discovered that aliases and imports from outer modules are also imported and aliased in the nested module.
I couldn’t find the behaviour documented anywhere. Did I just miss it?
Also wondering if this is deliberate or a side effect of how things are compiled.
I couldn’t find it either - also had a quick look in some of my books and not mentioned there either :101:
This is “documented” when we say that alias
, import
and require
are lexical. It means they do not care about functions, modules, conditionals, cases. At the moment they are defined, everything below the declaration in the same code branch will have the same aliases, imports, etc. So this is pretty much deliberate behaviour.
Of course, saying that the documentation is in the word “lexical” is a bit cryptic, so improvements to the Elixir documentation with examples are very welcome. Thank you!
Ah, here: https://hexdocs.pm/elixir/Kernel.SpecialForms.html#alias/2-lexical-scope
(Looks up lexical scope)
Thanks @josevalim. Makes sense. I’ll amend the post and maybe think about a documentation PR.
We’ve now launched a companion blog, Bytesize, for small bites (bytes - geddit?) of technical information: “today I learnt” or “just did this cool thing” type of posts. There’s a few Elixir posts on it already:
- Dealing with contact bounce from hardware switches (with Circuits GPIO): https://bytesize.cultivatehq.com/elixir/otp/nerves/2019/01/03/debounce-with-elixir.html
- Map ‘get and update’: https://bytesize.cultivatehq.com/elixir/2018/12/17/map-get-and-update.html
- Updating a map’s key: https://bytesize.cultivatehq.com/elixir/2018/12/17/map-puts-shorthand.html
I love this sort of thing, thank you for posting about it.
Couple more “Bytesize” Elixir related posts: