Added some info about how to run the shell and compile modules.

This commit is contained in:
mrshankly 2013-07-02 23:37:18 +01:00
parent 6763fc89e3
commit 231a211ef2

View File

@ -6,11 +6,19 @@ filename: learnelixir.ex
--- ---
```elixir ```elixir
# Single line comments start with a hash. # Single line comments start with a hashtag.
## -------------------- # There's no multi-line comment,
# but you can stack multiple comments.
# To use the elixir shell use the `iex` command.
# Compile your modules with the `elixirc` command.
# Both should be in your path if you installed elixir correctly.
## ---------------------------
## -- Basic types ## -- Basic types
## -------------------- ## ---------------------------
# There are numbers # There are numbers
3 # integer 3 # integer
@ -286,7 +294,6 @@ Recursion.sum_list([1,2,3], 0) #=> 6
# Elixir modules support attributes, there are built-in attributes and you # Elixir modules support attributes, there are built-in attributes and you
# may also add custom attributes. # may also add custom attributes.
defmodule MyMod do defmodule MyMod do
@moduledoc """ @moduledoc """
This is a built-in attribute on a example module. This is a built-in attribute on a example module.
@ -346,7 +353,6 @@ spawn(f) #=> #PID<0.40.0>
# messages to the process. To do message passing we use the `<-` operator. # messages to the process. To do message passing we use the `<-` operator.
# For all of this to be useful we need to be able to receive messages. This is # For all of this to be useful we need to be able to receive messages. This is
# achived with the `receive` mechanism: # achived with the `receive` mechanism:
defmodule Geometry do defmodule Geometry do
def area_loop do def area_loop do
receive do receive do
@ -371,6 +377,9 @@ pid <- {:rectangle, 2, 3}
pid <- {:circle, 2} pid <- {:circle, 2}
#=> Area = 12.56000000000000049738 #=> Area = 12.56000000000000049738
# {:circle,2} # {:circle,2}
# The shell is also a process, you can use `self` to get the current pid
self() #=> #PID<0.27.0>
``` ```
## References ## References