Inclusion of Parenthesis on Certain Functions

H. S. Teoh hsteoh at quickfur.ath.cx
Sun Jun 13 15:58:30 UTC 2021


On Sun, Jun 13, 2021 at 03:45:53PM +0000, Justin Choi via Digitalmars-d-learn wrote:
> I'm currently learning D right now, and I was wondering why certain
> functions like std.stdio.readln can work both with and without
> parenthesis for the function call. I've tried looking through the
> documentation but can't find an explanation for why you can use it
> without parenthesis.

In D, parentheses for function calls are optional when there are no
arguments. So:

	func();

can be shortened to:

	func;

When UFCS is in effect, the empty parentheses on the right side of the
function call are also optional:

	func(abc);

can be rewritten as:

	abc.func;


T

-- 
People demand freedom of speech to make up for the freedom of thought which they avoid. -- Soren Aabye Kierkegaard (1813-1855)


More information about the Digitalmars-d-learn mailing list