The “&” with no parameters

六月ゝ 毕业季﹏ 提交于 2020-11-29 04:51:43

问题


I have this:

    case test123(&(:some_module.test456(789))) do
      # ...
    end

An error:

invalid args for &, expected an expression in the format of &Mod.fun/arity, 
&local/arity or a capture containing at least one argument as &1, 
got: :some_module.test456(789)

However, I don't have a parameter to pass into it and previously it was merely

 fn(_) -> :some_module.test456(789) end

How to fix it? Switch back to "fn"?


回答1:


The & syntax cannot be used to create such anonymous functions because the compiler can't know whether you wanted to create a 0 or 1 or 2 or more arity function. You'll have to keep using fn(_) -> :some_module.test456(789) end.



来源:https://stackoverflow.com/questions/43852728/the-with-no-parameters

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!