digitalmars.D - Multi typed value return.
- Matthew Ong <ongbp yahoo.com> May 12 2011
- Adam Ruppe <destructionator gmail.com> May 12 2011
- Matthew Ong <ongbp yahoo.com> May 12 2011
- Jonathan M Davis <jmdavisProg gmx.com> May 12 2011
Hi D developer, Any plan to support this really cool feature of Multiple type return value? http://golang.org/doc/effective_go.html#multiple-returns In Java and C++ we need to use the HashMap to do this and does not have compiler checking and need runtime casting checking? func (file *File) Write(b []byte) (n int, err Error) // different type. func nextInt(b []byte, i int) (int, int) // same type func nextInt(b []byte, pos int) (value, nextPos int) // same type. These ability in D will be useful to reduced the amount of extra runtime casting and checking a function. I am aware of this in/out parameter like in the MS SQL/PL/SQL. However that would meant that I would need to create all those variables in stack before I call updateRow. //void updateRow(int out myNum, string out myStr); Where else if D allows : // function updating the collection table and returns the number of rows updated and also all the keys updated. (int changeCount, string[] autoId ) updateRowA(int myNum, string myStr); That would allow the caller to only create the variable needed in the stack post calling the updateRowA. Hope this is a good idea? Please share what u think. Matthew Ong.
May 12 2011
Look at http://dpldocs.info/std.typecons.Tuple Note though that D isn't a kitchen sink - features aren't added to the language just because. More often than not though, the existing features can do what you ask for if you combine them well. Spend some time working with the language and you'll probably find it's more than adequate for real work.
May 12 2011
Hi Adam, Hey. Thanks for that sample from an experience developer. That save me lot of time for figuring them out. That is a useful work around that does not need me to create a class/struct for a simple purpose to define and call a function to return this manner.
May 12 2011
On 2011-05-12 04:55, Matthew Ong wrote:Hi D developer, Any plan to support this really cool feature of Multiple type return value? http://golang.org/doc/effective_go.html#multiple-returns In Java and C++ we need to use the HashMap to do this and does not have compiler checking and need runtime casting checking? func (file *File) Write(b []byte) (n int, err Error) // different type. func nextInt(b []byte, i int) (int, int) // same type func nextInt(b []byte, pos int) (value, nextPos int) // same type. These ability in D will be useful to reduced the amount of extra runtime casting and checking a function. I am aware of this in/out parameter like in the MS SQL/PL/SQL. However that would meant that I would need to create all those variables in stack before I call updateRow. //void updateRow(int out myNum, string out myStr); Where else if D allows : // function updating the collection table and returns the number of rows updated and also all the keys updated. (int changeCount, string[] autoId ) updateRowA(int myNum, string myStr); That would allow the caller to only create the variable needed in the stack post calling the updateRowA. Hope this is a good idea?
D is not at a stage where we're looking to implement new features. We're looking to stabilize the language as it is and fully implement the few features which have been introduced but not fully implemented. So, don't expect new features to be added to the language any time soon. The current version of the language is D2. Once D2 has stabilized and is completely production-ready, we may begin on a new version of the language which introduces new features, but that's a ways down the road. For now, if you want multiple return values, the closest that you're going to get is either using out or ref function parameters to return values via the arguments to a function or to return a std.typeconse.Tuple of values. - Jonathan M Davis
May 12 2011









Matthew Ong <ongbp yahoo.com> 