How about "auto" parameters?

foobar foo at bar.com
Tue Jun 7 05:11:03 PDT 2011


Ary Manzana Wrote:

> On 6/3/11 11:25 PM, Andrei Alexandrescu wrote:
> > On 6/3/11 10:19 AM, Matthew Ong wrote:
> >> On 6/3/2011 11:47 AM, Mehrdad wrote:
> >>> == Quote from Jonathan M Davis (jmdavisProg at gmx.com)'s article
> >>
> >>>> understand templates to use D properly - especially when dealing
> >>> with Phobos -
> >>>> that doesn't help at all.
> >>>> I see no advantages with this idea and quite a few disadvantages.
> >>> This
> >>>> proposal adds absolutely nothing.
> >>>> - Jonathan M Davis
> >>>
> >>>
> >>> o__o way to bash the proposal, it actually convinced me lol...
> >>
> >>
> >> >> proposal adds absolutely nothing.
> >> You will get this frequently. Especially if you identify with Java
> >> development.
> >>
> >> Welcome to D forum, where new idea are squashed and maybe re-discussed
> >> later. Look up my name as Matthew Ong. Avoid asking the same questions.
> >>
> >> http://www.digitalmars.com/d/
> >> Notice: We *welcome feedback about the D compiler or language*,
> >>
> >> Not so true. Or out right should warn people as:
> >>
> >> Notice: Take it the way how we like it here, we are Not Burger K*ng.
> >> Please see:
> >> d.D.learn
> >> AND MAKE sure you read this
> >> d.D.NoSuchUselessSuggestion
> >>
> >> What do you think D forum people, at least new people here are for warn.
> >> Add a bit of humor into that.
> >>
> >> I do see a pattern here. Just joined D forum less than 4 weeks ago.
> >> Got a week off to clear my head. I think now I understand why D is still
> >> such a small community in the forum.
> >
> > I understand how you find that an attractive conclusion to reach, but
> > probably a more rational hypothesis is that some of your proposals have
> > been of poor quality. That doesn't reflect poorly on your abilities, it
> > just suggests that you have not yet accumulated sufficient expertise
> > with D.
> >
> > As an example, look at the activity of a current poster who proposed
> > very strongly a change in a way the intervals are handled. It was
> > arguably a very poor proposal for D, and people did their best to
> > explain why. That poster was outwitted by competent people with clear
> > and solid arguments. Yet that poster's way to solve that cognitive
> > dissonance - the low road if you ask me - was to conclude that the value
> > of his proposal is high in spite of all logic and reasoning, and that
> > everyone else is wrong.
> >
> > I suggest you don't fall for the same pattern, though clearly I
> > understand how attractive it is. It slows down learning.
> >
> >
> > Andrei
> 
> 
> Well, in Ruby every parameter type is auto. And it works pretty well. :-)
> 
> When you invoke a method and something goes wrong, like the auto 
> parameter doesn't have a method, it gives a sensible error message.
> 
> So:
> 
> void foo(auto parameter) {
>    return parameter * 2;
> }
> 
> could just be the same as
> 
> void foo(T)(T parameter) {
>    return parameter * 2;
> }
> 
> just with a nicer syntax (but I understand it doesn't add much).
> 
> I think a reply like: "this is the same as a template" is better than 
> "your proposals are of poor quality". It doesn't give a nice look to D, 
> specially coming from one of its main leaders.

I agree with Ary above and would also like to add that in the ML family of languages all the variables are also default auto typed: 
E.g.: 
fun add a b = a + b 

'add' would have the type ('a, 'a) -> 'a and the type inference engine will also infer that 'a must provide the + operator. 
I feel that this is more natural than having a dedicated function template syntax. 
Better yet, instead of auto parameters, just make parameter types optional (as in ML) and let the compiler generate the template. 

foo(a, b) { return a + b; } // will be lowered to:
T foo(T) (T a, T b) { return a + b; } 

Types are already inferred for delegate literals so why not extend this to regular functions too? 




More information about the Digitalmars-d mailing list