From 791a83502905ae19e59c0ec0f78e2a13741ce09f Mon Sep 17 00:00:00 2001 From: sabiwara Date: Mon, 7 Oct 2024 19:32:37 +0900 Subject: [PATCH 1/5] Update out-of-date claim about === --- lib/elixir/pages/getting-started/basic-types.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/elixir/pages/getting-started/basic-types.md b/lib/elixir/pages/getting-started/basic-types.md index 43ebb304eac..ac27fbf5ebd 100644 --- a/lib/elixir/pages/getting-started/basic-types.md +++ b/lib/elixir/pages/getting-started/basic-types.md @@ -322,13 +322,22 @@ iex> 1 == 2.0 false ``` -However, you can use the strict comparison operator [`===`](`===/2`) and [`!==`](`!==/2`) if you want to distinguish between integers and floats (that's the only difference between these operators): +However, you can use the strict comparison operator [`===`](`===/2`) and [`!==`](`!==/2`) if you want to distinguish between integers and floats: ```elixir iex> 1 === 1.0 false ``` +Besides this distinction, since Erlang 27, strict comparison operators are also considering `+0.0` and `-0.0` as non-equal: + +```elixir +iex> +0.0 === -0.0 +false +iex> +0.0 == -0.0 +true +``` + The comparison operators in Elixir can compare across any data type. We say these operators perform _structural comparison_. For more information, you can read our documentation on [Structural vs Semantic comparisons](`Kernel#module-structural-comparison`). Elixir also provides data-types for expressing collections, such as lists and tuples, which we learn next. When we talk about concurrency and fault-tolerance via processes, we will also discuss ports, pids, and references, but that will come on later chapters. Let's move forward. From 7847ed7ffc3c5405d5ebbbf2f2d367083ac8acd4 Mon Sep 17 00:00:00 2001 From: sabiwara Date: Mon, 7 Oct 2024 19:51:24 +0900 Subject: [PATCH 2/5] Add some more links to the binaries & strings guide --- .../pages/getting-started/binaries-strings-and-charlists.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/elixir/pages/getting-started/binaries-strings-and-charlists.md b/lib/elixir/pages/getting-started/binaries-strings-and-charlists.md index 3e0a22a4f5f..e19fe5fab59 100644 --- a/lib/elixir/pages/getting-started/binaries-strings-and-charlists.md +++ b/lib/elixir/pages/getting-started/binaries-strings-and-charlists.md @@ -184,7 +184,7 @@ iex> String.valid?(<<239, 191, 19>>) false ``` -The string concatenation operator `<>` is actually a binary concatenation operator: +The string concatenation operator [`<>`](`<>/2`) is actually a binary concatenation operator: ```elixir iex> "a" <> "ha" @@ -243,7 +243,7 @@ iex> [?h, ?e, ?l, ?l, ?o] ~c"hello" ``` -The `~c` sigil (we'll cover sigils later in the ["Sigils"](sigils.md) chapter) indicates the fact that we are dealing with a charlist and not a regular string. +The [`~c`](`Kernel.sigil_c/2`) sigil (we'll cover sigils later in the ["Sigils"](sigils.md) chapter) indicates the fact that we are dealing with a charlist and not a regular string. Instead of containing bytes, a charlist contains integer code points. However, the list is only printed as a sigil if all code points are within the ASCII range: @@ -283,7 +283,7 @@ iex> to_string(1) The functions above are polymorphic, in other words, they accept many shapes: not only do they convert charlists to strings (and vice-versa), they can also convert integers, atoms, and so on. -String (binary) concatenation uses the `<>` operator but charlists, being lists, use the list concatenation operator `++`: +String (binary) concatenation uses the [`<>`](`<>/2`) operator but charlists, being lists, use the list concatenation operator [`++`](`++/2`): ```elixir iex> ~c"this " <> ~c"fails" From 8d631272a6628ccdb3b5f9853f68319f53eddc1c Mon Sep 17 00:00:00 2001 From: sabiwara Date: Tue, 8 Oct 2024 07:12:52 +0900 Subject: [PATCH 3/5] Add brackets to function calls in docs --- lib/elixir/pages/getting-started/debugging.md | 2 +- .../pages/getting-started/module-attributes.md | 2 +- .../getting-started/modules-and-functions.md | 18 +++++++++--------- .../getting-started/try-catch-and-rescue.md | 2 +- lib/elixir/pages/meta-programming/macros.md | 6 +++--- .../pages/mix-and-otp/distributed-tasks.md | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/elixir/pages/getting-started/debugging.md b/lib/elixir/pages/getting-started/debugging.md index 0be3fb8b4e7..8b503106381 100644 --- a/lib/elixir/pages/getting-started/debugging.md +++ b/lib/elixir/pages/getting-started/debugging.md @@ -46,7 +46,7 @@ It is also very common to use `IO.inspect/2` with `binding/0`, which returns all ```elixir def some_fun(a, b, c) do - IO.inspect binding() + IO.inspect(binding()) ... end ``` diff --git a/lib/elixir/pages/getting-started/module-attributes.md b/lib/elixir/pages/getting-started/module-attributes.md index 4ebfee34283..c1eba8ee8b9 100644 --- a/lib/elixir/pages/getting-started/module-attributes.md +++ b/lib/elixir/pages/getting-started/module-attributes.md @@ -73,7 +73,7 @@ So far, we have seen how to define attributes, but how can we read them? Let's s ```elixir defmodule MyServer do @service URI.parse("https://example.com") - IO.inspect @service + IO.inspect(@service) end ``` diff --git a/lib/elixir/pages/getting-started/modules-and-functions.md b/lib/elixir/pages/getting-started/modules-and-functions.md index a369a660827..3b08e43d6f4 100644 --- a/lib/elixir/pages/getting-started/modules-and-functions.md +++ b/lib/elixir/pages/getting-started/modules-and-functions.md @@ -143,8 +143,8 @@ defmodule Concat do end end -IO.puts Concat.join("Hello", "world") #=> Hello world -IO.puts Concat.join("Hello", "world", "_") #=> Hello_world +IO.puts(Concat.join("Hello", "world")) #=> Hello world +IO.puts(Concat.join("Hello", "world", "_")) #=> Hello_world ``` Any expression is allowed to serve as a default value, but it won't be evaluated during the function definition. Every time the function is invoked and any of its default values have to be used, the expression for that default value will be evaluated: @@ -182,9 +182,9 @@ defmodule Concat do end end -IO.puts Concat.join("Hello", "world") #=> Hello world -IO.puts Concat.join("Hello", "world", "_") #=> Hello_world -IO.puts Concat.join("Hello") #=> Hello +IO.puts(Concat.join("Hello", "world")) #=> Hello world +IO.puts(Concat.join("Hello", "world", "_")) #=> Hello_world +IO.puts(Concat.join("Hello")) #=> Hello ``` When a variable is not used by a function or a clause, we add a leading underscore (`_`) to its name to signal this intent. This rule is also covered in our [Naming Conventions](../references/naming-conventions.md#underscore-_foo) document. @@ -194,12 +194,12 @@ When using default values, one must be careful to avoid overlapping function def ```elixir defmodule Concat do def join(a, b) do - IO.puts "***First join" + IO.puts("***First join") a <> b end def join(a, b, sep \\ " ") do - IO.puts "***Second join" + IO.puts("***Second join") a <> sep <> b end end @@ -219,13 +219,13 @@ $ iex concat.ex ``` ```elixir -iex> Concat.join "Hello", "world" +iex> Concat.join("Hello", "world") ***First join "Helloworld" ``` ```elixir -iex> Concat.join "Hello", "world", "_" +iex> Concat.join("Hello", "world", "_") ***Second join "Hello_world" ``` diff --git a/lib/elixir/pages/getting-started/try-catch-and-rescue.md b/lib/elixir/pages/getting-started/try-catch-and-rescue.md index 5c1dd23fcac..a2e0c2c5c32 100644 --- a/lib/elixir/pages/getting-started/try-catch-and-rescue.md +++ b/lib/elixir/pages/getting-started/try-catch-and-rescue.md @@ -224,7 +224,7 @@ iex> defmodule RunAfter do ...> def without_even_trying do ...> raise "oops" ...> after -...> IO.puts "cleaning up!" +...> IO.puts("cleaning up!") ...> end ...> end iex> RunAfter.without_even_trying diff --git a/lib/elixir/pages/meta-programming/macros.md b/lib/elixir/pages/meta-programming/macros.md index a3261ddcbab..58e7eb0e7bd 100644 --- a/lib/elixir/pages/meta-programming/macros.md +++ b/lib/elixir/pages/meta-programming/macros.md @@ -38,9 +38,9 @@ and play with those definitions: ```elixir iex> require Unless -iex> Unless.macro_unless(true, do: IO.puts "this should never be printed") +iex> Unless.macro_unless(true, do: IO.puts("this should never be printed")) nil -iex> Unless.fun_unless(true, do: IO.puts "this should never be printed") +iex> Unless.fun_unless(true, do: IO.puts("this should never be printed")) "this should never be printed" nil ``` @@ -50,7 +50,7 @@ In our *macro* implementation, the sentence was not printed, although it was pri In other words, when invoked as: ```elixir -Unless.macro_unless(true, do: IO.puts "this should never be printed") +Unless.macro_unless(true, do: IO.puts("this should never be printed")) ``` Our `macro_unless` macro received the following: diff --git a/lib/elixir/pages/mix-and-otp/distributed-tasks.md b/lib/elixir/pages/mix-and-otp/distributed-tasks.md index 608fd3c2dd3..88ea24f83c8 100644 --- a/lib/elixir/pages/mix-and-otp/distributed-tasks.md +++ b/lib/elixir/pages/mix-and-otp/distributed-tasks.md @@ -38,7 +38,7 @@ Let's define a module named `Hello` in this shell: ```elixir iex> defmodule Hello do -...> def world, do: IO.puts "hello world" +...> def world, do: IO.puts("hello world") ...> end ``` @@ -102,7 +102,7 @@ So far we have explored tasks that are started and run in isolation, without reg ```elixir task = Task.async(fn -> compute_something_expensive() end) -res = compute_something_else() +res = compute_something_else() res + Task.await(task) ``` From 83078791f8e7bf6f8a842dc8b79f1c163e4bd374 Mon Sep 17 00:00:00 2001 From: sabiwara Date: Tue, 8 Oct 2024 07:13:12 +0900 Subject: [PATCH 4/5] Add bracket to function calls in module docs --- lib/elixir/lib/code.ex | 2 +- lib/elixir/lib/task.ex | 4 ++-- lib/elixir/lib/task/supervisor.ex | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/elixir/lib/code.ex b/lib/elixir/lib/code.ex index 54c0c092892..f058b4203df 100644 --- a/lib/elixir/lib/code.ex +++ b/lib/elixir/lib/code.ex @@ -185,7 +185,7 @@ defmodule Code do defmodule MyTracer do def trace({:remote_function, _meta, module, name, arity}, env) do - IO.puts "#{env.file}:#{env.line} #{inspect(module)}.#{name}/#{arity}" + IO.puts("#{env.file}:#{env.line} #{inspect(module)}.#{name}/#{arity}") :ok end diff --git a/lib/elixir/lib/task.ex b/lib/elixir/lib/task.ex index 9eba4f452d2..f9bc9702d07 100644 --- a/lib/elixir/lib/task.ex +++ b/lib/elixir/lib/task.ex @@ -842,14 +842,14 @@ defmodule Task do Process.demonitor(ref, [:flush]) {url, state} = pop_in(state.tasks[ref]) - IO.puts "Got #{inspect(result)} for URL #{inspect url}" + IO.puts("Got #{inspect(result)} for URL #{inspect url}") {:noreply, state} end # If the task fails... def handle_info({:DOWN, ref, _, _, reason}, state) do {url, state} = pop_in(state.tasks[ref]) - IO.puts "URL #{inspect url} failed with reason #{inspect(reason)}" + IO.puts("URL #{inspect url} failed with reason #{inspect(reason)}") {:noreply, state} end end diff --git a/lib/elixir/lib/task/supervisor.ex b/lib/elixir/lib/task/supervisor.ex index 6086b2a18fe..8561629d355 100644 --- a/lib/elixir/lib/task/supervisor.ex +++ b/lib/elixir/lib/task/supervisor.ex @@ -498,7 +498,7 @@ defmodule Task.Supervisor do Starts a task as a child of the given `supervisor`. Task.Supervisor.start_child(MyTaskSupervisor, fn -> - IO.puts "I am running in a task" + IO.puts("I am running in a task") end) Note that the spawned process is not linked to the caller, but From 85b35c99c4049060e2c5f784e5001dfc496b71b4 Mon Sep 17 00:00:00 2001 From: Jean Klingler Date: Tue, 8 Oct 2024 18:05:28 +0900 Subject: [PATCH 5/5] Update lib/elixir/pages/getting-started/basic-types.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: José Valim --- lib/elixir/pages/getting-started/basic-types.md | 9 --------- 1 file changed, 9 deletions(-) diff --git a/lib/elixir/pages/getting-started/basic-types.md b/lib/elixir/pages/getting-started/basic-types.md index ac27fbf5ebd..0abe68b910e 100644 --- a/lib/elixir/pages/getting-started/basic-types.md +++ b/lib/elixir/pages/getting-started/basic-types.md @@ -329,15 +329,6 @@ iex> 1 === 1.0 false ``` -Besides this distinction, since Erlang 27, strict comparison operators are also considering `+0.0` and `-0.0` as non-equal: - -```elixir -iex> +0.0 === -0.0 -false -iex> +0.0 == -0.0 -true -``` - The comparison operators in Elixir can compare across any data type. We say these operators perform _structural comparison_. For more information, you can read our documentation on [Structural vs Semantic comparisons](`Kernel#module-structural-comparison`). Elixir also provides data-types for expressing collections, such as lists and tuples, which we learn next. When we talk about concurrency and fault-tolerance via processes, we will also discuss ports, pids, and references, but that will come on later chapters. Let's move forward.