May 2018
Intermediate to advanced
412 pages
9h 3m
English
Elixir is lexically scoped. The basic unit of scoping is the function body. Variables defined in a function (including its parameters) are local to that function. In addition, modules define a scope for local variables, but these are accessible only at the top level of that module, and not in functions defined in the module.
Most languages let you group together multiple code statements and treat them as a single code block. Often languages use braces for this. Here’s an example in C:
| | int line_no = 50; |
| | |
| | /* ..... */ |
| | |
| | if (line_no == 50) { |
| | printf("new-page\f"); |
| | line_no = 0; |
| | } |
Elixir doesn’t really have blocks such as these, but it does have ways of grouping expressions together. The most common ...
Read now
Unlock full access