Jump to page: 1 2
Thread overview
I have a dream about external methods too ...
Mar 14, 2005
Andrew Fedoniouk
Mar 14, 2005
pragma
Mar 14, 2005
Andrew Fedoniouk
Mar 14, 2005
Ben Hinkle
Mar 14, 2005
pragma
Mar 14, 2005
Ben Hinkle
Mar 14, 2005
pragma
Mar 14, 2005
Sean Kelly
Mar 14, 2005
Lionello Lunesu
Mar 14, 2005
Sean Kelly
Mar 14, 2005
Charles
Mar 14, 2005
Sean Kelly
Mar 14, 2005
Craig Black
Mar 14, 2005
Charles
Mar 14, 2005
Joey Peters
Mar 14, 2005
Craig Black
March 14, 2005
About external methods (or multimethods?)....

I would like to be able to write something like this one day.... Would be extremely nice....

typedef wchar[] string
{
    void insert(int at, wchar what)
    {
        int num = this.length;
        this.length = num + 1;
        ......
    }
    void opCatAssign(wchar what)
    {
        this.length = this.length + 1;
        this[this.length - 1]  = what;
     }
     ....
}

typedef uint color
{
    uint red()  {  return this & 0xFF; }
    uint green()  { ... }
    uint blue()  { ... }
}

Huh?

Andrew.


March 14, 2005
In article <d136o4$mbg$1@digitaldaemon.com>, Andrew Fedoniouk says...
>
>About external methods (or multimethods?)....
>
>I would like to be able to write something like this one day.... Would be extremely nice....
>
>typedef wchar[] string
>{
>    void insert(int at, wchar what)
>    {
>        int num = this.length;
>        this.length = num + 1;
>        ......
>    }
>    void opCatAssign(wchar what)
>    {
>        this.length = this.length + 1;
>        this[this.length - 1]  = what;
>     }
>     ....
>}
>
>typedef uint color
>{
>    uint red()  {  return this & 0xFF; }
>    uint green()  { ... }
>    uint blue()  { ... }
>}
>
>Huh?

I couldn't agree more.  In fact, I proposed almost the same exact thing a (long)
while back. (sorry if that was what you were referring to) ;)

OP: http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/8159

Proposal: http://www.prowiki.org/wiki4d/wiki.cgi?Typedef-Block

- EricAnderton at yahoo
March 14, 2005
:)

I have not seen your post, Eric! Honestly!

If two wise men (yet decent :)
independently (sic!) come up to the same idea
then it means that this idea at least is worth
something :)

Andrew.


"pragma" <pragma_member@pathlink.com> wrote in message news:d1380p$o27$1@digitaldaemon.com...
> In article <d136o4$mbg$1@digitaldaemon.com>, Andrew Fedoniouk says...
>>
>>About external methods (or multimethods?)....
>>
>>I would like to be able to write something like this one day.... Would be extremely nice....
>>
>>typedef wchar[] string
>>{
>>    void insert(int at, wchar what)
>>    {
>>        int num = this.length;
>>        this.length = num + 1;
>>        ......
>>    }
>>    void opCatAssign(wchar what)
>>    {
>>        this.length = this.length + 1;
>>        this[this.length - 1]  = what;
>>     }
>>     ....
>>}
>>
>>typedef uint color
>>{
>>    uint red()  {  return this & 0xFF; }
>>    uint green()  { ... }
>>    uint blue()  { ... }
>>}
>>
>>Huh?
>
> I couldn't agree more.  In fact, I proposed almost the same exact thing a
> (long)
> while back. (sorry if that was what you were referring to) ;)
>
> OP: http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/8159
>
> Proposal: http://www.prowiki.org/wiki4d/wiki.cgi?Typedef-Block
>
> - EricAnderton at yahoo


March 14, 2005
Well, I thought it could easily be done by just making a method that takes a 'color' but then calling it like some_color.red() instead of red(some_color)... But it didn't work:

The method 'toupper' can be called as string.toupper(), but why can't the same be done for 'color' ? Even without the typedef (using uint) it won't work?

Lionello


void toupper( char[] c )
{
 c ~= "bla";
}

typedef uint color;
int red( color c ) { return c&0xFF; }

int main( char[][]arg )
{
 char[] string;
 string.toupper();

 uint c;
 return c.red();
}


March 14, 2005
That somehow looks strange and unlikely, but useful. It could work a little different, much like how you can do:

enum Something : int { ... }

Perhaps one should be able to do:

# class Something : char[] {
#   void insert(int at, wchat what) { super.length = super.length + 1; ... }
# }

But it just doesn't make sense somehow.

"Andrew Fedoniouk" <news@terrainformatica.com> schreef in bericht news:d136o4$mbg$1@digitaldaemon.com...
> About external methods (or multimethods?)....
>
> I would like to be able to write something like this one day.... Would be extremely nice....
>
> typedef wchar[] string
> {
>    void insert(int at, wchar what)
>    {
>        int num = this.length;
>        this.length = num + 1;
>        ......
>    }
>    void opCatAssign(wchar what)
>    {
>        this.length = this.length + 1;
>        this[this.length - 1]  = what;
>     }
>     ....
> }
>
> typedef uint color
> {
>    uint red()  {  return this & 0xFF; }
>    uint green()  { ... }
>    uint blue()  { ... }
> }
>
> Huh?
>
> Andrew.



March 14, 2005
>OP: http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/8159
>
>Proposal: http://www.prowiki.org/wiki4d/wiki.cgi?Typedef-Block

nice write-up! That's a great use of wiki. I like this external method stuff. It
would make extending basic types easier. A variation on all this would be
something that makes official the array-method hack: return-type fcnname(T[],
..) can be called like x.fcnname(...). The general form of this would be
return-type fcnname(T, ...) can be called with x.fcnname(...). Maybe a concrete
proposal for this has been suggested already, too?
For example,
# char[] toString(int x){...}
# ...
# int y;
# printf("%.*s",y.toString()); // no need for .toString
The name lookup and overloading rules would have to be massaged so that
fcnname(T,...) could be found. I'll ponder this some more and probably try to
write up as nice a wiki proposal as you did for the typedef extension.

-Ben


March 14, 2005
In article <d14403$1lbo$1@digitaldaemon.com>, Ben Hinkle says...
>
>
>>OP: http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/8159
>>
>>Proposal: http://www.prowiki.org/wiki4d/wiki.cgi?Typedef-Block
>
>nice write-up! That's a great use of wiki.

Thank you.  I plan on doing this more often in the future, as per my suggestions for improving the DNG.  Please, post any critiques you have to wiki if you feel like it.

Its not captured on the page, but a major motivation I have for this is to provide a way to overload operators for scalars.  Right now, that's and advantage that C++ has over D.

> I like this external method stuff. It
>would make extending basic types easier. A variation on all this would be something that makes official the array-method hack

That gets my vote too, provided that operator overloads can be worked-in.  I prefer the typedef-block solution only because it forces one to create a new type, so the built-in primitives can stay as-is.  I think that's important, as I can easily see operator overloads on the built-in types as a font of bugs.

- EricAnderton at yahoo
March 14, 2005
> Proposal: http://www.prowiki.org/wiki4d/wiki.cgi?Typedef-Block

How do I get to the proposal(s) from the FrontPage of the wiki?


March 14, 2005
In article <d14bbd$1tok$1@digitaldaemon.com>, Ben Hinkle says...
>
>> Proposal: http://www.prowiki.org/wiki4d/wiki.cgi?Typedef-Block
>
>How do I get to the proposal(s) from the FrontPage of the wiki?
>

The closest thing we have is the Feature Request List, which is anything but a stack of formal proposals.

http://www.prowiki.org/wiki4d/wiki.cgi?FeatureRequestList

.. and it's not linked directly from the front page, but is available via "Idea Discussion".

- EricAnderton at yahoo
March 14, 2005
> About external methods (or multimethods?)....

This is a great idea, but this is not "multimethods".

-Craig



« First   ‹ Prev
1 2