为什么此通配符函数告诉我它的参数数量错误?

编程入门 行业动态 更新时间:2024-10-26 22:20:56
本文介绍了为什么此通配符函数告诉我它的参数数量错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

违规代码为:

<console>:47: error: wrong number of parameters; expected = 2 terms.foldLeft(r.unitA)(r.add(_, _.eval(x)))

我通过写来解决了我的问题:

I solved my problem by writing:

terms.foldLeft(r.unitA)((a,b) => r.add(a, b.eval(x)))

但是我仍然想知道是什么阻止了我的最初尝试?

But I'd still like to know what prevented my initial attempt?

推荐答案

这是SLS 6.23的部分:

Here is the section of the SLS 6.23:

iainmcgin.github.io/scala-ref-markdown/#placeholder-syntax-for-anonymous-functions

更新的链接:

www.scala-lang/files/archive/spec/2.11/06-expressions.html#placeholder-syntax-for-anonymous-functions

Daniel Sobral的帖子说:

Daniel Sobral's post says:

当您使用"_"作为占位符的匿名参数的占位符时 函数,该函数的范围是最里面的括号 包含它. 大部分时间.

"When you use "_" as a place holder for an anonymous parameter of a function, the scope of that function is the innermost parenthesis containing it. Most of the time.

更新自旋:我认为规范中的语法解释更容易理解,占位符不会转义封闭的Expr.有很多重复的问题.

Updated spin: I think the syntax explanation from the spec is easier to get, that the placeholder doesn't escape an enclosing Expr. There are various duplicate questions.

更多推荐

为什么此通配符函数告诉我它的参数数量错误?

本文发布于:2023-07-26 11:44:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1216014.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:通配符   告诉我   函数   数量   错误

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!