且构网

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

为什么Erlang变量未使用?

更新时间:2022-06-27 00:21:17

这是因为变量发生在发电机的LHS上,X和Y在这里,总是新的未绑定变量本地到理解。这意味着它们与三元组头中的X和Y不是相同的变量,因此,没有隐含的等式测试。这类似于乐趣,其中所有变量发生在乐趣的头部都是本地的乐趣的新变量。

This is because variables occurring on the LHS of generators, X and Y here, are always new unbound variables local to the comprehension. This means that they are not the same variables as the X and Y in the head of triples and, therefore, there is no implicit equality test. This similar to funs where all variables occurring in the head of a fun are alse new variables local to the fun.

这与其他大部分的erlang不同,是为什么编译器不仅警告头部中的X和Y不被使用,而且X和Y在理解中影响其他变量。他们在理解中也没有任何地方使用。

This is different from most of the rest of erlang, which is why the compiler not only warns that the X and Y in the head are not used but also that the X and Y in the comprehension shadow the other variables. They are also unused anywhere in the comprehension.

一个简单的方法来获得你想要的东西:

An easy way to get what you want is:

[ Result || Result = {X1,Y1,_} <- Self, X =:= X1, Y =:= Y1 ]