19

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.

Community
  • 1
  • 1
jtolle
  • 7,023
  • 2
  • 28
  • 50

4 Answers4

26

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.

Steve Jessop
  • 273,490
  • 39
  • 460
  • 699
  • Hah! As is often the case when I get an answer here, I now feel like a total dork. Of couse I know "unary", "binary", etc., but didn't make the connection. stackoverflow is way better than Google (which I did start with) for situations like this! – jtolle Apr 27 '11 at 15:27
7

A nullary or niladic function.

    

Mark Cidade
  • 98,437
  • 31
  • 224
  • 236
4

A Thunk?

  • Thanks. I didn't know "thunk" as another name for this. But "nullary" is the general term I was looking for. – jtolle Apr 27 '11 at 15:28
  • That is, I should say I knew "thunk" in terms of delayed computation, but not as a synonym for "nullary". – jtolle Apr 27 '11 at 15:33
0

A constant

Apparently that’s too short an answer.

Darrel Lee
  • 2,372
  • 22
  • 22