Why the value of the balance contains the value "llo"

I am working on documentation for an elixir and face the fact that I do not understand the solution. In the example below, I don’t understand why rest“llo” ends or for this fact, as the first result leads to “hello” and not “hehello”.

iex> "he" <> rest = "hello"
"hello"

iex> rest
"llo"
+4
source share
2 answers

This is the result of how Elixir works =. It does not mean:

"he";
rest = "hello";

No, pattern matching is performed instead. From the docs:

, = Elixir .

( .) , , , = - , .

= . , "". , , "". - . "he" + rest = "hello". → "he" + "llo" = "hello". , , rest = "llo".

+6

@Dair , , .

"=" , . . , , . .

, :

a = 1

, 1 ? :

1 = a

? . , . , , . , :

"he" <> rest = "hello"

, "llo" .

, .

+3

Source: https://habr.com/ru/post/1611863/


All Articles