Multi typed value return.

Matthew Ong ongbp at yahoo.com
Thu May 12 04:55:02 PDT 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.





More information about the Digitalmars-d mailing list