| Thread overview | |||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
April 21, 2004 Multiple value returns in D? | ||||
|---|---|---|---|---|
| ||||
I dont see multiple value returns in D. Wouldnt it be nice to finally have it anywhere else than in scheme? From a logical standpoint,we are already doing it anyway with reference parameters. Its just that something like (y2, error)fct(y1, someArg) would be more clear than just fct(y1, someArgs, y2, err). newbie1654 | ||||
April 21, 2004 Re: Multiple value returns in D? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to lacs | lacs wrote: >I dont see multiple value returns in D. Wouldnt it be nice to finally have it >anywhere else than in scheme? From a logical standpoint,we are already doing it >anyway with reference parameters. Its just that something like (y2, >error)fct(y1, someArg) would be more clear than just fct(y1, someArgs, y2, err). > > >newbie1654 > > This has been discussed before. Maybe if we're lucky it'll get into 2.0, but I don't see it in 1.0 as there are too many subtle problems. -- -Anderson: http://badmama.com.au/~anderson/ | |||
April 21, 2004 Re: Multiple value returns in D? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to J Anderson | J Anderson wrote:
> lacs wrote:
>
>> I dont see multiple value returns in D. Wouldnt it be nice to finally have it
>> anywhere else than in scheme? From a logical standpoint,we are already doing it
>> anyway with reference parameters. Its just that something like (y2,
>> error)fct(y1, someArg) would be more clear than just fct(y1, someArgs, y2, err).
>>
>>
>> newbie1654
>>
>>
> This has been discussed before. Maybe if we're lucky it'll get into 2.0, but I don't see it in 1.0 as there are too many subtle problems.
>
Ok I found and read some discussion about it. It seemed a real puzzle because of some stack and overloading considerations. However, just making the compiler considere
float, float foo(in float, in float);
the same as
void foo(in float, in float, out float, out float);
would not be very complicated. Does it really needs to be more sophisticated then that?
| |||
April 21, 2004 Re: Multiple value returns in D? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to lacs | lacs schrieb:
> I dont see multiple value returns in D. Wouldnt it be nice to finally have it
> anywhere else than in scheme? From a logical standpoint,we are already doing it
> anyway with reference parameters. Its just that something like (y2,
> error)fct(y1, someArg) would be more clear than just fct(y1, someArgs, y2, err).
Scroll down a bit, this question was asked yesterday or so and i answered extensively.
-eye
| |||
April 22, 2004 Re: Multiple value returns in D? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to lacs | On Wed, 21 Apr 2004 17:50:19 -0400, lacs wrote: > J Anderson wrote: >> lacs wrote: >> >>> I dont see multiple value returns in D. Wouldnt it be nice to finally >>> have it >>> anywhere else than in scheme? From a logical standpoint,we are already >>> doing it >>> anyway with reference parameters. Its just that something like (y2, >>> error)fct(y1, someArg) would be more clear than just fct(y1, someArgs, >>> y2, err). >>> >>> >>> newbie1654 >>> >>> >> This has been discussed before. Maybe if we're lucky it'll get into 2.0, but I don't see it in 1.0 as there are too many subtle problems. >> > Ok I found and read some discussion about it. It seemed a real puzzle > because of some stack and overloading considerations. However, just > making the compiler considere > float, float foo(in float, in float); > the same as > void foo(in float, in float, out float, out float); > would not be very complicated. Does it really needs to be more > sophisticated then that? I too think that the "Multiple Return Value" issue is just one of syntax and not semantics. It is *just* a way of coding in such a way to make it easy for the code reader/maintainer to see that a routine is returning more than one distinct value. The difference would be ... ValA, ValB = foo(inpA, inpB); as opposed to foo(inpA, inpB, ValA, ValB); which is more clear to readers what the routine is actually doing with the variables used. -- Derek 22/Apr/04 10:43:07 AM | |||
April 22, 2004 Re: Multiple value returns in D? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | Derek Parnell wrote: > ValA, ValB = foo(inpA, inpB); > >as opposed to > > foo(inpA, inpB, ValA, ValB); > >which is more clear to readers what the routine is actually doing with the >variables used. > > A problem with this form is the way the comma operator works. For example, what you presented is valid code ATM! int func() { return 0; } void main() { int a, b; a, b = func(); } Now you could introduce rules to take this out of the language (or change the syntax). It's just one of the subtle bugs and language changes I was talking about to implement such a thing. -- -Anderson: http://badmama.com.au/~anderson/ | |||
April 22, 2004 Re: Multiple value returns in D? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | Derek Parnell wrote:
>
> ValA, ValB = foo(inpA, inpB);
>
Not to be annoying, but I don't know that I like that syntax. I think something with parenthesis would be much better... but then, why not just return an array? It's practically the same thing, isn't it?
PHP, for example, provides a "array extracting" construct, which works as such:
list ($first_element, $second_element) = array(0 => 1, 1 => 2);
I believe Perl also has this, basically, except it's like this:
@array = (1, 2);
($first_element, $second_element) = @array;
But I think that syntax is ulgy too. I like the "list" construct because it makes it more logical.
list (ValA, ValB) = foo(inpA, inpB);
-[Unknown]
| |||
April 22, 2004 Re: Multiple value returns in D? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to J Anderson | On Thu, 22 Apr 2004 09:04:07 +0800, J Anderson wrote: > Derek Parnell wrote: > >> ValA, ValB = foo(inpA, inpB); >> >>as opposed to >> >> foo(inpA, inpB, ValA, ValB); >> >>which is more clear to readers what the routine is actually doing with the variables used. >> >> > A problem with this form is the way the comma operator works. For example, what you presented is valid code ATM! > > int func() { return 0; } > > void main() > { > int a, b; > a, b = func(); > } > > Now you could introduce rules to take this out of the language (or change the syntax). It's just one of the subtle bugs and language changes I was talking about to implement such a thing. I'm sorry that I didn't make myself clear. I wasn't suggesting *any* specific syntax, just the concept that a syntax change to support this idea might be worth considering. The example I gave was just to show something - not the precise syntax that D could use. That would need much more discussion yet. -- Derek 22/Apr/04 11:11:09 AM | |||
April 22, 2004 Re: Multiple value returns in D? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Unknown W. Brackets | On Wed, 21 Apr 2004 18:05:04 -0700, Unknown W. Brackets wrote: > Derek Parnell wrote: >> >> ValA, ValB = foo(inpA, inpB); >> > > Not to be annoying, but I don't know that I like that syntax. I think something with parenthesis would be much better... but then, why not just return an array? It's practically the same thing, isn't it? You are not annoying ;-) I wasn't promoting any specific syntax, just the idea that a syntax change for D that supports multiple return values might be a useful idea. > PHP, for example, provides a "array extracting" construct, which works as such: > > list ($first_element, $second_element) = array(0 => 1, 1 => 2); > > I believe Perl also has this, basically, except it's like this: > > @array = (1, 2); > ($first_element, $second_element) = @array; > > But I think that syntax is ulgy too. I like the "list" construct because it makes it more logical. > > list (ValA, ValB) = foo(inpA, inpB); > > -[Unknown] And I'm sure there are many others out there too. -- Derek 22/Apr/04 11:13:43 AM | |||
April 22, 2004 Re: Multiple value returns in D? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | Derek Parnell wrote: > >I'm sorry that I didn't make myself clear. I wasn't suggesting *any* >specific syntax, just the concept that a syntax change to support this idea >might be worth considering. The example I gave was just to show something - >not the precise syntax that D could use. That would need much more >discussion yet. > > > I would like multiple return types as well. There are huge threads earlier on this. I don't expect you to read them all but there must be at least a dozen different ways of doing multiple return values. -- -Anderson: http://badmama.com.au/~anderson/ | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply