1

I have a list L = [1,2,3].

I perform the following on L:

lists:sublist(L,2) ++ [10] ++ lists:nthtail(3,L).

Instead of storing the result in a new list, I want to store the result in L itself. However, when I do so, I am getting the obvious error: ** exception error: no match of right hand side value [1,2,300]

I don't want to use a new variable, I want to rewrite in L itself. Is it possible?

2240
  • 1,547
  • 2
  • 12
  • 30
Manika Sharma
  • 113
  • 1
  • 12
  • 1
    I understand that you are learning Erlang, If it is the case, I advice you to use the excellent site from Fred Hebert : [learnYouSomeErlang](https://learnyousomeerlang.com/). The official Erlang documentation is very useful as reference, but not oriented for learning. Good job and have fun! – Pascal Nov 22 '20 at 18:12
  • This is the same book as https://learnyousomeerlang.com/introduction, and this resource is beautifully put even for a beginner! Thanks a lot for your guidance, I am referring to the same resource, and as I am moving forward, Erlang has started to look quite handy! – Manika Sharma Nov 22 '20 at 18:16

1 Answers1

2

No, Erlang has single assignment. To use an example from Armstrong, in C this works:

x = 5;
x = x + 10;

But in Erlang it is written:

X = 5;
X1 = X + 10;
2240
  • 1,547
  • 2
  • 12
  • 30