From 09044470a089c4ccc896edf846b7ae54264cceae Mon Sep 17 00:00:00 2001 From: lidashuang Date: Mon, 31 Mar 2014 18:00:57 +0800 Subject: Update elixir.html.markdown --- elixir.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'elixir.html.markdown') diff --git a/elixir.html.markdown b/elixir.html.markdown index 8ea499ff..df586649 100644 --- a/elixir.html.markdown +++ b/elixir.html.markdown @@ -9,7 +9,7 @@ Elixir is a modern functional language built on top of the Erlang VM. It's fully compatible with Erlang, but features a more standard syntax and many more features. -```ruby +```elixir # Single line comments start with a hashtag. -- cgit v1.2.3 From 777c333ff078a7095f9b7ac303829b249f499b21 Mon Sep 17 00:00:00 2001 From: Sam Dodrill Date: Mon, 14 Apr 2014 11:04:44 -0700 Subject: Remove references to hash and hashtag in favor of number symbol --- elixir.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'elixir.html.markdown') diff --git a/elixir.html.markdown b/elixir.html.markdown index df586649..0892deb7 100644 --- a/elixir.html.markdown +++ b/elixir.html.markdown @@ -11,7 +11,7 @@ and many more features. ```elixir -# Single line comments start with a hashtag. +# Single line comments start with a number symbol. # There's no multi-line comment, # but you can stack multiple comments. -- cgit v1.2.3 From 0d6b7513c79bee6daf131d4437bf1319559fb6f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Veiga?= Date: Tue, 20 May 2014 07:51:34 +0200 Subject: replaced <- with send, corrected message sending --- elixir.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'elixir.html.markdown') diff --git a/elixir.html.markdown b/elixir.html.markdown index 0892deb7..b27b2ee8 100644 --- a/elixir.html.markdown +++ b/elixir.html.markdown @@ -358,7 +358,7 @@ f = fn -> 2 * 2 end #=> #Function spawn(f) #=> #PID<0.40.0> # `spawn` returns a pid (process identifier), you can use this pid to send -# messages to the process. To do message passing we use the `<-` operator. +# messages to the process. To do message passing we use the `send` operator. # For all of this to be useful we need to be able to receive messages. This is # achived with the `receive` mechanism: defmodule Geometry do @@ -378,11 +378,11 @@ end pid = spawn(fn -> Geometry.area_loop() end) #=> #PID<0.40.0> # Send a message to `pid` that will match a pattern in the receive statement -pid <- {:rectangle, 2, 3} +send pid, {:rectangle, 2, 3} #=> Area = 6 # {:rectangle,2,3} -pid <- {:circle, 2} +send pid, {:circle, 2} #=> Area = 12.56000000000000049738 # {:circle,2} -- cgit v1.2.3 From 506ffb7a683d136c550278efa184a51af0e5b5e7 Mon Sep 17 00:00:00 2001 From: William Clifford Date: Sat, 7 Jun 2014 07:45:57 -0700 Subject: Update elixir.html.markdown minor spelling fix: `s/catched/caught/` --- elixir.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'elixir.html.markdown') diff --git a/elixir.html.markdown b/elixir.html.markdown index b27b2ee8..946c0a1b 100644 --- a/elixir.html.markdown +++ b/elixir.html.markdown @@ -201,7 +201,7 @@ cond do end # `try/catch` is used to catch values that are thrown, it also supports an -# `after` clause that is invoked whether or not a value is catched. +# `after` clause that is invoked whether or not a value is caught. try do throw(:hello) catch -- cgit v1.2.3 From 27c7f4c4f039d07fc32e5b67493fdfe9c92a9e9d Mon Sep 17 00:00:00 2001 From: Nikhil Thomas Date: Thu, 18 Sep 2014 13:41:47 -0400 Subject: fix typo --- elixir.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'elixir.html.markdown') diff --git a/elixir.html.markdown b/elixir.html.markdown index 946c0a1b..c0abc815 100644 --- a/elixir.html.markdown +++ b/elixir.html.markdown @@ -360,7 +360,7 @@ spawn(f) #=> #PID<0.40.0> # `spawn` returns a pid (process identifier), you can use this pid to send # messages to the process. To do message passing we use the `send` operator. # For all of this to be useful we need to be able to receive messages. This is -# achived with the `receive` mechanism: +# achieved with the `receive` mechanism: defmodule Geometry do def area_loop do receive do -- cgit v1.2.3 From c49e6f1928d6a717734fe1afbb3f96adac37c0b7 Mon Sep 17 00:00:00 2001 From: Dzianis Dashkevich Date: Sat, 18 Oct 2014 14:00:32 +0300 Subject: [elixir/en] Replace Records section w/ Structs one Fix typos Add "Programming Elixir" and Elixir Cheat Sheet to References section --- elixir.html.markdown | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'elixir.html.markdown') diff --git a/elixir.html.markdown b/elixir.html.markdown index c0abc815..0a20e3df 100644 --- a/elixir.html.markdown +++ b/elixir.html.markdown @@ -2,6 +2,7 @@ language: elixir contributors: - ["Joao Marques", "http://github.com/mrshankly"] + - ["Dzianis Dashkevich", "https://github.com/dskecse"] filename: learnelixir.ex --- @@ -59,7 +60,7 @@ tail #=> [2,3] # the tuples have different sizes. # {a, b, c} = {1, 2} #=> ** (MatchError) no match of right hand side value: {1,2} -# There's also binaries +# There are also binaries <<1,2,3>> # binary # Strings and char lists @@ -108,7 +109,7 @@ div(10, 2) #=> 5 # To get the division remainder use `rem` rem(10, 3) #=> 1 -# There's also boolean operators: `or`, `and` and `not`. +# There are also boolean operators: `or`, `and` and `not`. # These operators expect a boolean as their first argument. true and true #=> true false or true #=> true @@ -119,7 +120,6 @@ false or true #=> true 1 || true #=> 1 false && 1 #=> false nil && 20 #=> nil - !true #=> false # For comparisons we have: `==`, `!=`, `===`, `!==`, `<=`, `>=`, `<` and `>` @@ -165,12 +165,12 @@ case {:one, :two} do {:four, :five} -> "This won't match" {:one, x} -> - "This will match and assign `x` to `:two`" + "This will match and bind `x` to `:two`" _ -> "This will match any value" end -# It's common practice to assign a value to `_` if we don't need it. +# It's common to bind the value to `_` if we don't need it. # For example, if only the head of a list matters to us: [head | _] = [1,2,3] head #=> 1 @@ -190,7 +190,7 @@ cond do "But I will" end -# It is common to see a last condition equal to `true`, which will always match. +# It is common to see the last condition equal to `true`, which will always match. cond do 1 + 1 == 3 -> "I will never be seen" @@ -301,7 +301,7 @@ end Recursion.sum_list([1,2,3], 0) #=> 6 # Elixir modules support attributes, there are built-in attributes and you -# may also add custom attributes. +# may also add custom ones. defmodule MyMod do @moduledoc """ This is a built-in attribute on a example module. @@ -312,21 +312,24 @@ defmodule MyMod do end ## --------------------------- -## -- Records and Exceptions +## -- Structs and Exceptions ## --------------------------- -# Records are basically structures that allow you to associate a name with -# a particular value. -defrecord Person, name: nil, age: 0, height: 0 +# Structs are extensions on top of maps that bring default values, +# compile-time guarantees and polymorphism into Elixir. +defmodule Person do + defstruct name: nil, age: 0, height: 0 +end -joe_info = Person.new(name: "Joe", age: 30, height: 180) -#=> Person[name: "Joe", age: 30, height: 180] +joe_info = %Person{ name: "Joe", age: 30, height: 180 } +#=> %Person{age: 30, height: 180, name: "Joe"} # Access the value of name joe_info.name #=> "Joe" # Update the value of age -joe_info = joe_info.age(31) #=> Person[name: "Joe", age: 31, height: 180] +older_joe_info = %{ joe_info | age: 31 } +#=> %Person{age: 31, height: 180, name: "Joe"} # The `try` block with the `rescue` keyword is used to handle exceptions try do @@ -394,5 +397,7 @@ self() #=> #PID<0.27.0> * [Getting started guide](http://elixir-lang.org/getting_started/1.html) from [elixir webpage](http://elixir-lang.org) * [Elixir Documentation](http://elixir-lang.org/docs/master/) +* ["Programming Elixir"](https://pragprog.com/book/elixir/programming-elixir) by Dave Thomas +* [Elixir Cheat Sheet](http://media.pragprog.com/titles/elixir/ElixirCheat.pdf) * ["Learn You Some Erlang for Great Good!"](http://learnyousomeerlang.com/) by Fred Hebert -* "Programming Erlang: Software for a Concurrent World" by Joe Armstrong +* ["Programming Erlang: Software for a Concurrent World"](https://pragprog.com/book/jaerlang2/programming-erlang) by Joe Armstrong -- cgit v1.2.3 From 5720c56026567ebf3d756ae0e8971565e66ab06d Mon Sep 17 00:00:00 2001 From: james sangho nah Date: Sun, 1 Feb 2015 01:32:21 +1300 Subject: Add ranges under 'Basic types' --- elixir.html.markdown | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'elixir.html.markdown') diff --git a/elixir.html.markdown b/elixir.html.markdown index 0a20e3df..fb5f183a 100644 --- a/elixir.html.markdown +++ b/elixir.html.markdown @@ -91,6 +91,11 @@ string. <<1,2,3>> <> <<4,5>> #=> <<1,2,3,4,5>> "hello " <> "world" #=> "hello world" +# Ranges are represented as `start..end` (both inclusive) +1..10 #=> 1..10 +lower..upper = 1..10 # Can use pattern matching on ranges as well +[lower, upper] #=> [1, 10] + ## --------------------------- ## -- Operators ## --------------------------- -- cgit v1.2.3 From 5e2eed46b23130353122c5bf80be2f3aa2f656bb Mon Sep 17 00:00:00 2001 From: Christian Schlensker Date: Wed, 24 Jun 2015 10:50:39 -0700 Subject: Fix typo in elixer --- elixir.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'elixir.html.markdown') diff --git a/elixir.html.markdown b/elixir.html.markdown index fb5f183a..c8599838 100644 --- a/elixir.html.markdown +++ b/elixir.html.markdown @@ -195,7 +195,7 @@ cond do "But I will" end -# It is common to see the last condition equal to `true`, which will always match. +# It is common to set the last condition equal to `true`, which will always match. cond do 1 + 1 == 3 -> "I will never be seen" -- cgit v1.2.3