class extensions
Chris Nicholson-Sauls
ibisbasenji at gmail.com
Thu Aug 30 22:10:29 PDT 2007
Nathan Reed wrote:
> Bill Baxter wrote:
>> Chris Nicholson-Sauls wrote:
>>> Bill Baxter wrote:
>>>> kris wrote:
>>>> So my feeling is that for this to be more useful:
>>>> 1) Extension members should be marked as such and *only* be allowed
>>>> to be called with member syntax. Those not marked as such will not
>>>> be allowed to be called with member syntax. (if you need both then
>>>> it's easy enough to write a trivial forwarding function.)
>>>
>>> Its not a bad idea. The "trivial forwarding function" should be
>>> inlineable anyhow. Maybe a "context" parameter? Something like:
>>> size_t indexOf : T[] array (T) (T elem) { ... }
>>>
>>> Where the (':' param) after the function name creates the
>>> context-param. Other examples:
>>>
>>> ulong area : IShape shp () { ... }
>>>
>>> void unique : inout T[] array (T) () { ... }
>>>
>>>
>>> Its just a random on-the-spot idea.
>>>
>>
>> Maybe even just use a semi-colon instead of comma in the arg list?
>> size_t indexOf(T)(T[] array; T elem) { ... }
>> ulong area (IShape shp;) { ... }
>> void unique (ref T[] array; T) () { ... }
>>
>> --bb
>
> I like that syntax; something similiar is used in mathematics on
> occasion. Simple and elegant.
>
> Thanks,
> Nathan Reed
Agreed. I believe the use of semicolons within params was once suggested for another
purpose, ages ago, and (obviously) went nowhere. Maybe this suggestion will be a bit more
lucky.
-- Chris Nicholson-Sauls
More information about the Digitalmars-d
mailing list