Skip to content

Commit 1c08705

Browse files
committed
various corrections in Crash Course
1 parent 35feb3d commit 1c08705

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

crash-course.markdown

+17-10
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ is_atom(''). %=> true
226226
```elixir
227227
is_atom :ok #=> true
228228
is_atom :'ok' #=> true
229+
is_atom Ok #=> true
229230
is_atom :"Multiple words" #=> true
230231
is_atom :"" #=> true
231232
```
@@ -242,8 +243,8 @@ That said, Elixir does not import the default `element` and `setelement` functio
242243
**Erlang**
243244

244245
```erlang
245-
element(1, {a, b, c}) %=> a
246-
setelement(1, {a, b, c}, d) %=> {d, b, c}
246+
element(1, {a, b, c}). %=> a
247+
setelement(1, {a, b, c}, d). %=> {d, b, c}
247248
```
248249

249250
**Elixir**
@@ -294,14 +295,17 @@ Elixir offers a literal syntax for creating a list of two-item tuples where the
294295
**Erlang**
295296

296297
```erlang
297-
[{another_key, 20}, {key, 10}]
298+
Proplist = [{another_key, 20}, {key, 10}].
299+
proplists:get_value(another_key, Proplist).
300+
%=> 20
298301
```
299302

300303
**Elixir**
301304

302305
```elixir
303306
kw = [another_key: 20, key: 10]
304-
kw[:another_key] #=> 20
307+
kw[:another_key]
308+
#=> 20
305309
```
306310

307311
### Maps
@@ -311,10 +315,11 @@ Erlang R17 introduced maps, a key-value store, with no ordering. Keys and values
311315
**Erlang**
312316

313317
```erlang
314-
Map = #{key => 0}
315-
Updated = Map#{key := 1}
316-
#{key := Value} = Updated
317-
Value =:= 1
318+
Map = #{key => 0}.
319+
Updated = Map#{key := 1}.
320+
#{key := Value} = Updated.
321+
Value =:= 1.
322+
%=> true
318323
```
319324

320325
**Elixir**
@@ -324,6 +329,7 @@ map = %{:key => 0}
324329
map = %{map | :key => 1}
325330
%{:key => value} = map
326331
value === 1
332+
#=> true
327333
```
328334

329335
If the keys are all atoms, Elixir allows developers to use `key: 0` for defining the map as well as using `.key` for accessing fields:
@@ -456,7 +462,7 @@ Pattern matching in Elixir is based on Erlang's implementation and in general is
456462

457463
```erlang
458464
loop_through([H|T]) ->
459-
io:format '~p~n', [H],
465+
io:format('~p~n', [H]),
460466
loop_through(T);
461467

462468
loop_through([]) ->
@@ -625,6 +631,7 @@ f.({:a, :b})
625631
#=> "All your {:a, :b} are belong to us"
626632
```
627633

634+
628635
### First-class functions
629636

630637
Anonymous functions are first-class values, so they can be passed as arguments to other functions and also can serve as a return value. There is a special syntax to allow named functions be treated in the same manner.
@@ -654,6 +661,7 @@ Enum.map [1, 2, 3], &Math.square/1
654661
#=> [1, 4, 9]
655662
```
656663

664+
657665
### Partials in Elixir
658666

659667
Elixir supports partial application of functions which can be used to define anonymous functions in a concise way:
@@ -676,7 +684,6 @@ defmodule Math do
676684
end
677685

678686
Enum.map [1, 2, 3], &Math.square/1
679-
680687
#=> [1, 4, 9]
681688
```
682689

0 commit comments

Comments
 (0)