User Tools

Site Tools


This is an old revision of the document!

Notes while learning Elixir


Elixir's syntax is too flexible for my taste. For example, () are optional around arguments in function calls. I am happy that mix format now adds them!


The import statement defaults to importing all public names in the module, an unsafe default.

To limit the imported names, this ugly syntax is required:

import MyModule, only: [MyFunc: 1]

What I don't like about the syntax above:

* The comma after the MyModule. It's there because import is a macro, and only: […] is the second argument (more about that below). Maybe I'll accept it or (get used to it) when I learn to code macros. For a beginner, that comma is just strange.

* The colon after only. That's because the second argument is actually a keyword list (or whatever it's called, I'm not sure about the name of that now). The full syntax would be {:only, x}, but there's this syntactic sugar that allows spelling such lists without the braces and comma, when they appear as the trailing arguments in a function or macro call.

* The list [MyFunc: 1] to specify a function with arity 1. Why not MyFunc/1, the syntax used by the capture operator &?

notes_while_learning_elixir.1534121828.txt.gz · Last modified: 2018/08/12 17:57 by luciano