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 From d8001da79909734d333de31079ca2f4d884a6b21 Mon Sep 17 00:00:00 2001 From: "chris@chriszimmerman.net" Date: Thu, 15 Oct 2015 20:59:18 -0400 Subject: Added an alternative way to fire up a process in Elixir. --- elixir.html.markdown | 2 ++ 1 file changed, 2 insertions(+) (limited to 'elixir.html.markdown') diff --git a/elixir.html.markdown b/elixir.html.markdown index c8599838..9fdf37e9 100644 --- a/elixir.html.markdown +++ b/elixir.html.markdown @@ -384,6 +384,8 @@ end # Compile the module and create a process that evaluates `area_loop` in the shell pid = spawn(fn -> Geometry.area_loop() end) #=> #PID<0.40.0> +#Alternatively +pid = spawn(Geometry, :area_loop, []) # Send a message to `pid` that will match a pattern in the receive statement send pid, {:rectangle, 2, 3} -- cgit v1.2.3 From 65f951d87c80deff6c447faa4690dcfe1bb4d36a Mon Sep 17 00:00:00 2001 From: "chris@chriszimmerman.net" Date: Sat, 17 Oct 2015 19:37:47 -0400 Subject: Added documentation on receive do blocks in Elixir. --- elixir.html.markdown | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'elixir.html.markdown') diff --git a/elixir.html.markdown b/elixir.html.markdown index 9fdf37e9..60f0b01c 100644 --- a/elixir.html.markdown +++ b/elixir.html.markdown @@ -369,6 +369,13 @@ spawn(f) #=> #PID<0.40.0> # 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 # achieved with the `receive` mechanism: + +# The `receive do` block is used to listen for messages and process +# them when they are received. A `receive do` block will only +# process one received message. In order to process multiple +# messages, a function with a `receive do` block must recursively +# call itself to get into the `receive do` block again. + defmodule Geometry do def area_loop do receive do -- cgit v1.2.3 From 07e04e7a2d0f2b7269e4495c338b039a30f70e64 Mon Sep 17 00:00:00 2001 From: "chris@chriszimmerman.net" Date: Sat, 17 Oct 2015 20:49:58 -0400 Subject: Fixed spacing with Elixir comment. --- 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 60f0b01c..eedeb227 100644 --- a/elixir.html.markdown +++ b/elixir.html.markdown @@ -391,7 +391,7 @@ end # Compile the module and create a process that evaluates `area_loop` in the shell pid = spawn(fn -> Geometry.area_loop() end) #=> #PID<0.40.0> -#Alternatively +# Alternatively pid = spawn(Geometry, :area_loop, []) # Send a message to `pid` that will match a pattern in the receive statement -- cgit v1.2.3 From 33628dca5cb4367cbbad1e4f48ddab0630b03330 Mon Sep 17 00:00:00 2001 From: Chris Martin Date: Wed, 4 Nov 2015 23:28:26 -0500 Subject: elixir: add eval results to try-rescue examples --- elixir.html.markdown | 2 ++ 1 file changed, 2 insertions(+) (limited to 'elixir.html.markdown') diff --git a/elixir.html.markdown b/elixir.html.markdown index eedeb227..720e080c 100644 --- a/elixir.html.markdown +++ b/elixir.html.markdown @@ -343,6 +343,7 @@ rescue RuntimeError -> "rescued a runtime error" _error -> "this will rescue any error" end +#=> "rescued a runtime error" # All exceptions have a message try do @@ -351,6 +352,7 @@ rescue x in [RuntimeError] -> x.message end +#=> "some error" ## --------------------------- ## -- Concurrency -- cgit v1.2.3