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: _posts/2012-12-04-elixir-v0-7-2-released.markdown
+3-3
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ the type specification syntax.
14
14
15
15
Here's the gist:
16
16
17
-
{% highlight elixir %}
17
+
```elixir
18
18
@specmyfun(integer), do: integer
19
19
# becomes
20
20
@specmyfun(integer) :: integer
@@ -34,7 +34,7 @@ Here's the gist:
34
34
@type a ::fun(integer, integer, do: integer)
35
35
# becomes
36
36
@type a :: (integer, integer -> integer) or ((integer, integer) -> integer) or (fun(integer, integer) -> integer)
37
-
{% endhighlight %}
37
+
```
38
38
39
39
Another change is that Mix now echoes the output of external tools
40
40
such as git and rebar, and handles exit status correctly. This have previously
@@ -50,4 +50,4 @@ under some circunstances when using records.
50
50
51
51
Lastly, but not least importantly, I'd like to mention that we're very excited about how the community around Elixir is building up. Thank you all for being around and supporting us!
52
52
53
-
[Learn more about Elixir](/getting_started/1.html)!
53
+
[Learn more about Elixir](/getting_started/1.html)!
Copy file name to clipboardExpand all lines: _posts/2013-01-27-elixir-v0-8-0-released.markdown
+11-11
Original file line number
Diff line number
Diff line change
@@ -24,9 +24,9 @@ We have written a whole [guide chapter about creating OTP applications, supervis
24
24
25
25
Elixir favors the use of utf-8 binaries since its first release. In the latest releases, we took it up a notch by adding Unicode support, built upon the Unicode Standard 6.2.0. Elixir v0.8 takes this even further, adding more convenience functions and better support to named sequences:
26
26
27
-
{% highlight elixir %}
27
+
```elixir
28
28
String.capitalize("fiN") #=> "Fin"
29
-
{% endhighlight %}
29
+
```
30
30
31
31
The example above contains a string with only two codepoints, [the codepoint fi](http://www.fileformat.info/info/unicode/char/FB01/index.htm) and [the codepoint n](http://www.fileformat.info/info/unicode/char/006E/index.htm). Look how Elixir properly capitalizes the string, returning a new string made of three codepoints (all ascii letters).
32
32
@@ -36,35 +36,35 @@ Learn more about [Unicode support with the String module](http://elixir-lang.org
36
36
37
37
As per this release, Elixir AST nodes can contain metadata. This metadata is compilation time only but may allow macros to annotate important information in AST nodes, like line numbers, file and other library specific information. If you quote an Elixir expression, we can see the metadata slot:
38
38
39
-
{% highlight elixir %}
39
+
```elixir
40
40
quotedo:hello("world")
41
41
{ :hello, [], ["world"] }
42
-
{% endhighlight %}
42
+
```
43
43
44
44
In the example above, we can see the AST representation of the expression `hello("world")`. It is made of a tuple of three elements, the first one is the function name represented by the atom `:hello`, the second one is a keyword list containing metadata (in this case, no metadata is available) and the third is a list of arguments, containing the string "world".
45
45
46
46
By default, `quote` does not annotate line numbers, but we can pass it as an option:
47
47
48
-
{% highlight elixir %}
48
+
```elixir
49
49
quoteline:__ENV__.line, do:hello("world")
50
50
{ :hello, [line:9], ["world"] }
51
-
{% endhighlight %}
51
+
```
52
52
53
53
Now, we can see the metadata spot being used to annotate the line number. This change allowed us to take our macros one step further...
54
54
55
55
## Macros expansion
56
56
57
-
Prior to this release, Elixir had limited expansion of imports and aliases. We decided this would be an important issue to tackle in this release, as people are building more and more projects on top of Elixir.
57
+
Prior to this release, Elixir had limited expansion of imports and aliases. We decided this would be an important issue to tackle in this release, as people are building more and more projects on top of Elixir.
58
58
59
59
Imagine you manually implemented `unless` as a macro, that does the opposite of `if`:
60
60
61
-
{% highlight elixir %}
61
+
```elixir
62
62
defmacrounless(expr, opts) do
63
63
quotedo
64
64
if(!unquote(expr), unquote(opts))
65
65
end
66
66
end
67
-
{% endhighlight %}
67
+
```
68
68
69
69
When some code call the `unless` macro above, in previous Elixir versions, it would expect the `if` macro to be available at the caller. This may not be necessarily true and, even worse, another implementation of the `if` macro, not compatible to the one above, could be available.
70
70
@@ -93,11 +93,11 @@ For each number of keys, we have measured and normalized those values against `H
93
93
`orddict` is still the faster representation for small ranges since it is a simple list. However, `HashDict` is able to be relatively fast compared to `orddict` for those small ranges and the fastest solution once you have dozens of keys. [Those results can be verified when using other types as keys as well](https://gist.github.com/436a9d2bca5051a6dfab).
94
94
95
95
Finally, given `HashDict` starts with a compact representation, it also takes less memory. Compared to the `dict` implementation, an empty `HashDict` takes only 5 words, while `dict` takes 47.
96
-
96
+
97
97
## Wrapping up
98
98
99
99
We continue actively working on Elixir and this release is the [result of our efforts on different areas](https://github.com/elixir-lang/elixir/blob/v0.8.0/CHANGELOG.md)! We have exciting plans and newer possibilities to explore, as a new release of Erlang OTP also comes out in a couple weeks.
100
100
101
101
Also, we previously announced Elixir is going to be released frequently, every 2 to 4 weeks. We have made a small detour to get v0.8.0 out of the door, but we are back to our regular schedule as of today!
102
102
103
-
[Celebrate with us and give Elixir a try](/getting_started/1.html)!
103
+
[Celebrate with us and give Elixir a try](/getting_started/1.html)!
Copy file name to clipboardExpand all lines: _posts/2013-04-29-elixir-v0-8-2-released.markdown
+4-4
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ We have also added colored output to Interactive Elixir (IEx) but it requires Er
16
16
17
17
Finally, Elixir has always given special attention to documentation. You can easily document functions with the `@doc` attribute:
18
18
19
-
{% highlight elixir %}
19
+
```elixir
20
20
defmoduleMathdo
21
21
@doc """
22
22
Add two numbers together.
@@ -31,18 +31,18 @@ defmodule Math do
31
31
a + b
32
32
end
33
33
end
34
-
{% endhighlight %}
34
+
```
35
35
36
36
The documentation above is embedded into the module and can be easily retrieved at runtime. For example, by typing `h Math.add/2` into Interactive Elixir, we can access the documentation for that module.
37
37
38
38
Elixir v0.8.2 takes this to the next level by adding support to doctests. Given the example above, you can configure Elixir to automatically run the code samples in your documentation by including a call to the `doctest` macro in your test suite:
39
39
40
-
{% highlight elixir %}
40
+
```elixir
41
41
defmoduleMathTestdo
42
42
useExUnit.Case, async:true
43
43
doctest Math
44
44
end
45
-
{% endhighlight %}
45
+
```
46
46
47
47
You can learn more about [doctests on our documentation page](http://elixir-lang.org/docs/stable/ExUnit.DocTest.html) and get more information about our latest release [on the CHANGELOG](https://github.com/elixir-lang/elixir/blob/ed27611f48ba150404c95fe15f1d6058a4287330/CHANGELOG.md).
Copy file name to clipboardExpand all lines: _posts/2013-05-23-elixir-v0-9-0-released.markdown
+10-10
Original file line number
Diff line number
Diff line change
@@ -18,9 +18,9 @@ Let's talk about the goodies!
18
18
19
19
We have spent some time improving compilation time. The particular scenario we have worked on was the definition of records:
20
20
21
-
{% highlight elixir %}
21
+
```elixir
22
22
defrecordUser, name:nil, age:nil
23
-
{% endhighlight %}
23
+
```
24
24
25
25
Records are a good scenario because they are implemented in Elixir, using Elixir macros, and they also define a module underneath, which exercises the Erlang VM compilation stack.
26
26
@@ -52,10 +52,10 @@ A special thanks to [Eric Meadows-Jonsson](https://github.com/ericmj) for implem
52
52
53
53
Elixir v0.9.0 changes its main abstraction for enumeration from iterators to reducers. Before Elixir v0.9.0, when you invoked:
54
54
55
-
{% highlight elixir %}
55
+
```elixir
56
56
Enum.map([1,2,3], fn(x) -> x * x end)
57
57
#=> [1, 4, 9]
58
-
{% endhighlight %}
58
+
```
59
59
60
60
It asked the `Enum.Iterator` protocol for instructions on how to iterate the list `[1,2,3]`. This iteration happened by retrieving each item in the list, one by one, until there were no items left.
61
61
@@ -69,7 +69,7 @@ Reducers solve all of those problems by using a more functional approach. Instea
69
69
70
70
Here is how we implement the `Enumerable` protocol for lists:
71
71
72
-
{% highlight elixir %}
72
+
```elixir
73
73
defimplEnumerable, for: Listdo
74
74
defreduce(list, acc, fun) do
75
75
do_reduce(list, acc, fun)
@@ -83,27 +83,27 @@ defimpl Enumerable, for: List do
83
83
acc
84
84
end
85
85
end
86
-
{% endhighlight %}
86
+
```
87
87
88
88
The implementation above works as a simple `reduce` function (also called `fold`, `inject` or `foldl` in other languages). Here is how it works:
89
89
90
-
{% highlight elixir %}
90
+
```elixir
91
91
# Sum all elements in a list
92
92
Enumerable.reduce([1,2,3], 0, fn(x, acc) -> x + acc end)
93
93
#=> 6
94
-
{% endhighlight %}
94
+
```
95
95
96
96
The `Enum.map/2` we have used above is now implemented in terms of this reducing function:
Copy file name to clipboardExpand all lines: _posts/2013-07-13-elixir-v0-10-0-released.markdown
+10-10
Original file line number
Diff line number
Diff line change
@@ -12,47 +12,47 @@ Elixir v0.10.0 is released with support for streams, sets and many improvements
12
12
13
13
The default mechanism for working with collections in Elixir is the `Enum` module. With it, you can map over ranges, lists, sets, dictionaries and any other structure as long as it implements the `Enumerable` protocol:
14
14
15
-
{% highlight elixir %}
15
+
```elixir
16
16
Enum.map([1,2,3], fn(x) -> x *2end)
17
17
#=> [2,4,6]
18
-
{% endhighlight %}
18
+
```
19
19
20
20
The `Enum` module performs eager evaluation. Consider the following example:
21
21
22
-
{% highlight elixir %}
22
+
```elixir
23
23
[1,2,3]
24
24
|>Enum.take_while(fn(x) -> x <3end)
25
25
|>Enum.map(fn(x) -> x *2end)
26
26
#=> [2,4]
27
-
{% endhighlight %}
27
+
```
28
28
29
29
In the example above, we enumerate the items in list once, taking all elements that are less than 3, and then we enumerate the remaining elements again, multiplying them by two. In order to retrieve the final result, we have created one intermediate list. As we add more operations, more intermediate lists will be generated.
30
30
31
31
This approach is simple and efficient for the majority of the cases but, when working with large collections, we can generate many, possibly large, intermediate lists affecting performance. That's one of the problems Streams solve. Let's rewrite the example above using Streams:
32
32
33
-
{% highlight elixir %}
33
+
```elixir
34
34
[1,2,3]
35
35
|>Stream.take_while(fn(x) -> x <3end)
36
36
|>Stream.map(fn(x) -> x *2end)
37
37
#=> #Stream.Lazy<...>
38
-
{% endhighlight %}
38
+
```
39
39
40
40
Now, instead of getting the result back, we got a Stream. The list elements are yet to be enumerated! We can realize the stream by calling any of the Enum functions, like `Enum.to_list/1`. By doing so the list will be iterated just once avoiding the intermediary representations.
41
41
42
42
In a nutshell, Streams are composable, lazy enumerables. Streams are also useful when doing IO or expressing infinite computations. We can retrieve a file as a stream:
43
43
44
-
{% highlight elixir %}
44
+
```elixir
45
45
File.stream!("README.md")
46
-
{% endhighlight %}
46
+
```
47
47
48
48
In the example above, we got a stream that will enumerate the lines in the file one by one when enumerated. We could further extend the stream above, for example, by rejecting blank lines, and the file will be opened just when its results are actually needed.
49
49
50
50
Do you need a random number generator? We got your back:
`Stream.repeatedly/1` returns an infinite stream but that's ok we just need its first three elements. You can learn more about [stream and related functions in `Stream` module documentation](http://elixir-lang.org/docs/stable/Stream.html).
0 commit comments