4 ms·
The same result could be achieved by introducing a smaller change to the language that doesn't completely redefine the way existing functions are evaluated. By
by jpatte 12y ago
The same result could be achieved by introducing a smaller change to the language that doesn't completely redefine the way existing functions are evaluated. By using some specific signature (like adding a keyword to the first argument of a function), you could indicate that this function may be used as a member method of the first argument. For example, C# uses the keyword 'this' for its extension methods:
public static class Helpers
{
public static string UrlEncode(this string url)
{
//...
}
}
// then later:
string someText = "...";
string a = Helpers.UrlEncode(someText); // valid
string b = someText.UrlEncode(); // valid too
But of course that would mean having to update all the function declarations of the standard library to add the new keyword when needed...
- bodyfour 12y agoYes, I agree that there are simpler changes that would fix the problem, and personally I'd root for them. Stroustrup's proposal is still interesting in that it would solve it and unify operator/method dispatch at the same time. It has a certain elegance.