ufcs and integer params
Timon Gehr
timon.gehr at gmx.ch
Sun Jul 15 14:29:04 PDT 2012
On 07/15/2012 08:56 PM, Jonathan M Davis wrote:
> On Sunday, July 15, 2012 19:50:18 Timon Gehr wrote:
>> On 07/15/2012 05:40 AM, Jonathan M Davis wrote:
>>> On Sunday, July 15, 2012 05:30:55 Jay Norwood wrote:
>>>> I see from this other discussions that it looks like 2.059 ( or
>>>> maybe 2.060) does support something like 3.cm(). Not sure from
>>>> the discussion if it would also accept 3.cm as in the xtext/xtend
>>>> example.
>>>>
>>>> http://forum.dlang.org/thread/smoniukqfxerutqrjshf@forum.dlang.org
>>>
>>> UFCS (universal function call syntax) was added in 2.059. If cm is a
>>> function, then 3.cm() will work. If it's a property function, then 3.cm
>>> will work. If you don't compile with -property, then 3.cm will still work
>>> with cm being a non-property function, but -property will become the
>>> normal behavior eventually, so you shouldn't expect that 3.cm will work
>>> long term unless cm is a property function.
>>
>> I expect it to stay.
>>
>> Another reason why @property-'enforcement' is flawed:
>>
>> @property auto cm(int arg){ .. }
>>
>> cm=2; // ok
>> 2.cm; // ok
>>
>> The two code snippets would in fact be equivalent.
>
> @property isn't perfect, and I admit that the fact that both cm = 2 and 2.cm
> works here is undesirable, given what's trying to be done here, but it makes
> sense given that it's abstracting a variable. It's just undesirable that you
> can't make it so that it functions only as a getter.
cm=2 is in fact a getter call. I don't mind this, because I don't need
to write that code if I don't want to. The 'puritanical' view is simply
incompatible with how the whole thing is laid out.
> But the overall situation
> is still a whale of a lot better than the laxity of letting just any function
> be called with or without parens depending no what each particular programmer
> feels like doing with it. If it's a property, it should be treated as such,
> and if it isn't, it shouldn't.
>
>> What is enforced here? Why would it matter if anything is 'enforced'?
>
> If you marked it as a property, then it's supposed to be abstracting a
> variable and should be treated as one, just like if it's a normal function, it
> should be invoked as a function,
This seems to be tautological. But what this statement presumably
really meant to say was 'it should be invoked as a function using the
notation present in eg. C or Java'.
> just like ++ shouldn't suddenly do --, and / shouldn't *.
>
That depends entirely on the domain of these functions.
> I don't want to get into this argument again.
Yah, we have gone through this before.
> The current plan is (and has been for some time)
> that -property will become the normal behavior,
It is obvious that -property is broken and will not become the normal
behaviour.
More information about the Digitalmars-d-learn
mailing list