Skip to content

Commit 22dd09f

Browse files
committed
Merge pull request #3 from carlosgaldino/master
Highlight code
2 parents 0b3c5b3 + 5e2b7e3 commit 22dd09f

File tree

8 files changed

+1042
-689
lines changed

8 files changed

+1042
-689
lines changed

_includes/top.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
66
<title>{{ page.title }}</title>
77
<link rel="stylesheet" type="text/css" href="/css/style.css">
8+
<link rel="stylesheet" type="text/css" href="/css/syntax.css">
89
<link rel="shortcut icon" href="/images/logo/drop.png">
910
<meta name="viewport" content="width=device-width,initial-scale=1">
1011
<link rel="stylesheet" id="font-bitter-css" href="http://fonts.googleapis.com/css?family=Bitter&amp;ver=1" type="text/css" media="screen">
@@ -49,4 +50,4 @@ <h2 id="site-description">
4950
</h2>
5051
</div>
5152

52-
<div id="main">
53+
<div id="main">

css/syntax.css

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
.highlight { background: #ffffff; }
2+
.highlight .c { color: #999988; font-style: italic } /* Comment */
3+
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
4+
.highlight .k { font-weight: bold } /* Keyword */
5+
.highlight .o { font-weight: bold } /* Operator */
6+
.highlight .cm { color: #999988; font-style: italic } /* Comment.Multiline */
7+
.highlight .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
8+
.highlight .c1 { color: #999988; font-style: italic } /* Comment.Single */
9+
.highlight .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
10+
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
11+
.highlight .gd .x { color: #000000; background-color: #ffaaaa } /* Generic.Deleted.Specific */
12+
.highlight .ge { font-style: italic } /* Generic.Emph */
13+
.highlight .gr { color: #aa0000 } /* Generic.Error */
14+
.highlight .gh { color: #999999 } /* Generic.Heading */
15+
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
16+
.highlight .gi .x { color: #000000; background-color: #aaffaa } /* Generic.Inserted.Specific */
17+
.highlight .go { color: #888888 } /* Generic.Output */
18+
.highlight .gp { color: #555555 } /* Generic.Prompt */
19+
.highlight .gs { font-weight: bold } /* Generic.Strong */
20+
.highlight .gu { color: #aaaaaa } /* Generic.Subheading */
21+
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
22+
.highlight .kc { font-weight: bold } /* Keyword.Constant */
23+
.highlight .kd { font-weight: bold } /* Keyword.Declaration */
24+
.highlight .kp { font-weight: bold } /* Keyword.Pseudo */
25+
.highlight .kr { font-weight: bold } /* Keyword.Reserved */
26+
.highlight .kt { color: #445588; font-weight: bold } /* Keyword.Type */
27+
.highlight .m { color: #009999 } /* Literal.Number */
28+
.highlight .s { color: #d14 } /* Literal.String */
29+
.highlight .na { color: #008080 } /* Name.Attribute */
30+
.highlight .nb { color: #0086B3 } /* Name.Builtin */
31+
.highlight .nc { color: #445588; font-weight: bold } /* Name.Class */
32+
.highlight .no { color: #008080 } /* Name.Constant */
33+
.highlight .ni { color: #800080 } /* Name.Entity */
34+
.highlight .ne { color: #990000; font-weight: bold } /* Name.Exception */
35+
.highlight .nf { color: #990000; font-weight: bold } /* Name.Function */
36+
.highlight .nn { color: #555555 } /* Name.Namespace */
37+
.highlight .nt { color: #000080 } /* Name.Tag */
38+
.highlight .nv { color: #008080 } /* Name.Variable */
39+
.highlight .ow { font-weight: bold } /* Operator.Word */
40+
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
41+
.highlight .mf { color: #009999 } /* Literal.Number.Float */
42+
.highlight .mh { color: #009999 } /* Literal.Number.Hex */
43+
.highlight .mi { color: #009999 } /* Literal.Number.Integer */
44+
.highlight .mo { color: #009999 } /* Literal.Number.Oct */
45+
.highlight .sb { color: #d14 } /* Literal.String.Backtick */
46+
.highlight .sc { color: #d14 } /* Literal.String.Char */
47+
.highlight .sd { color: #d14 } /* Literal.String.Doc */
48+
.highlight .s2 { color: #d14 } /* Literal.String.Double */
49+
.highlight .se { color: #d14 } /* Literal.String.Escape */
50+
.highlight .sh { color: #d14 } /* Literal.String.Heredoc */
51+
.highlight .si { color: #d14 } /* Literal.String.Interpol */
52+
.highlight .sx { color: #d14 } /* Literal.String.Other */
53+
.highlight .sr { color: #009926 } /* Literal.String.Regex */
54+
.highlight .s1 { color: #d14 } /* Literal.String.Single */
55+
.highlight .ss { color: #990073 } /* Literal.String.Symbol */
56+
.highlight .bp { color: #999999 } /* Name.Builtin.Pseudo */
57+
.highlight .vc { color: #008080 } /* Name.Variable.Class */
58+
.highlight .vg { color: #008080 } /* Name.Variable.Global */
59+
.highlight .vi { color: #008080 } /* Name.Variable.Instance */
60+
.highlight .il { color: #009999 } /* Literal.Number.Integer.Long */

getting_started/1.markdown

+125-83
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ If you don't use any of the distributions above, don't worry! Continue reading f
3131

3232
You can download and compile Elixir in few steps:
3333

34-
$ git clone https://github.com/elixir-lang/elixir.git
35-
$ cd elixir
36-
$ make test
34+
{% highlight console %}
35+
$ git clone https://github.com/elixir-lang/elixir.git
36+
$ cd elixir
37+
$ make test
3738

38-
$ bin/elixir -v
39-
Elixir 0.4.0.dev
39+
$ bin/elixir -v
40+
Elixir 0.4.0.dev
41+
{% endhighlight %}
4042

4143
If tests pass, you are ready to go. Otherwise, feel free to open an issue [in the issues tracker on Github](https://github.com/elixir-lang/elixir).
4244

@@ -49,88 +51,110 @@ If tests pass, you are ready to go. Otherwise, feel free to open an issue [in th
4951

5052
We can start Elixir interactive mode by running `bin/iex` in the same directory you compiled Elixir or by simply running `iex` if you installed it from a distribution. In interactive mode, we can type any Elixir expression. Let's warm up with some basic arithmetic expressions:
5153

52-
iex> 1 + 1
53-
2
54-
iex> 10 - 5
55-
5
56-
iex> 10 / 2
57-
5.0
54+
{% highlight iex %}
55+
iex> 1 + 1
56+
2
57+
iex> 10 - 5
58+
5
59+
iex> 10 / 2
60+
5.0
61+
{% endhighlight %}
5862

5963
Notice `10 / 2` returned a float `5.0` instead of an integer. This is expected, in Elixir the operator `/` always returns a float. In case you want to do integer division or get the division remainder, you can invoke the `div` and `rem` functions:
6064

61-
iex> div(10, 2)
62-
5
63-
iex> div 10, 2
64-
5
65-
iex> rem 10, 3
66-
1
65+
{% highlight iex %}
66+
iex> div(10, 2)
67+
5
68+
iex> div 10, 2
69+
5
70+
iex> rem 10, 3
71+
1
72+
{% endhighlight %}
6773

6874
In the example above, we called two functions called `div` and `rem`. Notice that parenthesis are not required in order to invoke a function. We are going to discuss more about it later. Let's move forward and see which other data types we have in Elixir:
6975

7076
## 1.3 Basic types
7177

7278
Some basic types are:
7379

74-
iex> 1 # integer
75-
iex> 1.0 # float
76-
iex> :atom # atom / symbol
77-
iex> {1,2,3} # tuple
78-
iex> [1,2,3] # list
80+
{% highlight iex %}
81+
iex> 1 # integer
82+
iex> 1.0 # float
83+
iex> :atom # atom / symbol
84+
iex> {1,2,3} # tuple
85+
iex> [1,2,3] # list
86+
{% endhighlight %}
7987

8088
Elixir also provides functions (note the dot between the variable and arguments when calling a function):
8189

82-
# function
83-
iex> x = fn(a, b) -> a + b end
84-
#Fun<erl_eval.12.111823515>
85-
iex> x.(1, 2)
86-
3
90+
{% highlight iex %}
91+
# function
92+
iex> x = fn(a, b) -> a + b end
93+
#Fun<erl_eval.12.111823515>
94+
iex> x.(1, 2)
95+
3
96+
{% endhighlight %}
8797

8898
And double-quoted strings:
8999

90-
iex> "string"
91-
"string"
100+
{% highlight iex %}
101+
iex> "string"
102+
"string"
103+
{% endhighlight %}
92104

93105
Strings in Elixir are UTF-8 binaries delimited by double quotes. A single-quoted string in Elixir is called a char list and is simply a list of characters:
94106

95-
iex> 'string'
96-
'string'
107+
{% highlight iex %}
108+
iex> 'string'
109+
'string'
110+
{% endhighlight %}
97111

98112
There is also string interpolation:
99113

100-
iex> name = "world"
101-
iex> "hello #{name}"
102-
"hello world"
114+
{% highlight iex %}
115+
iex> name = "world"
116+
iex> "hello #{name}"
117+
"hello world"
118+
{% endhighlight %}
103119

104120
We can use the `is_binary` and `is_list` helpers to detect if a given string is a binary (double-quoted) or a list (single-quoted):
105121

106-
iex> is_binary "string"
107-
true
108-
iex> is_list "string"
109-
false
122+
{% highlight iex %}
123+
iex> is_binary "string"
124+
true
125+
iex> is_list "string"
126+
false
110127

111-
iex> is_binary 'string'
112-
false
113-
iex> is_list 'string'
114-
true
128+
iex> is_binary 'string'
129+
false
130+
iex> is_list 'string'
131+
true
132+
{% endhighlight %}
115133

116134
Although they represent the same thing, double-quoted and single-quoted strings are different and best suited for different scenarios:
117135

118-
iex> "string" == 'string'
119-
false
136+
{% highlight iex %}
137+
iex> "string" == 'string'
138+
false
139+
{% endhighlight %}
120140

121141
Most of the cases, developers should use double-quoted strings as their representation is more compact. We are going to discuss this subject with more detail in the next chapter.
122142

123143
Elixir also provides `true` and `false` as booleans:
124144

125-
iex> true
126-
true
127-
iex> is_boolean false
128-
true
145+
{% highlight iex %}
146+
iex> true
147+
true
148+
iex> is_boolean false
149+
true
150+
{% endhighlight %}
129151

130152
Booleans are represented internally as atoms:
131153

132-
iex> is_atom(true)
133-
true
154+
{% highlight iex %}
155+
iex> is_atom(true)
156+
true
157+
{% endhighlight %}
134158

135159
Elixir also provides Port, References and PIDs as data types (usually used in process communication) but they are out of the scope of a getting started tutorial. For now, let's take a look at the basic operators in Elixir before we move on to the next chapter.
136160

@@ -140,70 +164,88 @@ As we saw earlier, Elixir provides `+`, `-`, `*`, `/` as arithmetic operators.
140164

141165
Elixir also provides `++` and `--` to manipulate lists:
142166

143-
iex> [1,2,3] ++ [4,5,6]
144-
[1,2,3,4,5,6]
145-
iex> [1,2,3] -- [2]
146-
[1,3]
167+
{% highlight iex %}
168+
iex> [1,2,3] ++ [4,5,6]
169+
[1,2,3,4,5,6]
170+
iex> [1,2,3] -- [2]
171+
[1,3]
172+
{% endhighlight %}
147173

148174
Since single-quoted strings are lists, we can also use `++` and `--` as operators to manipulate them:
149175

150-
iex> 'some' ++ ' example'
151-
'some example'
152-
iex> 'some' -- 'oe'
153-
'sm'
176+
{% highlight iex %}
177+
iex> 'some' ++ ' example'
178+
'some example'
179+
iex> 'some' -- 'oe'
180+
'sm'
181+
{% endhighlight %}
154182

155183
Notice that `++` and `--` cannot be used to manipulate double quoted strings, as they are binaries. That said, string concatenation is done via `<>`:
156184

157-
iex> "foo" <> "bar"
158-
"foobar"
185+
{% highlight iex %}
186+
iex> "foo" <> "bar"
187+
"foobar"
188+
{% endhighlight %}
159189

160190
Elixir also provides three boolean operators: `or`, `and` and `not`. Those operators are strict in the sense those operators expects only booleans (true or false) as arguments:
161191

162-
iex> true and true
163-
true
164-
iex> false or is_atom(:example)
165-
true
192+
{% highlight iex %}
193+
iex> true and true
194+
true
195+
iex> false or is_atom(:example)
196+
true
197+
{% endhighlight %}
166198

167199
Giving a non-boolean as argument will raise an exception:
168200

169-
iex> 1 and true
170-
** (::ArgumentError) argument error
201+
{% highlight iex %}
202+
iex> 1 and true
203+
** (::ArgumentError) argument error
204+
{% endhighlight %}
171205

172206
`or` and `and` are short-circuit operators. They just execute the right side in case the left side is not enough to determine the result:
173207

174-
iex> false and error("This error will never be raised")
175-
false
208+
{% highlight iex %}
209+
iex> false and error("This error will never be raised")
210+
false
176211

177-
iex> true or error("This error will never be raised")
178-
true
212+
iex> true or error("This error will never be raised")
213+
true
214+
{% endhighlight %}
179215

180216
> Note: If you are an Erlang developer, `and` and `or` in Elixir actually map to the `andalso` and `orelse` operators in Erlang.
181217
182218
Elixir also provides `==`, `!=`, `===`, `!===`, `<=`, `>=`, `<` and `>` as comparison operators:
183219

184-
iex> 1 == 1
185-
true
186-
iex> 1 != 2
187-
true
188-
iex> 1 < 2
189-
true
220+
{% highlight iex %}
221+
iex> 1 == 1
222+
true
223+
iex> 1 != 2
224+
true
225+
iex> 1 < 2
226+
true
227+
{% endhighlight %}
190228

191229
The difference between `==` and `===` is that the latter is more strict when comparing integers and floats:
192230

193-
iex> 1 == 1.0
194-
true
195-
iex> 1 === 1.0
196-
false
231+
{% highlight iex %}
232+
iex> 1 == 1.0
233+
true
234+
iex> 1 === 1.0
235+
false
236+
{% endhighlight %}
197237

198238
In Elixir, we can compare two different data types:
199239

200-
iex> 1 < :atom
201-
true
240+
{% highlight iex %}
241+
iex> 1 < :atom
242+
true
243+
{% endhighlight %}
202244

203245
The reason we can compare different data types is for pragmatism. Sorting algorithms don't need to worry about different data types in order to sort. The overall sorting order is defined below:
204246

205247
number < atom < reference < functions < port < pid < tuple < list < bit string
206248

207249
You actually don't need to memorize this ordering, it is important just to know an order exists.
208250

209-
Well, that is it for the introduction. In the next chapter, we are going to discuss some basic functions, data types conversions and a bit of control-flow.
251+
Well, that is it for the introduction. In the next chapter, we are going to discuss some basic functions, data types conversions and a bit of control-flow.

0 commit comments

Comments
 (0)