문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

A nullary or niladic function.

    

A Thunk?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top