object.function()

Jonathan M Davis jmdavisProg at gmx.com
Fri May 13 16:41:50 PDT 2011


> > 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


More information about the Digitalmars-d-learn mailing list