Skip to content

Commit f24ac61

Browse files
author
José Valim
committed
Update crash-course.markdown
1 parent c4ba26f commit f24ac61

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

crash-course.markdown

+6-14
Original file line numberDiff line numberDiff line change
@@ -327,31 +327,23 @@ lines.
327327
"""
328328
{% endhighlight %}
329329

330-
### Keyword list (Orddict)
330+
### Keyword list
331331

332-
Orddicts in Erlang are created using either `orddict:new/0` or `orddict:from_list/1` while Elixir offers a literal syntax and calls them keyword lists:
332+
Elixir offers a literal syntax for creating a list of two-item tuples where the first item in the tuple is an atom and calls them keyword lists:
333333

334334
**Erlang**
335335

336336
{% highlight erlang %}
337-
Dict = orddict:new(),
338-
Dict1 = orddict:store(key, 10, Dict),
339-
Dict2 = orddict:store(another_key, 20, Dict1).
340-
%=> [{another_key,20},{key,10}]
341-
342-
Dict = orddict:from_list([{key, 10}, {another_key, 20}]).
343-
%=> [{another_key,20},{key,10}]
337+
[{another_key,20},{key,10}]
344338
{% endhighlight %}
345339

346340
**Elixir**
347341

348342
{% highlight elixir %}
349-
dict = [another_key: 20, key: 10]
350-
#=> [another_key: 20, key: 10]
343+
kw = [another_key: 20, key: 10]
344+
kw[:another_key] #=> 20
351345
{% endhighlight %}
352346

353-
Their internal representation is the same though. Both are made of a list of tuples.
354-
355347
### Records
356348

357349
The syntax for records differs significantly between Erlang and Elixir. Please refer to [this section][1] in the Erlang book to read a detailed introduction to records in Erlang. And [this chapter][2] from Elixir's Getting Started guide provides a description of records in Elixir.
@@ -500,7 +492,7 @@ When defining a function with the same name multiple times, each such definition
500492

501493
Elixir doesn't require punctuation to separate clauses, but they must be grouped together.
502494

503-
### Function Overloading
495+
### Identifying functions
504496

505497
In both Erlang and Elixir, a function is not identified only by its name, but by its name and arity. In both examples below, we are defining four different functions (all named `sum`, but with different arity):
506498

0 commit comments

Comments
 (0)