Multi typed value return.

Jonathan M Davis jmdavisProg at gmx.com
Thu May 12 08:13:48 PDT 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


More information about the Digitalmars-d mailing list