Whence came UFCS?

Steven Schveighoffer schveiguy at gmail.com
Fri Jul 27 13:38:26 UTC 2018


On 7/27/18 7:24 AM, Simen Kjærås wrote:
> On Friday, 27 July 2018 at 10:30:07 UTC, Jonathan M Davis wrote:
>> It evolved out of D's member function call syntax for arrays - 
>> basically, for years before we had UFCS in D, we had UFCS for arrays. 
>> However, when and how that was added to arrays, I don't know. I don't 
>> recall it ever not being in the language, but I never used D1, and I 
>> don't know if it had it. At minimum, it's been in D since early D2, if 
>> not much earlier. I'd have to do a lot of spelunking through old 
>> releases to figure out when it was added.
>>
>> Certainly, the origins of UFCS in D do not come from making it 
>> possible to extend user-defined types with member functions. It comes 
>> from wanting member function call syntax when using arrays (probably 
>> aimed primarily at strings, but I don't know). It's just that later it 
>> was proposed to extend it so that it would work with any type and thus 
>> make the member function call syntax universal.
> 
> This compiles in DMD 0.50 (oldest version on the download page, nov 20, 
> 2002), so I think it's safe to say it's been around for a while:
> 
> void fun(int[] arr) {}
> 
> void main() {
>      int[] a;
>      a.fun();
> }
> 
> Arrays' .reverse, .sort and others were added in 0.24, but I can't find 
> a download for anything before 0.50.

Reverse and sort were properties (compiler built-ins), not extensions. 
If it existed in 2002, it's safe to say it was there pretty much from 
the beginning.

-Steve


More information about the Digitalmars-d mailing list