digitalmars.D.learn - Inclusion of Parenthesis on Certain Functions
- Justin Choi (5/5) Jun 13 2021 I'm currently learning D right now, and I was wondering why
- mw (3/8) Jun 13 2021 Uniform Function Call Syntax (UFCS)
- H. S. Teoh (14/19) Jun 13 2021 In D, parentheses for function calls are optional when there are no
- Bastiaan Veelo (4/6) Jun 13 2021 https://dlang.org/spec/function.html#optional-parenthesis
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
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
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
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