[Issue 8381] New: Uniform function call syntax (pseudo member) enhancement suggestions
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jul 12 01:54:29 PDT 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8381
Summary: Uniform function call syntax (pseudo member)
enhancement suggestions
Product: D
Version: unspecified
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: tommitissari at hotmail.com
--- Comment #0 from Tommi <tommitissari at hotmail.com> 2012-07-12 01:54:22 PDT ---
As I see it, the goal of uniform function call syntax, as
described here http://www.drdobbs.com/blogs/cpp/232700394, is to
allow non-intrusively extending the functionality of a type. I
think the current implementation falls short in accomplishing
this goal on two accounts:
1) You can't non-intrusively add static member functions
2) You can't non-intrusively add constructors
So, I'm suggesting these two features to be added to the language:
1. Static members as free functions
------------------------------------
If function invocations like the following are encountered...
A) Type.func(<ARGUMENTS>);
B) Type.func; // it's a static @property function
...and those functions haven't been implemented as members,
the function invocations get lowered into:
A) func!Type(<ARGUMENTS>);
B) func!Type;
For example:
enum Fruit {apple, orange}
// CODE // LOWERED CODE
Fruit.letEmRot(); // .letEmRot!Fruit();
if (Fruit.isEatable) // if (.isEatable!Fruit)
{
Fruit myfruit;
myfruit.split(3); // .split!Fruit(3); // only if it can't
// be lowered into:
// .split(myfruit, 3)
}
2. Class & struct constructors as free functions
-------------------------------------------------
If a constructor call hasn't been implemented by Type...
auto t = Type(<ARGUMENTS>);
...then it get's lowered into a free function call...
auto t = .make!Type(<ARGUMENTS>);
For example:
enum Fruit {apple, orange}
// CODE // LOWERED CODE
auto f = Fruit("red"); // auto f = .make!Fruit("red");
--
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