Function calls

Pelle Månsson pelle.mansson at gmail.com
Fri Jan 29 11:23:55 PST 2010


On 01/29/2010 08:07 PM, Steven Schveighoffer wrote:
> On Fri, 29 Jan 2010 13:43:50 -0500, Pelle Månsson
> <pelle.mansson at gmail.com> wrote:
>
>> On 01/29/2010 07:10 PM, Steven Schveighoffer wrote:
>>> Note in the anecdote above, both users would have
>>> been satisfied if you could *only* call empty without parentheses.
>>>
>>
>> That's a good point. The writeln = 3; is also a good point. :)
>>
>> What I'm trying to defend is the ability to call non-property
>> functions without the parens.
>>
>> I find this:
>>
>> array.stable_sort;
>> file.detach;
>> range.popFront;
>>
>> to look less noisy, clearer and just plain sexier than the respective
>> versions with the parens.
>
> You've cited three functions where the function names cannot be
> misinterpreted as properties. This is not the case for all function
> names. If you wish to have a way to specify a function can be called
> either way, then I think you also need a way to specify that a function
> can only be called with parentheses.
>
> I don't disagree that the above is unambiguous, but there are examples
> where it is ambiguous.
>
> f.read;
>
> does this mean read f, or is it an accidental noop fetching a property
> indicating f is read?
>
> Requiring parentheses also allows you to force meanings where they would
> otherwise be interpreted as properties:
>
> f.next();
>
> Looks like it advances f, even though next isn't a verb. Without the
> parentheses, it looks like a noop access of a property.

I disagree, it doesn't look like it advances. With the parens, it just 
looks like a java-style get-function. To me, at least.

> I'm not too concerned with requiring () on your examples because it's
> inconsequential to me -- having parentheses isn't *less* clear than not
> having them. I don't mind if you wish to allow these calls without
> parens, but there has to still be a way to force the parens.
>
> -Steve

I disagree. I understand that in some cases we would not want to permit 
calling with parenthesis, and that calling as assignment is sometimes 
less than ideal. I do not, however, see any reason to allow forcing of 
parenthesis for regular functions.



More information about the Digitalmars-d mailing list