A new class -->String

Jari-Matti Mäkelä jmjmak at utu.fi.invalid
Thu Apr 5 11:56:36 PDT 2007


Daniel Keep wrote:

> 
> 
> Jari-Matti Mäkelä wrote:
>> David B. Held wrote:
>>> Jari-Matti Mäkelä wrote:
>>>> David B. Held wrote:
>>>>> If there were a way to switch between method call and free
>>>>> function syntax, then this distinction would become moot (and maybe we
>>>>> will get that as well...).
>> 
>>>> D has that already :)
>> 
>>> Well, it isn't general:
>>>
>>> void foo(int x) { int y = x; }
>>>
>>> unittest
>>> {
>>>     int z = 5;
>>>     z.foo();
>>> }
>>>
>>> test.d(43): Error: no property 'foo' for type 'int'
>>> test.d(43): Error: function expected before (), not 1 of type int
>> 
>> Hm, I wonder if that's a compiler bug. I have not used this feature
>> recently, but I recall it used to work. I even have bindings where this
>> feature is used to provide an alternative syntax for a wrapper class.
>> Now that I tested it, it only seems to work with arrays and AAs anymore.
>> But it's still enough to implement those string functions though.
> 
> From what I understand, it's not a feature, it's a bug.  No, I'm
> serious: this happens because of a bug in DMD.  The only reason it's
> never been fixed is because people actually really, really like that it
> works :)

Ah, you're right. I didn't find it in the language docs either.

> The whole "switch function to member of first arg" thing is only usable,
> as you said, on arrays and AAs.  Having it usable in general would be
> wicked-nifty-awesome-keen, to mix my colloquialisms. :)

In Scala language this can be "safely" done with views and implicit type
conversions. If this "poor man's version" isn't a good solution in the long
run, at least there is another way to do this that has strong academic
backing behind it. That alternative is also much more flexible.



More information about the Digitalmars-d mailing list