www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Inclusion of Parenthesis on Certain Functions

reply Justin Choi <justinjchoice gmail.com> writes:
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.
Jun 13 2021
next sibling parent mw <mingwu gmail.com> writes:
On Sunday, 13 June 2021 at 15:45:53 UTC, Justin Choi 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.
Uniform Function Call Syntax (UFCS) https://tour.dlang.org/tour/en/gems/uniform-function-call-syntax-ufcs
Jun 13 2021
prev sibling next sibling parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
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)
Jun 13 2021
prev sibling parent Bastiaan Veelo <Bastiaan Veelo.net> writes:
On Sunday, 13 June 2021 at 15:45:53 UTC, Justin Choi wrote:
 I've tried looking through the documentation but can't find an 
 explanation for why you can use it without parenthesis.
https://dlang.org/spec/function.html#optional-parenthesis (Some exceptions regarding delegates and function pointers exist.) —Bastiaan
Jun 13 2021