且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

模式匹配在Erlang

更新时间:2022-11-13 23:30:50

这是因为 [x] 等于 [x | []] ,所以它匹配 f2([_ | B]) - > [B]; 。你可以看到 B = [] 你的情况。

it is because [x] is equal to [x|[]] so it matches f2([_|B]) -> [B];. As you can see B=[] inn your case.

我想你没有写你想要的去做。在表达式 [A | B] 中,A是列表的第一个元素,而B是列表的其余部分(因此它是一个列表)。这意味着 [1,2,1] 将不匹配 [A1,A2 | A1] ;但是 [[1],2,1] [[a,b],1,a,b] 将会。

I think you didn't write what you want to do. in the expression [A|B], A is the first element of the list, while B is the rest of the list (so it is a list). That means that [1,2,1] will not match [A1, A2 | A1]; but [[1],2,1] or [[a,b],1,a,b] will.