You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: crash-course.markdown
+17-10
Original file line number
Diff line number
Diff line change
@@ -226,6 +226,7 @@ is_atom(''). %=> true
226
226
```elixir
227
227
is_atom :ok#=> true
228
228
is_atom :'ok'#=> true
229
+
is_atom Ok#=> true
229
230
is_atom :"Multiple words"#=> true
230
231
is_atom :""#=> true
231
232
```
@@ -242,8 +243,8 @@ That said, Elixir does not import the default `element` and `setelement` functio
242
243
**Erlang**
243
244
244
245
```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}
247
248
```
248
249
249
250
**Elixir**
@@ -294,14 +295,17 @@ Elixir offers a literal syntax for creating a list of two-item tuples where the
294
295
**Erlang**
295
296
296
297
```erlang
297
-
[{another_key, 20}, {key, 10}]
298
+
Proplist= [{another_key, 20}, {key, 10}].
299
+
proplists:get_value(another_key, Proplist).
300
+
%=> 20
298
301
```
299
302
300
303
**Elixir**
301
304
302
305
```elixir
303
306
kw = [another_key:20, key:10]
304
-
kw[:another_key] #=> 20
307
+
kw[:another_key]
308
+
#=> 20
305
309
```
306
310
307
311
### Maps
@@ -311,10 +315,11 @@ Erlang R17 introduced maps, a key-value store, with no ordering. Keys and values
311
315
**Erlang**
312
316
313
317
```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
318
323
```
319
324
320
325
**Elixir**
@@ -324,6 +329,7 @@ map = %{:key => 0}
324
329
map = %{map |:key=>1}
325
330
%{:key=> value} = map
326
331
value ===1
332
+
#=> true
327
333
```
328
334
329
335
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
456
462
457
463
```erlang
458
464
loop_through([H|T]) ->
459
-
io:format'~p~n', [H],
465
+
io:format('~p~n', [H]),
460
466
loop_through(T);
461
467
462
468
loop_through([]) ->
@@ -625,6 +631,7 @@ f.({:a, :b})
625
631
#=> "All your {:a, :b} are belong to us"
626
632
```
627
633
634
+
628
635
### First-class functions
629
636
630
637
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.
0 commit comments