digitalmars.D - tuple trouble
- =?iso-8859-1?q?Knud_S=F8rensen?= (18/18) Oct 30 2005 I am having some trouble to see if tuples types would be a good idea in ...
- Georg Wrede (28/48) Oct 30 2005 This Tuple Thing pops up at regular intervals.
- =?ISO-8859-1?Q?Jari-Matti_M=E4kel=E4?= (7/9) Oct 31 2005 I don't think there's much point in making the language any slower. It's...
- Georg Wrede (6/16) Oct 31 2005 Exactly. So, those who want the library can write it right now, and this...
- Sean Kelly (8/12) Oct 31 2005 "auto" makes this very easy to do too:
I am having some trouble to see if tuples types would be a good idea in d. So, I would like to hear your opinions. First we already uses tuples for function arguments like: func_1(elem_1, elem_2,elem_3); But what if one could do something like. tuple arg= new tuple(elem_1,elem_2,elem_3); res1=func_1 arg; ... res_n=func_n arg; Would that be useful at all ?? Then if functions could return tuples we could write: res_21=func_2 func_1 arg; // for the combined function It would be more like the mathematical notation func_2 o func_1(arg) but would it just lead to more spaghetti code ? What do you think ?
Oct 30 2005
Knud Sørensen wrote:I am having some trouble to see if tuples types would be a good idea in d. So, I would like to hear your opinions. First we already uses tuples for function arguments like: func_1(elem_1, elem_2,elem_3); But what if one could do something like. tuple arg= new tuple(elem_1,elem_2,elem_3); res1=func_1 arg; ... res_n=func_n arg; Would that be useful at all ?? Then if functions could return tuples we could write: res_21=func_2 func_1 arg; // for the combined function It would be more like the mathematical notation func_2 o func_1(arg) but would it just lead to more spaghetti code ? What do you think ?This Tuple Thing pops up at regular intervals. Of course it would be nice to have fluid tuples (a la Euphoria, for example). The you could write: real [] foo = sin(2.3, 0.2, 0.002, 0.55); But then, can any of the proponents imagine what kind of rewriting of the entire language (and rewriting of the entire front-end) this would require? Plus, implementing this would strain (as in making slower) everything we do with the language. Out of which 99% would still be "conventional", that is, functions returning exactly one value anyhow. If somebody really wanted to do this Tuple Thing, then it would not be too hard to write a library for Tuple Proof Functions. Those would take 1..n arguments and return (possibly, depending on the context) 1..n results. No prob, D is well suited to writing that library. Then we could have something like: typedef Object [] tuple; tuple sin(...) // whatever, probably a 0..n list of reals { tuple daStuff = new tuple(); // so munch a list of arguments, one at a time // if it's a real, do sin it // else do something proper or polite with it // finally return the generated pile of stool return daStuff; } Thus, the question arises, do we really have to interfere with the language itself to get this done, or can we just write the library?
Oct 30 2005
Georg Wrede wrote:Thus, the question arises, do we really have to interfere with the language itself to get this done, or can we just write the library?I don't think there's much point in making the language any slower. It's pretty convenient to implement this as a separate library. If Walter is able to merge this syntax into the language without much trouble / performance issues, it might be even useful. BTW, does Walter have any plans to support multiple function return values in the future?
Oct 31 2005
Jari-Matti Mäkelä wrote:Georg Wrede wrote:Exactly. So, those who want the library can write it right now, and this would let Walter do more important stuff. Besides, living with multiple return values is a "way of life", which can already be done in D. It's a different way of thinking, just like OO, structural, procedural, generic, and whatever-programming.Thus, the question arises, do we really have to interfere with the language itself to get this done, or can we just write the library?I don't think there's much point in making the language any slower. It's pretty convenient to implement this as a separate library. If Walter is able to merge this syntax into the language without much trouble / performance issues, it might be even useful.
Oct 31 2005
Georg Wrede wrote:Besides, living with multiple return values is a "way of life", which can already be done in D. It's a different way of thinking, just like OO, structural, procedural, generic, and whatever-programming."auto" makes this very easy to do too: Tuple!(int,int,int) getStuff(); auto ret = getStuff(); int a = ret.val!(1); int b = ret.val!(2); int c = ret.val!(3); Sean
Oct 31 2005