Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/elixir/lib/code.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/elixir/lib/task.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/elixir/lib/task/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion lib/elixir/pages/getting-started/basic-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I want to go into this level of distinction for a getting started guide. I would just remove the note and leave the content as it was, and we can mention the differences in the === and !== docs.

In particular, IEEE recommends +0.0 and -0.0 to actually be equal. But === is about "are they the same term"?

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.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:

Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion lib/elixir/pages/getting-started/debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
2 changes: 1 addition & 1 deletion lib/elixir/pages/getting-started/module-attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
18 changes: 9 additions & 9 deletions lib/elixir/pages/getting-started/modules-and-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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"
```
Expand Down
2 changes: 1 addition & 1 deletion lib/elixir/pages/getting-started/try-catch-and-rescue.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/elixir/pages/meta-programming/macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions lib/elixir/pages/mix-and-otp/distributed-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down Expand Up @@ -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)
```

Expand Down
Loading