[Issue 8381] Uniform function call syntax (pseudo member) enhancement suggestions

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jul 12 12:21:24 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=8381



--- Comment #7 from David Piepgrass <qwertie256 at gmail.com> 2012-07-12 12:21:21 PDT ---
> It almost looks like we're trying to pass MyType as first argument to the
> function, but because we can't pass type as function argument, we pass it as
> first template argument. But you're right that none of that is very obvious.
> Maybe the whole uniform function call syntax could have been implemented
> somehow differently so that it had been more intuitive to people new to the
> language.

Well, yeah, maybe. I could probably think of some alternatives that are a bit
more intuitive than UFCS. For example I think it would be nice to allow 
"alternate" interfaces to types, something like:

alias MyInt : int {
    bool isPrime() const { ... }
}
MyInt x = 7;   writeln(x.isPrime()); // OK
int   y = x+1; writeln(y.isPrime()); // ERROR, no such function in "int"

>But I really mean type when I say, "extending the functionality of a type". I
>mean not only class but all user defined types as well, like enum, struct and
>union.

My proposal could easily include enums and structs, too:

static enum Goo { static Goo g() {...} }
static struct Hoo { static void f() {...} }

It reminds me that C# allows "new Hoo()" for structs even though they are not
allocated on the heap. If that existed in D then the "static new" part of my
proposal could work well for structs, too.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list