Re: Multiple return values...

2012-03-11 Thread Timon Gehr
On 03/11/2012 07:57 PM, Andrei Alexandrescu wrote: On 3/11/12 6:50 AM, Manu wrote: On 11 March 2012 05:04, Andrei Alexandrescu mailto:seewebsiteforem...@erdani.org>> There is no difference. A Tuple is a product type, exactly like superposing arbitrary values together. So you're saying that what

Re: Multiple return values...

2012-03-11 Thread Timon Gehr
On 03/11/2012 07:58 PM, Andrei Alexandrescu wrote: On 3/11/12 7:52 AM, Timon Gehr wrote: It is extremely obvious how multiple return values should work. (int, int) fun(); writeln(fun()); auto a = fun(); writeln(a); What should happen? Andrei That largely depends on fun. For instance, if

Re: Multiple return values...

2012-03-11 Thread Timon Gehr
On 03/11/2012 08:17 PM, Andrei Alexandrescu wrote: If you create a variable of type TypeTuple!(ReturnType1, ReturnType2), what's its layout? That is context-dependent: union U{ TypeTuple!(int, double) x; // superimposed according to union abi } struct S{ TypeTuple!(int, double) x; //

Re: Multiple return values...

2012-03-11 Thread Robert Jacques
On Sun, 11 Mar 2012 12:39:56 -0500, Manu wrote: On 11 March 2012 18:50, Robert Jacques wrote: On Sun, 11 Mar 2012 05:57:05 -0500, Manu wrote: On 11 March 2012 04:35, Sean Cavanaugh wrote: On 3/10/2012 8:08 PM, Mantis wrote: [snip] And Walter has talked about using the XMM registers to

Re: Multiple return values...

2012-03-11 Thread Timon Gehr
On 03/11/2012 09:30 PM, Robert Jacques wrote: On Sun, 11 Mar 2012 12:39:56 -0500, Manu wrote: On 11 March 2012 18:50, Robert Jacques wrote: On Sun, 11 Mar 2012 05:57:05 -0500, Manu wrote: On 11 March 2012 04:35, Sean Cavanaugh wrote: On 3/10/2012 8:08 PM, Mantis wrote: [snip] And Walte

Re: Multiple return values...

2012-03-11 Thread Manu
On 11 March 2012 20:57, Andrei Alexandrescu wrote: > I don't know what you mean by "structured type". What I mean by "product > type" is this: > http://en.wikipedia.org/wiki/**Product_type > The first line on that page states my meaning verbatim: "In pr

Re: Multiple return values...

2012-03-11 Thread Timon Gehr
On 03/11/2012 09:41 PM, Manu wrote: On 11 March 2012 20:57, Andrei Alexandrescu ... Regarding low-level efficiency, the main issue is that structs and function argument lists have distinct layouts. Consider: import std.stdio, std.typecons; int a(int b, int c) { return

Re: Multiple return values...

2012-03-11 Thread Robert Jacques
On Sun, 11 Mar 2012 15:38:21 -0500, Timon Gehr wrote: On 03/11/2012 09:30 PM, Robert Jacques wrote: On Sun, 11 Mar 2012 12:39:56 -0500, Manu wrote: On 11 March 2012 18:50, Robert Jacques wrote: On Sun, 11 Mar 2012 05:57:05 -0500, Manu wrote: On 11 March 2012 04:35, Sean Cavanaugh wrote:

Re: Multiple return values...

2012-03-11 Thread Timon Gehr
On 03/11/2012 10:57 PM, Robert Jacques wrote: On Sun, 11 Mar 2012 15:38:21 -0500, Timon Gehr wrote: On 03/11/2012 09:30 PM, Robert Jacques wrote: Manu, why are you assuming that the struct is returned in any sort of fixed memory layout? Because that is what the ABI says. * 1, 2 and 4 byte

Re: Multiple return values...

2012-03-11 Thread Robert Jacques
On Sun, 11 Mar 2012 05:56:03 -0500, Manu wrote: On 11 March 2012 03:45, Robert Jacques wrote: On Sat, 10 Mar 2012 19:27:05 -0600, Manu wrote: On 11 March 2012 00:25, Sean Cavanaugh wrote: On 3/10/2012 4:37 AM, Manu wrote: [snip] Manu, please go read the D ABI (http://dlang.org/abi.html

Re: Multiple return values...

2012-03-11 Thread Robert Jacques
On Sun, 11 Mar 2012 17:48:53 -0500, Timon Gehr wrote: On 03/11/2012 10:57 PM, Robert Jacques wrote: On Sun, 11 Mar 2012 15:38:21 -0500, Timon Gehr wrote: On 03/11/2012 09:30 PM, Robert Jacques wrote: Manu, why are you assuming that the struct is returned in any sort of fixed memory layout?

Re: Multiple return values...

2012-03-11 Thread Timon Gehr
On 03/11/2012 11:58 PM, Robert Jacques wrote: Manu was arguing that MRV were somehow special and had mystical optimization potential. That's simply not true. Not exactly mystical, but it is certainly there. void main(){ auto a = foo(); // MRV/struct return bar(&a.x); // defined in a di

Re: Multiple return values...

2012-03-11 Thread Manu
On 12 March 2012 00:50, Robert Jacques wrote: > On Sun, 11 Mar 2012 05:56:03 -0500, Manu wrote: > >> On 11 March 2012 03:45, Robert Jacques wrote: >> >>> On Sat, 10 Mar 2012 19:27:05 -0600, Manu wrote: >>> On 11 March 2012 00:25, Sean Cavanaugh wrote: On 3/10/2012 4:37 AM, Man

Re: Multiple return values...

2012-03-11 Thread Manu
On 12 March 2012 00:58, Robert Jacques wrote: > That's an argument for using the right register for the job. And we can / > will be doing this on x86-64, as other compilers have already done. Manu > was arguing that MRV were somehow special and had mystical optimization > potential. That's simply

Re: Multiple return values...

2012-03-11 Thread Andrew Wiley
On Sun, Mar 11, 2012 at 7:44 PM, Manu wrote: > On 12 March 2012 00:58, Robert Jacques wrote: >> >> That's an argument for using the right register for the job. And we can / >> will be doing this on x86-64, as other compilers have already done. Manu was >> arguing that MRV were somehow special and

Re: Multiple return values...

2012-03-11 Thread Robert Jacques
On Sun, 11 Mar 2012 18:15:31 -0500, Timon Gehr wrote: On 03/11/2012 11:58 PM, Robert Jacques wrote: Manu was arguing that MRV were somehow special and had mystical optimization potential. That's simply not true. Not exactly mystical, but it is certainly there. void main(){ auto a = foo

Re: Multiple return values...

2012-03-11 Thread Robert Jacques
On Sun, 11 Mar 2012 19:44:32 -0500, Manu wrote: On 12 March 2012 00:58, Robert Jacques wrote: That's an argument for using the right register for the job. And we can / will be doing this on x86-64, as other compilers have already done. Manu was arguing that MRV were somehow special and had m

Re: Multiple return values...

2012-03-11 Thread Andrei Alexandrescu
On 3/11/12 6:30 PM, Manu wrote: D should define an MRV ABI which is precisely the ABI for passing multiple args TO a function, but in reverse, for any given architecture. This also has the lovely side effect of guaranteeing correct argument placement for chain-called functions. I'm quoting this

Re: Multiple return values...

2012-03-11 Thread Mantis
12.03.2012 4:00, Robert Jacques пишет: On Sun, 11 Mar 2012 18:15:31 -0500, Timon Gehr wrote: On 03/11/2012 11:58 PM, Robert Jacques wrote: Manu was arguing that MRV were somehow special and had mystical optimization potential. That's simply not true. Not exactly mystical, but it is certainl

Re: Multiple return values...

2012-03-11 Thread Robert Jacques
On Sun, 11 Mar 2012 18:30:33 -0500, Manu wrote: On 12 March 2012 00:50, Robert Jacques wrote: On Sun, 11 Mar 2012 05:56:03 -0500, Manu wrote: On 11 March 2012 03:45, Robert Jacques wrote: On Sat, 10 Mar 2012 19:27:05 -0600, Manu wrote: On 11 March 2012 00:25, Sean Cavanaugh [snip] x

Re: Multiple return values...

2012-03-11 Thread Robert Jacques
On Sun, 11 Mar 2012 21:49:52 -0500, Mantis wrote: 12.03.2012 4:00, Robert Jacques пишет: On Sun, 11 Mar 2012 18:15:31 -0500, Timon Gehr wrote: On 03/11/2012 11:58 PM, Robert Jacques wrote: Manu was arguing that MRV were somehow special and had mystical optimization potential. That's simply

Re: Multiple return values...

2012-03-12 Thread Timon Gehr
On 03/12/2012 05:01 AM, Robert Jacques wrote: On Sun, 11 Mar 2012 21:49:52 -0500, Mantis wrote: 12.03.2012 4:00, Robert Jacques пишет: On Sun, 11 Mar 2012 18:15:31 -0500, Timon Gehr wrote: On 03/11/2012 11:58 PM, Robert Jacques wrote: Manu was arguing that MRV were somehow special and had

Re: Multiple return values...

2012-03-12 Thread Manu
On 12 March 2012 04:44, Andrei Alexandrescu wrote: > On 3/11/12 6:30 PM, Manu wrote: > >> D should >> define an MRV ABI which is precisely the ABI for passing multiple args >> >> TO a function, but in reverse, for any given architecture. This also has >> the lovely side effect of guaranteeing corr

Re: Multiple return values...

2012-03-12 Thread Manu
On 12 March 2012 04:00, Robert Jacques wrote: > On Sun, 11 Mar 2012 18:15:31 -0500, Timon Gehr wrote: > > On 03/11/2012 11:58 PM, Robert Jacques wrote: >> >>> Manu was arguing that MRV were somehow special and had mystical >>> optimization potential. That's simply not true. >>> >> >> Not exactl

Re: Multiple return values...

2012-03-12 Thread Mantis
12.03.2012 6:01, Robert Jacques пишет: On Sun, 11 Mar 2012 21:49:52 -0500, Mantis wrote: [...] That's the point of discussion. Fields of structure may not be optimized away, because they are not independent variables. In D you have unchecked pointer-to-pointer casts, and results of these casts

Re: Multiple return values...

2012-03-12 Thread RivenTheMage
So, function with MRV is basically the function that returns Tuple where one can specify return convention? --- auto fun() { return(Windows) tuple(1, 2.0f); } (int x, float y) = fun(); ---

Re: Multiple return values...

2012-03-12 Thread Iain Buclaw
On 12 March 2012 01:37, Andrew Wiley wrote: > On Sun, Mar 11, 2012 at 7:44 PM, Manu wrote: >> On 12 March 2012 00:58, Robert Jacques wrote: >>> >>> That's an argument for using the right register for the job. And we can / >>> will be doing this on x86-64, as other compilers have already done. Ma

Re: Multiple return values...

2012-03-12 Thread Iain Buclaw
On 12 March 2012 00:44, Manu wrote: > On 12 March 2012 00:58, Robert Jacques wrote: >> >> That's an argument for using the right register for the job. And we can / >> will be doing this on x86-64, as other compilers have already done. Manu was >> arguing that MRV were somehow special and had myst

Re: Multiple return values...

2012-03-12 Thread Manu
On 12 March 2012 19:03, Iain Buclaw wrote: > On 12 March 2012 00:44, Manu wrote: > > On 12 March 2012 00:58, Robert Jacques wrote: > >> > >> That's an argument for using the right register for the job. And we can > / > >> will be doing this on x86-64, as other compilers have already done. > Man

Re: Multiple return values...

2012-03-12 Thread Iain Buclaw
On 12 March 2012 17:22, Manu wrote: > On 12 March 2012 19:03, Iain Buclaw wrote: >> >> On 12 March 2012 00:44, Manu wrote: >> > On 12 March 2012 00:58, Robert Jacques wrote: >> >> >> >> That's an argument for using the right register for the job. And we can >> >> / >> >> will be doing this on x

Re: Multiple return values...

2012-03-12 Thread Iain Buclaw
On 12 March 2012 17:49, Iain Buclaw wrote: > On 12 March 2012 17:22, Manu wrote: >> On 12 March 2012 19:03, Iain Buclaw wrote: >>> >>> On 12 March 2012 00:44, Manu wrote: >>> > On 12 March 2012 00:58, Robert Jacques wrote: >>> >> >>> >> That's an argument for using the right register for the j

Re: Multiple return values...

2012-03-12 Thread Manu
On 12 March 2012 19:49, Iain Buclaw wrote: > > OK, -msse2 is not an ARM target option. :~) > Oh sorry, I thought you were asking about the x86 codegen ;) I used -S -O2 -float-abi=hard Looking around, the "Procedure Call Standard for the ARM Architecture" > specifically says (section 5.4: Resul

Re: Multiple return values...

2012-03-12 Thread Iain Buclaw
On 12 March 2012 17:59, Manu wrote: > On 12 March 2012 19:49, Iain Buclaw wrote: >> >> OK, -msse2 is not an ARM target option. :~) > > > Oh sorry, I thought you were asking about the x86 codegen ;) > > I used -S -O2 -float-abi=hard > > >> Looking around, the "Procedure Call Standard for the ARM A

Re: Multiple return values...

2012-03-12 Thread Robert Jacques
On Mon, 12 Mar 2012 02:15:55 -0500, Timon Gehr wrote: On 03/12/2012 05:01 AM, Robert Jacques wrote: On Sun, 11 Mar 2012 21:49:52 -0500, Mantis wrote: 12.03.2012 4:00, Robert Jacques пишет: On Sun, 11 Mar 2012 18:15:31 -0500, Timon Gehr wrote: On 03/11/2012 11:58 PM, Robert Jacques wrote:

Re: Multiple return values...

2012-03-12 Thread Robert Jacques
On Mon, 12 Mar 2012 04:46:45 -0500, Mantis wrote: 12.03.2012 6:01, Robert Jacques пишет: On Sun, 11 Mar 2012 21:49:52 -0500, Mantis wrote: [...] That's the point of discussion. Fields of structure may not be optimized away, because they are not independent variables. In D you have unchecked p

Re: Multiple return values...

2012-03-12 Thread Robert Jacques
On Mon, 12 Mar 2012 04:25:54 -0500, Manu wrote: On 12 March 2012 04:00, Robert Jacques wrote: On Sun, 11 Mar 2012 18:15:31 -0500, Timon Gehr wrote: On 03/11/2012 11:58 PM, Robert Jacques wrote: Manu was arguing that MRV were somehow special and had mystical optimization potential. That'

Re: Multiple return values...

2012-03-12 Thread Martin Nowak
Is this basically like saying it'll never happen? There is already a pending pull request implementing the syntax, that addresses half of the feature straight up.. codegen can come later, I agreed earlier that it is of lesser importance. You don't see the immediate value in a convenient MRV syntax

Re: Multiple return values...

2012-03-12 Thread Andrei Alexandrescu
On 3/12/12 3:37 AM, Manu wrote: On 12 March 2012 04:44, Andrei Alexandrescu mailto:seewebsiteforem...@erdani.org>> wrote: On 3/11/12 6:30 PM, Manu wrote: D should define an MRV ABI which is precisely the ABI for passing multiple args TO a function, but in re

Re: Multiple return values...

2012-03-13 Thread Manu
On 13 March 2012 06:45, Andrei Alexandrescu wrote: > You see, at this point I have no idea what to believe anymore. You argued > very strongly from the position of one whose life depends on efficiency. > Here and there you'd mix some remark about syntax, and I'd like "whaa?..." > but generally dis

Re: Multiple return values...

2012-03-13 Thread Iain Buclaw
On 13 March 2012 09:12, Manu wrote: > On 13 March 2012 06:45, Andrei Alexandrescu > wrote: >> >> You see, at this point I have no idea what to believe anymore. You argued >> very strongly from the position of one whose life depends on efficiency. >> Here and there you'd mix some remark about synt

Re: Multiple return values...

2012-03-13 Thread Manu
On 13 March 2012 13:27, Iain Buclaw wrote: > What about alternative optimisations for MRV, rather than stating that > it should always be returned in registers where possible (and breaking > ABI on all target platforms). What about, for example, using named > return value optimisation in this ca

Re: Multiple return values...

2012-03-13 Thread Andrei Alexandrescu
On 3/13/12 4:12 AM, Manu wrote: I think I feel a sense of urgency towards the ABI aspect because it is a breaking change, and I suspect the longer anything like that is left, the less likely/more risky it becomes. If it gets delayed for 6-12 months, are you honestly more or less likely to say it'

Re: Multiple return values...

2012-03-13 Thread Manu
On 13 March 2012 16:44, Andrei Alexandrescu wrote: > I thought more about it and we should be fine with two functions > (untested): > > enum Skip {}; > @property ref Skip skip() { >static __gshared Skip result; >return result; > } > > void scatter(T, U...)(auto ref T source, ref U targets)

Re: Multiple return values...

2012-03-13 Thread Andrei Alexandrescu
On 3/13/12 10:48 AM, Manu wrote: float t; ... (myStruct.pos, t, _, int err) = intersectThings(); I actually find the scatter syntax better than this. Anyway, I hope you'll agree there's not much difference pragmatically. Andrei

Re: Multiple return values...

2012-03-13 Thread Manu
On 13 March 2012 18:07, Andrei Alexandrescu wrote: > On 3/13/12 10:48 AM, Manu wrote: > >> float t; >> ... >> (myStruct.pos, t, _, int err) = intersectThings(); >> > > I actually find the scatter syntax better than this. Anyway, I hope you'll > agree there's not much difference pragmatically. Th

Re: Multiple return values...

2012-03-13 Thread Andrei Alexandrescu
On 3/13/12 12:02 PM, Manu wrote: There's a few finicky differences. I'm still of the understanding (and I may be wrong, still mystified by some of D's more complicated template syntax) that once you give the returned tuple a name, it is structurally bound to the stack. At that point, passing any

Re: Multiple return values...

2012-03-13 Thread Manu
On 13 March 2012 19:25, Andrei Alexandrescu wrote: > On 3/13/12 12:02 PM, Manu wrote: > >> There's a few finicky differences. I'm still of the understanding (and I >> may be wrong, still mystified by some of D's more complicated template >> syntax) that once you give the returned tuple a name, it

Re: Multiple return values...

2012-03-13 Thread Jose Armando Garcia
On Tue, Mar 13, 2012 at 9:07 AM, Andrei Alexandrescu wrote: > On 3/13/12 10:48 AM, Manu wrote: >> >> float t; >> ... >> (myStruct.pos, t, _, int err) = intersectThings(); > This can be checked at compile time. The D compiler can check that the number of arguments and the types match. > > I actua

Re: Multiple return values...

2012-03-13 Thread Andrei Alexandrescu
On 3/13/12 2:07 PM, Jose Armando Garcia wrote: On Tue, Mar 13, 2012 at 9:07 AM, Andrei Alexandrescu wrote: On 3/13/12 10:48 AM, Manu wrote: float t; ... (myStruct.pos, t, _, int err) = intersectThings(); This can be checked at compile time. The D compiler can check that the number of arg

Re: Multiple return values...

2012-03-13 Thread Andrei Alexandrescu
On 3/13/12 1:20 PM, Manu wrote: What value does it add over Kenji's change? Is this because Kenji's change is unable to perform direct to existing variables? Yes. My understanding from early in the thread was that Kenji's change hides the returned tuple, and performs a convenient unpack. How

Re: Multiple return values...

2012-03-13 Thread Manu
On 13 March 2012 21:40, Andrei Alexandrescu wrote: > On 3/13/12 1:20 PM, Manu wrote: > >> What value does it add over Kenji's change? Is this because Kenji's >> change is unable to perform direct to existing variables? >> > > Yes. > > > My understanding from early in the thread was that Kenji's c

Re: Multiple return values...

2012-03-13 Thread Andrei Alexandrescu
On 3/13/12 2:57 PM, Manu wrote: And you think that's more readable and intuitive than: (v1, v2, v3) = fun(); ? Yes (e.g. when I see the commas my mind starts running in all directions because that's valid code nowadays that ignores v1 and v2 and keeps v3 as an lvalue). Let me put it another

Re: Multiple return values...

2012-03-13 Thread Martin Nowak
Shall we discuss the shortcomings of his implementation? Can someone demonstrate the details of his implementation? From the little examples up in the thread, it looked like you could only declare new variables inline, but not assign out to existing ones. I'd say this needs to be added too, and p

Re: Multiple return values...

2012-03-14 Thread Ary Manzana
On 3/13/12 6:12 PM, Andrei Alexandrescu wrote: On 3/13/12 2:57 PM, Manu wrote: And you think that's more readable and intuitive than: (v1, v2, v3) = fun(); ? Yes (e.g. when I see the commas my mind starts running in all directions because that's valid code nowadays that ignores v1 and v2 and k

Re: Multiple return values...

2012-03-14 Thread Andrei Alexandrescu
On 3/14/12 2:02 PM, Ary Manzana wrote: On 3/13/12 6:12 PM, Andrei Alexandrescu wrote: On 3/13/12 2:57 PM, Manu wrote: And you think that's more readable and intuitive than: (v1, v2, v3) = fun(); ? Yes (e.g. when I see the commas my mind starts running in all directions because that's valid co

Re: Multiple return values...

2012-03-14 Thread Simen Kjærås
On Wed, 14 Mar 2012 20:02:50 +0100, Ary Manzana wrote: Here's what you can do in Ruby: a = 1 b = 2 # Swap the contents a, b = b, a Can you do something like that with templates in D, with a nice syntax? template to(T...) { alias T to; } auto from(T...)(T t) { struct Result { T t

Re: Multiple return values...

2012-03-14 Thread Ary Manzana
On 3/14/12 5:00 PM, Simen Kjærås wrote: On Wed, 14 Mar 2012 20:02:50 +0100, Ary Manzana wrote: Here's what you can do in Ruby: a = 1 b = 2 # Swap the contents a, b = b, a Can you do something like that with templates in D, with a nice syntax? template to(T...) { alias T to; } auto from(T

Re: Multiple return values...

2012-03-14 Thread Manu
On 14 March 2012 22:10, Ary Manzana wrote: > On 3/14/12 5:00 PM, Simen Kjærås wrote: > >> On Wed, 14 Mar 2012 20:02:50 +0100, Ary Manzana >> wrote: >> >> Here's what you can do in Ruby: >>> >>> a = 1 >>> b = 2 >>> >>> # Swap the contents >>> a, b = b, a >>> >>> Can you do something like that wi

Re: Multiple return values...

2012-03-14 Thread Andrei Alexandrescu
On 3/14/12 3:00 PM, Simen Kjærås wrote: template to(T...) { alias T to; } auto from(T...)(T t) { struct Result { T t; alias t this; } return Result( t ); } void main( ) { int a = 3; int b = 4; to!(a, b) = from(b, a); assert( a == 4 ); assert( b == 3 ); } I got reborn inside a little when se

Re: Multiple return values...

2012-03-14 Thread Derek Parnell
On Thu, 15 Mar 2012 08:52:26 +1100, Andrei Alexandrescu wrote: On 3/14/12 3:00 PM, Simen Kjærås wrote: template to(T...) { alias T to; } auto from(T...)(T t) { struct Result { T t; alias t this; } return Result( t ); } void main( ) { int a = 3; int b = 4; to!(a, b) = from(b, a); assert(

Re: Multiple return values...

2012-03-14 Thread Simen Kjærås
On Wed, 14 Mar 2012 22:52:26 +0100, Andrei Alexandrescu wrote: On 3/14/12 3:00 PM, Simen Kjærås wrote: template to(T...) { alias T to; } auto from(T...)(T t) { struct Result { T t; alias t this; } return Result( t ); } void main( ) { int a = 3; int b = 4; to!(a, b) = from(b, a); assert(

Re: Multiple return values...

2012-03-15 Thread Iain Buclaw
On 14 March 2012 22:06, Derek Parnell wrote: > On Thu, 15 Mar 2012 08:52:26 +1100, Andrei Alexandrescu > wrote: > >> On 3/14/12 3:00 PM, Simen Kjærås wrote: >>> >>> template to(T...) { >>> alias T to; >>> } >>> >>> auto from(T...)(T t) { >>> struct Result { T t; alias t this; } >>> return Result(

Re: Multiple return values...

2012-03-15 Thread Timon Gehr
On 03/14/2012 11:06 PM, Derek Parnell wrote: On Thu, 15 Mar 2012 08:52:26 +1100, Andrei Alexandrescu wrote: On 3/14/12 3:00 PM, Simen Kjærås wrote: template to(T...) { alias T to; } auto from(T...)(T t) { struct Result { T t; alias t this; } return Result( t ); } void main( ) { int a = 3; i

Re: Multiple return values...

2012-03-15 Thread Derek
On Thu, 15 Mar 2012 19:23:57 +1100, Timon Gehr wrote: I'd like to break the nexus between science and magic here. // this is used to access language built-in tuples template to(T...) { alias T to; } // this builds a struct akin to std.typecons.tuple // it contains the function parameter

Re: Multiple return values...

2012-03-15 Thread Iain Buclaw
On 15 March 2012 09:52, Derek wrote: > On Thu, 15 Mar 2012 19:23:57 +1100, Timon Gehr wrote: >>> >>> I'd like to break the nexus between science and magic here. >>> >> >> // this is used to access language built-in tuples >> template to(T...) { >>     alias T to; >> } >> >> // this builds a struc

Re: Multiple return values...

2012-03-15 Thread Andrei Alexandrescu
On 3/15/12 5:14 AM, Iain Buclaw wrote: On 15 March 2012 09:52, Derek wrote: Are you saying that the generated code is something like ... struct __tmpS { int Fa, int Fb }; __tempS __tmp; __tmp.Fa = a; __tmp.Fb = b; a = __tmp.Fb; b = __tmp.Fa; In effect, yes. Given that the

Re: Multiple return values...

2012-03-15 Thread Manu
On 15 March 2012 17:32, Andrei Alexandrescu wrote: > On 3/15/12 5:14 AM, Iain Buclaw wrote: > >> On 15 March 2012 09:52, Derek wrote: >> >>> Are you saying that the generated code is something like ... >>> >>> >>> struct __tmpS { int Fa, int Fb }; >>> __tempS __tmp; >>> __tmp.Fa = a; >>>

Re: Multiple return values...

2012-03-15 Thread Andrei Alexandrescu
On 3/15/12 11:30 AM, Manu wrote: On 15 March 2012 17:32, Andrei Alexandrescu mailto:seewebsiteforem...@erdani.org>> wrote: One note - the code is really ingenious, but I still prefer swap() in this case. It's more concise and does less work in the general case. swap(a[i + k], a[j + j

Re: Multiple return values...

2012-03-15 Thread Timon Gehr
On 03/15/2012 04:32 PM, Andrei Alexandrescu wrote: One note - the code is really ingenious, but I still prefer swap() in this case. It's more concise and does less work in the general case. swap(a[i + k], a[j + j]); only computes the indexing once (in source, too). In the general case, the

Re: Multiple return values...

2012-03-15 Thread Manu
On 15 March 2012 19:05, Andrei Alexandrescu wrote: > On 3/15/12 11:30 AM, Manu wrote: > >> On 15 March 2012 17:32, Andrei Alexandrescu >> > > >> >> >> wrote: >>One note - the code is really ingenious, but I still prefer swap() >>in this case. It's m

Re: Multiple return values...

2012-03-15 Thread Andrei Alexandrescu
On 3/15/12 12:51 PM, Manu wrote: On 15 March 2012 19:05, Andrei Alexandrescu It's a function call. Why is a function call a ugly hack? Because now we're involving libraries to perform a trivial assignment. It's not a trivial assignment, it's swapping two pieces of data. This matter has a

Re: Multiple return values...

2012-03-15 Thread foobar
On Thursday, 15 March 2012 at 17:05:00 UTC, Andrei Alexandrescu wrote: On 3/15/12 11:30 AM, Manu wrote: On 15 March 2012 17:32, Andrei Alexandrescu > wrote: One note - the code is really ingenious, but I still prefer swap() in this case. It's more co

Re: Multiple return values...

2012-03-15 Thread foobar
On Thursday, 15 March 2012 at 18:23:57 UTC, Andrei Alexandrescu wrote: I understand how the draw of reaching for new syntax is extremely alluring. I used to fall for it much more often, but over years I have hardened myself to resist it, and I think that made me a better language designer. In

Re: Multiple return values...

2012-03-15 Thread bearophile
Andrei Alexandrescu: > generally the question is not "why couldn't we add syntax X?" but > instead "why should we add syntax X?" You are right. Tuples are a basic data structure, some other language constructs are built on them (swapping items is just one of their purposes, then there is multi

Re: Multiple return values...

2012-03-15 Thread Simen Kjærås
On Thu, 15 Mar 2012 23:44:09 +0100, foobar wrote: Is swap usually inlined by the compiler? This is the body of swap for simple types: auto tmp = lhs; lhs = rhs; rhs = tmp; For more complex types: ubyte[T.sizeof] t = void; auto a = (cast(ubyte*) &lhs)[0 .. T.sizeof]; auto b = (c

Re: Multiple return values...

2012-03-15 Thread H. S. Teoh
On Fri, Mar 16, 2012 at 12:11:44AM +0100, Simen Kjærås wrote: > On Thu, 15 Mar 2012 23:44:09 +0100, foobar wrote: > > >Is swap usually inlined by the compiler? > > This is the body of swap for simple types: > > auto tmp = lhs; > lhs = rhs; > rhs = tmp; > > For more complex types: > >

Re: Multiple return values...

2012-03-15 Thread Andrei Alexandrescu
On 3/15/12 5:44 PM, foobar wrote: On Thursday, 15 March 2012 at 18:23:57 UTC, Andrei Alexandrescu wrote: I understand how the draw of reaching for new syntax is extremely alluring. I used to fall for it much more often, but over years I have hardened myself to resist it, and I think that made m

Re: Multiple return values...

2012-03-15 Thread James Miller
> 2. When was the last time you needed to swap arbitrary numbers of elements, > and so badly and frequently, you needed a new language feature for that? > > > Andrei I would like to point out Boscop's vector swizzling tutorial that he made recently as evidence that not only do you not need it that

Re: Multiple return values...

2012-03-15 Thread H. S. Teoh
On Fri, Mar 16, 2012 at 04:46:52PM +1300, James Miller wrote: > > 2. When was the last time you needed to swap arbitrary numbers of > > elements, and so badly and frequently, you needed a new language > > feature for that? > > > > > > Andrei > > I would like to point out Boscop's vector swizzling

Re: Multiple return values...

2012-03-16 Thread Iain Buclaw
On 16 March 2012 02:26, Andrei Alexandrescu wrote: > On 3/15/12 5:44 PM, foobar wrote: >> >> On Thursday, 15 March 2012 at 18:23:57 UTC, Andrei Alexandrescu wrote: >>> >>> >>> I understand how the draw of reaching for new syntax is extremely >>> alluring. I used to fall for it much more often, but

Re: Multiple return values...

2012-03-16 Thread Iain Buclaw
On 15 March 2012 17:51, Manu wrote: > On 15 March 2012 19:05, Andrei Alexandrescu > wrote: >> >> On 3/15/12 11:30 AM, Manu wrote: >>> >>> On 15 March 2012 17:32, Andrei Alexandrescu >>> mailto:seewebsiteforem...@erdani.org>> >>> >>> wrote: >>>    One note - the code is really ingenious, but I sti

Re: Multiple return values...

2012-03-16 Thread Artur Skawina
On 03/16/12 01:03, H. S. Teoh wrote: > On Fri, Mar 16, 2012 at 12:11:44AM +0100, Simen Kjærås wrote: >> On Thu, 15 Mar 2012 23:44:09 +0100, foobar wrote: >> >>> Is swap usually inlined by the compiler? >> >> This is the body of swap for simple types: >> >> auto tmp = lhs; >> lhs = rhs; >> rh

Re: Multiple return values...

2012-03-16 Thread Manu
On 16 March 2012 04:26, Andrei Alexandrescu wrote: > > A good design should strive to provide general features instead of >> special cases (E.g. swap is limited to the 2-tuple case). Also, why >> force an overhead of a function call on such a basic feature as >> assignment? Is swap usually inlined

Re: Multiple return values...

2012-03-16 Thread Andrei Alexandrescu
On 3/16/12 6:29 AM, Manu wrote: On 16 March 2012 04:26, Andrei Alexandrescu mailto:seewebsiteforem...@erdani.org>> wrote: A good design should strive to provide general features instead of special cases (E.g. swap is limited to the 2-tuple case). Also, why force an overhe

Re: Multiple return values...

2012-03-16 Thread Iain Buclaw
On 16 March 2012 16:37, Andrei Alexandrescu wrote: > On 3/16/12 6:29 AM, Manu wrote: >> >> On 16 March 2012 04:26, Andrei Alexandrescu >> mailto:seewebsiteforem...@erdani.org>> >> >> wrote: >> >>        A good design should strive to provide general features instead of >>        special cases (E.g

Re: Multiple return values...

2012-03-16 Thread Andrei Alexandrescu
On 3/16/12 3:48 AM, Iain Buclaw wrote: This could also be done for arrays too. (int a, b) = arr[]; -> static assert(arr.length == 2); int a = arr[0]; int b = arr[1]; Yah, the rewrite is purely syntactic, not tuple-specific. That's a major thing I like about it. Or possibly a use in v

Re: Multiple return values...

2012-03-16 Thread Andrei Alexandrescu
On 3/16/12 11:50 AM, Iain Buclaw wrote: If you were to forget all about MRV for a brief moment, the change request being proposed here is to return *all* structures (including delegates, complex types and vectors) in registers if at all possible even if the underlying ABI default is to return it

Re: Multiple return values...

2012-03-16 Thread Iain Buclaw
On 16 March 2012 16:53, Andrei Alexandrescu wrote: > On 3/16/12 11:50 AM, Iain Buclaw wrote: >> >> If you were to forget all about MRV for a brief moment, the change >> request being proposed here is to return *all* structures (including >> delegates, complex types and vectors) in registers if at

Re: Multiple return values...

2012-03-16 Thread Manu
On 16 March 2012 18:37, Andrei Alexandrescu wrote: > Actually, as has been mentioned, swizzling can be done very nicely inside > the language. > How? The only example I saw in this thread was your from()/to() approach, which Timon said didn't actually work...? On 3/16/12 6:29 AM, Manu wrote: >

Re: Multiple return values...

2012-03-16 Thread Manu
On 16 March 2012 18:53, Andrei Alexandrescu wrote: > On 3/16/12 11:50 AM, Iain Buclaw wrote: > >> If you were to forget all about MRV for a brief moment, the change >> request being proposed here is to return *all* structures (including >> delegates, complex types and vectors) in registers if at a

Re: Multiple return values...

2012-03-16 Thread Manu
On 16 March 2012 19:13, Iain Buclaw wrote: > On 16 March 2012 16:53, Andrei Alexandrescu > wrote: > > On 3/16/12 11:50 AM, Iain Buclaw wrote: > >> > >> If you were to forget all about MRV for a brief moment, the change > >> request being proposed here is to return *all* structures (including > >

Re: Multiple return values...

2012-03-16 Thread Timon Gehr
On 03/16/2012 06:33 PM, Manu wrote: On 16 March 2012 18:37, Andrei Alexandrescu mailto:seewebsiteforem...@erdani.org>> wrote: Actually, as has been mentioned, swizzling can be done very nicely inside the language. How? Use opDispatch. a = a.yxwz; The only example I saw in this thr

Re: Multiple return values...

2012-03-16 Thread Manu
On 16 March 2012 19:53, Timon Gehr wrote: > On 03/16/2012 06:33 PM, Manu wrote: > >> On 16 March 2012 18:37, Andrei Alexandrescu >> > > >> >> >> wrote: >> >>Actually, as has been mentioned, swizzling can be done very nicely >>inside the language. >

Re: Multiple return values...

2012-03-16 Thread Simen Kjærås
On Fri, 16 Mar 2012 03:26:55 +0100, Andrei Alexandrescu wrote: I think this is a reasonable request: (auto a, b) = fun(); ---> static assert(fun().length == 2); auto __t = fun(); auto a = __t[0]; auto b = __t[1]; That would be nice. As was mentioned in a later post, this works for stat

Re: Multiple return values...

2012-03-16 Thread bearophile
Simen K.: > Now, a pattern that our productive friend bearophile posted earlier was > this: > > int[] foo(); > > (auto a, b) = foo(); > > ---> > > auto __t = foo(); > assert( __t.length > 0 ); > auto a = __t[0]; > auto b = __t[1..$]; > > Is this something we might also want? That's not a g

Tuple unpacking syntax [Was: Re: Multiple return values...]

2012-03-13 Thread bearophile
Andrei Alexandrescu: > Let me put it another way: I don't see one syntax over another a deal > maker or deal breaker. At all. I am usually able to follow threads, but this time I am a bit lost (this discussion has mixed very different topics like ABIs, implementation efficiency of tuples and t

Re: Tuple unpacking syntax [Was: Re: Multiple return values...]

2012-03-13 Thread Michael
Maybe [x, y] = func(); ?

Re: Tuple unpacking syntax [Was: Re: Multiple return values...]

2012-03-13 Thread foobar
On Tuesday, 13 March 2012 at 22:26:14 UTC, bearophile wrote: Andrei Alexandrescu: Let me put it another way: I don't see one syntax over another a deal maker or deal breaker. At all. I am usually able to follow threads, but this time I am a bit lost (this discussion has mixed very different

Re: Tuple unpacking syntax [Was: Re: Multiple return values...]

2012-03-13 Thread Kevin Cox
Kind of unrelated but I think that it is important to have a way to ignore values also. Leaving them bank would sufice. (int i,,float f) = intBoringFloat();

Re: Tuple unpacking syntax [Was: Re: Multiple return values...]

2012-03-13 Thread Derek Parnell
On Wed, 14 Mar 2012 13:33:18 +1100, Kevin Cox wrote: Kind of unrelated but I think that it is important to have a way to ignore values also. Leaving them bank would sufice. (int i,,float f) = intBoringFloat(); For what its worth, the Euphoria Programming Language uses ? to signify ign

<    1   2   3   >