什么是不带参数的函数?
是否有一个术语比“不带参数的函数”更简洁地描述不带参数的函数? (就像“高阶函数”意味着“将函数作为参数或返回函数的函数”一样)
我自然会想到“void”,但当我看到“void”时,我也会想到副作用。我正在考虑的情况是在不断
的讨论中发现的那种情况:
,您可以在其中创建一个不带参数、没有副作用的闭包,但仍然可以做一些有趣的事情。
Is there a term that describes a function that takes no arguments more concisely than "function that takes no arguments"? (In the same way that e.g. "higher order function" means "function that takes functions as arguments or returns a function")
I naturally think of "void", but I also think of side effects when I see "void". The situation I'm thinking of is the sort found in this discussion of constantly
:
What is this functional "pattern" called?
where you might create a closure that takes no arguments, has no side effects, but still does something interesting.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
无效函数,通常: http://en.wikipedia.org/wiki/Arity
函数是否有副作用与它有多少参数正交,因此在没有函数有副作用的语言中,您不需要更具体的术语。在有副作用的语言中,我想你会称其为“无副作用”或“纯”零函数。
然后,通过(例如)记忆化,即使您知道在幕后它确实有副作用,函数也可以在逻辑上是纯粹的。
A nullary function, usually: http://en.wikipedia.org/wiki/Arity
Whether a function has side-effects is orthogonal to how many arguments it has, so in a language where no function ever has side-effects, you don't need a more specific term. In languages with side-effects, I suppose you'd call it a "side-effect-free" or "pure" nullary function.
And then with (for example) memoization, a function can be logically pure even though you know that behind the scenes, it does have side-effects.
nullary 或 niladic 函数。
A nullary or niladic function.
Thunk?
A Thunk?
一个常数
显然这个答案太短了。
A constant
Apparently that’s too short an answer.