Skip to content

Commit f9bf9de

Browse files
committed
Use "fenced blocks" on code
Instead of {% highlight erlang %} use ```erlang ``` And use iex to command line stuff
1 parent f4f017e commit f9bf9de

16 files changed

+1456
-1091
lines changed

_posts/2012-12-04-elixir-v0-7-2-released.markdown

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ the type specification syntax.
1414

1515
Here's the gist:
1616

17-
{% highlight elixir %}
17+
```elixir
1818
@spec myfun(integer), do: integer
1919
# becomes
2020
@spec myfun(integer) :: integer
@@ -34,7 +34,7 @@ Here's the gist:
3434
@type a :: fun(integer, integer, do: integer)
3535
# becomes
3636
@type a :: (integer, integer -> integer) or ((integer, integer) -> integer) or (fun(integer, integer) -> integer)
37-
{% endhighlight %}
37+
```
3838

3939
Another change is that Mix now echoes the output of external tools
4040
such as git and rebar, and handles exit status correctly. This have previously
@@ -50,4 +50,4 @@ under some circunstances when using records.
5050

5151
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!
5252

53-
[Learn more about Elixir](/getting_started/1.html)!
53+
[Learn more about Elixir](/getting_started/1.html)!

_posts/2013-01-27-elixir-v0-8-0-released.markdown

+11-11
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ We have written a whole [guide chapter about creating OTP applications, supervis
2424

2525
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:
2626

27-
{% highlight elixir %}
27+
```elixir
2828
String.capitalize("fiN") #=> "Fin"
29-
{% endhighlight %}
29+
```
3030

3131
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).
3232

@@ -36,35 +36,35 @@ Learn more about [Unicode support with the String module](http://elixir-lang.org
3636

3737
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:
3838

39-
{% highlight elixir %}
39+
```elixir
4040
quote do: hello("world")
4141
{ :hello, [], ["world"] }
42-
{% endhighlight %}
42+
```
4343

4444
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".
4545

4646
By default, `quote` does not annotate line numbers, but we can pass it as an option:
4747

48-
{% highlight elixir %}
48+
```elixir
4949
quote line: __ENV__.line, do: hello("world")
5050
{ :hello, [line: 9], ["world"] }
51-
{% endhighlight %}
51+
```
5252

5353
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...
5454

5555
## Macros expansion
5656

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.
5858

5959
Imagine you manually implemented `unless` as a macro, that does the opposite of `if`:
6060

61-
{% highlight elixir %}
61+
```elixir
6262
defmacro unless(expr, opts) do
6363
quote do
6464
if(!unquote(expr), unquote(opts))
6565
end
6666
end
67-
{% endhighlight %}
67+
```
6868

6969
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.
7070

@@ -93,11 +93,11 @@ For each number of keys, we have measured and normalized those values against `H
9393
`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).
9494

9595
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+
9797
## Wrapping up
9898

9999
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.
100100

101101
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!
102102

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)!

_posts/2013-04-29-elixir-v0-8-2-released.markdown

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ We have also added colored output to Interactive Elixir (IEx) but it requires Er
1616

1717
Finally, Elixir has always given special attention to documentation. You can easily document functions with the `@doc` attribute:
1818

19-
{% highlight elixir %}
19+
```elixir
2020
defmodule Math do
2121
@doc """
2222
Add two numbers together.
@@ -31,18 +31,18 @@ defmodule Math do
3131
a + b
3232
end
3333
end
34-
{% endhighlight %}
34+
```
3535

3636
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.
3737

3838
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:
3939

40-
{% highlight elixir %}
40+
```elixir
4141
defmodule MathTest do
4242
use ExUnit.Case, async: true
4343
doctest Math
4444
end
45-
{% endhighlight %}
45+
```
4646

4747
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).
4848

_posts/2013-05-23-elixir-v0-9-0-released.markdown

+10-10
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ Let's talk about the goodies!
1818

1919
We have spent some time improving compilation time. The particular scenario we have worked on was the definition of records:
2020

21-
{% highlight elixir %}
21+
```elixir
2222
defrecord User, name: nil, age: nil
23-
{% endhighlight %}
23+
```
2424

2525
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.
2626

@@ -52,10 +52,10 @@ A special thanks to [Eric Meadows-Jonsson](https://github.com/ericmj) for implem
5252

5353
Elixir v0.9.0 changes its main abstraction for enumeration from iterators to reducers. Before Elixir v0.9.0, when you invoked:
5454

55-
{% highlight elixir %}
55+
```elixir
5656
Enum.map([1,2,3], fn(x) -> x * x end)
5757
#=> [1, 4, 9]
58-
{% endhighlight %}
58+
```
5959

6060
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.
6161

@@ -69,7 +69,7 @@ Reducers solve all of those problems by using a more functional approach. Instea
6969

7070
Here is how we implement the `Enumerable` protocol for lists:
7171

72-
{% highlight elixir %}
72+
```elixir
7373
defimpl Enumerable, for: List do
7474
def reduce(list, acc, fun) do
7575
do_reduce(list, acc, fun)
@@ -83,27 +83,27 @@ defimpl Enumerable, for: List do
8383
acc
8484
end
8585
end
86-
{% endhighlight %}
86+
```
8787

8888
The implementation above works as a simple `reduce` function (also called `fold`, `inject` or `foldl` in other languages). Here is how it works:
8989

90-
{% highlight elixir %}
90+
```elixir
9191
# Sum all elements in a list
9292
Enumerable.reduce([1,2,3], 0, fn(x, acc) -> x + acc end)
9393
#=> 6
94-
{% endhighlight %}
94+
```
9595

9696
The `Enum.map/2` we have used above is now implemented in terms of this reducing function:
9797

98-
{% highlight elixir %}
98+
```elixir
9999
defmodule Enum do
100100
def map(collection, fun) do
101101
Enumerable.reduce(collection, [], fn(x, acc) ->
102102
[fun.(x, acc)|acc]
103103
end) |> reverse
104104
end
105105
end
106-
{% endhighlight %}
106+
```
107107

108108
This approach solves all the problems above:
109109

_posts/2013-07-13-elixir-v0-10-0-released.markdown

+10-10
Original file line numberDiff line numberDiff line change
@@ -12,47 +12,47 @@ Elixir v0.10.0 is released with support for streams, sets and many improvements
1212

1313
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:
1414

15-
{% highlight elixir %}
15+
```elixir
1616
Enum.map([1,2,3], fn(x) -> x * 2 end)
1717
#=> [2,4,6]
18-
{% endhighlight %}
18+
```
1919

2020
The `Enum` module performs eager evaluation. Consider the following example:
2121

22-
{% highlight elixir %}
22+
```elixir
2323
[1,2,3]
2424
|> Enum.take_while(fn(x) -> x < 3 end)
2525
|> Enum.map(fn(x) -> x * 2 end)
2626
#=> [2,4]
27-
{% endhighlight %}
27+
```
2828

2929
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.
3030

3131
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:
3232

33-
{% highlight elixir %}
33+
```elixir
3434
[1,2,3]
3535
|> Stream.take_while(fn(x) -> x < 3 end)
3636
|> Stream.map(fn(x) -> x * 2 end)
3737
#=> #Stream.Lazy<...>
38-
{% endhighlight %}
38+
```
3939

4040
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.
4141

4242
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:
4343

44-
{% highlight elixir %}
44+
```elixir
4545
File.stream!("README.md")
46-
{% endhighlight %}
46+
```
4747

4848
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.
4949

5050
Do you need a random number generator? We got your back:
5151

52-
{% highlight elixir %}
52+
```elixir
5353
Stream.repeatedly(fn -> :random.uniform end) |> Enum.take(3)
5454
#=> [0.4435846174457203, 0.7230402056221108, 0.94581636451987]
55-
{% endhighlight %}
55+
```
5656

5757
`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).
5858

0 commit comments

Comments
 (0)