Skip to content

Commit bb63a9c

Browse files
author
José Valim
committed
Try using elixir syntax highlight.
1 parent ea00d79 commit bb63a9c

File tree

2 files changed

+82
-61
lines changed

2 files changed

+82
-61
lines changed

_posts/2012-04-17-what-s-new-in-elixir-1.markdown

+47-37
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,44 @@
22
layout: post
33
title: What's New in Elixir #1
44
author: Alexei Sholik
5-
category: whatsnew
5+
category: "What's New in Elixir"
66
excerpt: Last week Elixir has seen a lot of new features, improvements, and bug fixes. In this little post I'm going to highlight some of the most prominent ones.
77
---
88

99
Last week Elixir has seen a lot of new features, improvements, and bug fixes. In this little post I'm going to highlight some of the most prominent ones.
1010

1111
* Access protocol has been added for tuples, lists, strings, and whatnot. It allows us to easily access elements of a collection. We can also use a regex to find the first match in a string or a list. Examples follow:
1212

13-
dict = [a: 1, b: 2, c: 3]
14-
dict[:a] #=> 1
15-
dict[:d] #=> nil
16-
tuple = {5, 4, 3, 2, 1}
17-
tuple[1] #=> 5
18-
tuple[0] #=> nil
19-
tuple[-1] #=> 1
20-
defrecord TestRec, red: 0, green: 0, blue: 0
21-
r = TestRec[red: 255, blue: 80] #=> new record
22-
s = "The quick brown fox jumps over the lazy dog."
23-
s[%r/[a-z]+o[a-z]+/] #=> "brown"
13+
```elixir
14+
dict = [a: 1, b: 2, c: 3]
15+
dict[:a] #=> 1
16+
dict[:d] #=> nil
17+
18+
tuple = {5, 4, 3, 2, 1}
19+
tuple[1] #=> 5
20+
tuple[0] #=> nil
21+
tuple[-1] #=> 1
22+
23+
defrecord TestRec, red: 0, green: 0, blue: 0
24+
r = TestRec[red: 255, blue: 80] #=> new record
25+
s = "The quick brown fox jumps over the lazy dog."
26+
s[%r/[a-z]+o[a-z]+/] #=> "brown"
27+
```
2428

2529
* Access protocol also makes it possible to pattern-match records:
2630

27-
defrecord TestRec, red: 0, green: 0, blue: 0
28-
r = TestRec[red: 255, blue: 80] #=> new record
29-
case r do
30-
match: TestRec[red: 0]
31-
:no_match
32-
match: TestRec[red: red, blue: 80]
33-
:ok
34-
end
35-
#=> :ok
36-
red === 255 #=> true
31+
```elixir
32+
defrecord TestRec, red: 0, green: 0, blue: 0
33+
r = TestRec[red: 255, blue: 80] #=> new record
34+
case r do
35+
match: TestRec[red: 0]
36+
:no_match
37+
match: TestRec[red: red, blue: 80]
38+
:ok
39+
end
40+
#=> :ok
41+
red === 255 #=> true
42+
```
3743

3844
* The `Orddict` module is no longer with us, it has been renamed to `Keyword`. The new module only allows atoms to be used as keys. A general purpose module for dicts will be added sooner or later.
3945

@@ -43,24 +49,28 @@ Last week Elixir has seen a lot of new features, improvements, and bug fixes. In
4349

4450
* Support for nested modules has been added.
4551

46-
defmodule Father do
47-
defmodule Child do
48-
def child_fun(str) do
49-
IO.puts str
50-
end
51-
end
52-
def fun do
53-
Child.child_fun "some argument"
54-
end
55-
end
56-
Father.Child.child_fun "hello!"
52+
```elixir
53+
defmodule Father do
54+
defmodule Child do
55+
def child_fun(str) do
56+
IO.puts str
57+
end
58+
end
59+
def fun do
60+
Child.child_fun "some argument"
61+
end
62+
end
63+
Father.Child.child_fun "hello!"
64+
```
5765

5866
* The `Regex` module has received new functions, namely, `source` and `opts`. It can also be `inspect`ed now.
5967

60-
reg = %r/[a-z]+o[a-z]+/im
61-
Regex.source reg #=> "[a-z]+o[a-z]+"
62-
Regex.opts reg #=> "im"
63-
inspect reg #=> "%r\"[a-z]+o[a-z]+\"im"
68+
```elixir
69+
reg = %r/[a-z]+o[a-z]+/im
70+
Regex.source reg #=> "[a-z]+o[a-z]+"
71+
Regex.opts reg #=> "im"
72+
inspect reg #=> "%r\"[a-z]+o[a-z]+\"im"
73+
```
6474

6575
* A new `read_info` function has been added to the [`File` module](https://github.com/elixir-lang/elixir/blob/35b22c598defd8be07d46d2e7e8fc0ddf9ec4e80/lib/file.ex) allowing
6676
users to query for file attributes.

_posts/2012-04-17-what-s-new-in-elixir-2.markdown

+35-24
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
layout: post
33
title: What's New in Elixir #2
44
author: Alexei Sholik
5-
category: whatsnew
5+
category: "What's New in Elixir"
66
excerpt: This week has not seen as many prominent new features as the previous one. Still, more bugs have been fixed and a number of small improvements has been made here and there, so the overall progress is quite noticeable.
77
---
88
This week has not seen as many prominent new features as the previous one. Still, more bugs have been fixed and a number of small improvements has been made here and there, so the overall progress is quite noticeable.
@@ -11,35 +11,46 @@ Let's get started with our usual overview. I'm using the latest master (`2851da4
1111

1212
* Literal support for hexadecimal, octal and binary numbers has been added.
1313

14-
0xFF #=> 255
15-
0o10 #=> 8
16-
0b1010 #=> 10
14+
```elixir
15+
0xFF #=> 255
16+
0o10 #=> 8
17+
0b1010 #=> 10
18+
```
1719

1820
* New functions in the [List module](https://github.com/elixir-lang/elixir/blob/master/lib/list.ex): `sort`, `zip`, `unzip`.
1921

20-
# Charlists are sorted in lexicographic order
21-
List.sort ['10', '2', '4', '1', '21']
22-
#=> ['1', '10', '2', '21', '4']
23-
# Numerical sort for charlists using a custom function
24-
List.sort ['10', '2', '4', '1', '21'], fn(a, b) ->
25-
{na, _} = :string.to_integer a
26-
{nb, _} = :string.to_integer b
27-
na <= nb
28-
end
29-
#=> ['1', '2', '4', '10', '21']
30-
List.zip [[1, 2], [:a, :b], ["one", "two"]]
31-
#=> [{1,:a,"one"},{2,:b,"two"}]
22+
```elixir
23+
# Charlists are sorted in lexicographic order
24+
List.sort ['10', '2', '4', '1', '21']
25+
#=> ['1', '10', '2', '21', '4']
26+
27+
# Numerical sort for charlists using a custom function
28+
List.sort ['10', '2', '4', '1', '21'], fn(a, b) ->
29+
{na, _} = :string.to_integer a
30+
{nb, _} = :string.to_integer b
31+
na <= nb
32+
end
33+
#=> ['1', '2', '4', '10', '21']
34+
35+
List.zip [[1, 2], [:a, :b], ["one", "two"]]
36+
#=> [{1,:a,"one"},{2,:b,"two"}]
37+
```
3238

3339
* The [System module](https://github.com/elixir-lang/elixir/blob/master/lib/system.ex) has been merged into master. It provides functions for communicating with OS environment, running external commands, getting the stacktrace, etc.
3440

35-
System.pwd
36-
#=> "/Users/alco/Documents/git/elixir"
37-
System.get_env "PAGER"
38-
#=> "less"
39-
System.cmd 'date'
40-
#=> "Fri Apr 13 19:35:13 EEST 2012\n"
41-
System.stacktrace
42-
#=> (usually long output)
41+
```elixir
42+
System.pwd
43+
#=> "/Users/alco/Documents/git/elixir"
44+
45+
System.get_env "PAGER"
46+
#=> "less"
47+
48+
System.cmd 'date'
49+
#=> "Fri Apr 13 19:35:13 EEST 2012\n"
50+
51+
System.stacktrace
52+
#=> (usually long output)
53+
```
4354

4455
* In other news, we're getting closer to having a dedicated site for documentation, JSON parsing/serialization is currently in the works, and there's also work being done on bringing dicts back into Elixir.
4556

0 commit comments

Comments
 (0)