www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - object.function()

reply %u <a3052152 jnxjn.com> writes:
I have a question,
can I write all functions like this object.function() instead of
functin(object) ?
or that form for some function or cases.
May 13 2011
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
 I have a question,
 can I write all functions like this object.function() instead of
functin(object) ?
 or that form for some function or cases.

This currently only works for D arrays. (I think Walter&Andrei wanted it for other types too originally, I do not know if it will be implemented.)
May 13 2011
parent "Jonathan M Davis" <jmdavisProg gmx.com> writes:
 I have a question,
 can I write all functions like this object.function() instead of
 functin(object) ? or that form for some function or cases.

This currently only works for D arrays. (I think Walter&Andrei wanted it for other types too originally, I do not know if it will be implemented.)

It currently only works for arrays. IIRC, the fact that it ever worked that way in the first place was a bug rather than intended, but it was determined to be useful and was kept around. There has been a push to make it it so that it works for _everything_ (so-called Universal Function Call Syntax) - which would make stuff like 3.min(4) legal. It's not clear however whether that will ever happen. If nothing else, there are a number of design and implementation issues which may make it too difficult to reasonably implement. In particular, would increase the number possible ambiguities in code, which would cause problems. So, it may or may not ever be implemented, and if it is implemented, it may only be implemented in a restricted sense. Regardless, for now, it only works with arrays. - Jonathan M Davis
May 13 2011