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
+30-30
Original file line number
Diff line number
Diff line change
@@ -51,7 +51,7 @@ You may keep the shell running while you're editing the file. Just don't forget
51
51
52
52
Elixir too has an interactive shell called `iex`. Compiling Elixir code can be done with `elixirc` (which is similar to Erlang's `erlc`). Elixir also provides an executable named `elixir` to run Elixir code. The module defined above can be written in Elixir as:
53
53
54
-
{% highlight ruby %}
54
+
{% highlight elixir %}
55
55
# module_name.ex
56
56
defmodule ModuleName do
57
57
def hello do
@@ -62,7 +62,7 @@ end
62
62
63
63
And compiled from `iex`:
64
64
65
-
{% highlight ruby %}
65
+
{% highlight elixir %}
66
66
Interactive Elixir
67
67
iex> c("module_name.ex")
68
68
[ModuleName]
@@ -73,7 +73,7 @@ Hello world!
73
73
74
74
However notice that in Elixir you don't need to create a file only to create a new module, Elixir modules can be defined directly in the shell:
75
75
76
-
{% highlight ruby %}
76
+
{% highlight elixir %}
77
77
defmodule MyModule do
78
78
def hello do
79
79
IO.puts "Another Hello"
@@ -117,7 +117,7 @@ X + Y.
117
117
118
118
**Elixir**
119
119
120
-
{% highlight ruby %}
120
+
{% highlight elixir %}
121
121
x = 2; y = 3
122
122
x + y
123
123
{% endhighlight %}
@@ -152,7 +152,7 @@ ok
152
152
153
153
**Elixir**
154
154
155
-
{% highlight ruby %}
155
+
{% highlight elixir %}
156
156
iex> a = 1
157
157
1
158
158
iex> a = 2
@@ -178,13 +178,13 @@ orddict:new().
178
178
179
179
to invoke the `new` function from the `orddict` module. In Elixir, use the dot `.` in place of the colon `:`
180
180
181
-
{% highlight ruby %}
181
+
{% highlight elixir %}
182
182
Process.self
183
183
{% endhighlight %}
184
184
185
185
**Note**. Since Erlang modules are represented by atoms, you may invoke Erlang functions in Elixir as follows:
186
186
187
-
{% highlight ruby %}
187
+
{% highlight elixir %}
188
188
:lists.sort [3, 2, 1]
189
189
{% endhighlight %}
190
190
@@ -212,7 +212,7 @@ X = 10.
212
212
213
213
**Elixir**
214
214
215
-
{% highlight ruby %}
215
+
{% highlight elixir %}
216
216
:im_an_atom
217
217
:me_too
218
218
@@ -235,7 +235,7 @@ is_atom(''). %=> true
235
235
236
236
**Elixir**
237
237
238
-
{% highlight ruby %}
238
+
{% highlight elixir %}
239
239
is_atom :ok #=> true
240
240
is_atom :'ok' #=> true
241
241
is_atom :"Multiple words" #=> true
@@ -259,7 +259,7 @@ setelement(1, { a, b, c }, d) % => { d, b, c }
0 commit comments