为什么我不能用Erlang重写列表?

lzfw57am  于 2022-12-08  发布在  Erlang
关注(0)|答案(1)|浏览(115)

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?

2mbi3lxu

2mbi3lxu1#

不,Erlang有single assignment。要使用example from Armstrong,在C中可以这样做:

x = 5;
x = x + 10;

但在爱尔兰语中,它是这样写的:

X = 5;
X1 = X + 10;

相关问题