Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
September 29, 2007 Functions which return multiple values? | ||||
---|---|---|---|---|
| ||||
Without using an array or struct, can D return more than one value from a function? If not, why isn't this a desirable feature for a programming language to have? |
September 29, 2007 Re: Functions which return multiple values? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dan | Dan schrieb:
> Without using an array or struct, can D return more than one value from a function? If not, why isn't this a desirable feature for a programming language to have?
You can use "out" arguments or a tuple return type.
|
September 29, 2007 Re: Functions which return multiple values? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frank Benoit | Frank Benoit wrote:
> Dan schrieb:
>> Without using an array or struct, can D return more than one value from a function? If not, why isn't this a desirable feature for a programming language to have?
>
> You can use "out" arguments or a tuple return type.
At the end of the video of Walter's talk at the NWCPP users group he says he'd like to add the ability to return tuples. But I don't know if that's still something rattling around in his mind or not.
--bb
|
September 29, 2007 Re: Functions which return multiple values? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bill Baxter | Bill Baxter schrieb:
> Frank Benoit wrote:
>> Dan schrieb:
>>> Without using an array or struct, can D return more than one value from a function? If not, why isn't this a desirable feature for a programming language to have?
>>
>> You can use "out" arguments or a tuple return type.
>
> At the end of the video of Walter's talk at the NWCPP users group he says he'd like to add the ability to return tuples. But I don't know if that's still something rattling around in his mind or not.
>
> --bb
Hm right, functions cannot return a tuple directly.
In my current code I use
template Struct(T...){
struct Struct{
T t;
}
}
and in functions....
Struct!(long, bool[]) get(){
Struct!(long, bool[]) res;
res.t[0] = 34;
res.t[1] = [ true, false ];
return res;
}
|
September 30, 2007 Re: Functions which return multiple values? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dan | Dan wrote:
> Without using an array or struct, can D return more than one value from a function? If not, why isn't this a desirable feature for a programming language to have?
This is possible with user-defined tuples, but the built-in tuples need to be wrapped in a struct to do the same.
Sean
|
Copyright © 1999-2021 by the D Language Foundation