Re: Idea: swap with multiple arguments

2016-05-26 Thread Seb via Digitalmars-d
On Thursday, 26 May 2016 at 02:17:20 UTC, Observer wrote: On Wednesday, 25 May 2016 at 17:08:02 UTC, Martin Tschierschke wrote: A newbee question about language design: When I looked first time at Ruby I liked the simple a,b = b,a syntax, so swap. Would it be theoretically possible to allow th

Re: Idea: swap with multiple arguments

2016-05-25 Thread Observer via Digitalmars-d
On Wednesday, 25 May 2016 at 17:08:02 UTC, Martin Tschierschke wrote: A newbee question about language design: When I looked first time at Ruby I liked the simple a,b = b,a syntax, so swap. Would it be theoretically possible to allow this? And if not, where does it breaks the general language

Re: Idea: swap with multiple arguments

2016-05-25 Thread Andrei Alexandrescu via Digitalmars-d
On 05/25/2016 01:08 PM, Martin Tschierschke wrote: On Monday, 23 May 2016 at 20:01:08 UTC, Andrei Alexandrescu wrote: So swap(a, b) swaps the contents of a and b. This could be easily generalized to multiple arguments such that swap(a1, a2, ..., an) arranges things such that a1 gets an, a2 gets

Re: Idea: swap with multiple arguments

2016-05-25 Thread Brian Schott via Digitalmars-d
On Wednesday, 25 May 2016 at 17:08:02 UTC, Martin Tschierschke wrote: And if not, where does it breaks the general language design? Here: https://en.wikipedia.org/wiki/Comma_operator

Re: Idea: swap with multiple arguments

2016-05-25 Thread Martin Tschierschke via Digitalmars-d
On Monday, 23 May 2016 at 20:01:08 UTC, Andrei Alexandrescu wrote: So swap(a, b) swaps the contents of a and b. This could be easily generalized to multiple arguments such that swap(a1, a2, ..., an) arranges things such that a1 gets an, a2 gets a1, a3 gets a2, etc. I do know applications for th

Re: Idea: swap with multiple arguments

2016-05-25 Thread Nordlöw via Digitalmars-d
On Monday, 23 May 2016 at 21:47:31 UTC, Ali Çehreli wrote: Yes, rotate(), but then I would never remember what direction it rotates. Ali I agree. So we need rotate{Forward,Backward} or rotate{Left,Right} then. I vote for the former case.

Re: Idea: swap with multiple arguments

2016-05-24 Thread Era Scarecrow via Digitalmars-d
On Tuesday, 24 May 2016 at 12:22:01 UTC, H. S. Teoh wrote: And why would you assume that it would rotate right? The default assumption, unless stated clearly and widely followed everywhere, is unclear and leads to misunderstandings. hmmm rotate left would be a lot easier (and cleaner) to imp

Re: Idea: swap with multiple arguments

2016-05-24 Thread Observer via Digitalmars-d
On Tuesday, 24 May 2016 at 08:56:31 UTC, Jonathan M Davis wrote: On Tuesday, May 24, 2016 02:40:24 Observer via Digitalmars-d wrote: If you don't see value in it, you've neglected to learn PostScript. I wasn't aware that postscript was a programming language. All I know about it is that it's

Re: Idea: swap with multiple arguments

2016-05-24 Thread Xinok via Digitalmars-d
On Tuesday, 24 May 2016 at 18:51:32 UTC, Andrei Alexandrescu wrote: On 05/24/2016 02:48 PM, Xinok wrote: BTW, Phobos already has a function called bringToFront which can rotate/roll ranges but the interface is a bit different compared to other languages. https://dlang.org/phobos/std_algorithm

Re: Idea: swap with multiple arguments

2016-05-24 Thread Andrei Alexandrescu via Digitalmars-d
On 05/24/2016 02:48 PM, Xinok wrote: BTW, Phobos already has a function called bringToFront which can rotate/roll ranges but the interface is a bit different compared to other languages. https://dlang.org/phobos/std_algorithm_mutation.html#.bringToFront This may be a misunderstanding. The orig

Re: Idea: swap with multiple arguments

2016-05-24 Thread Andrei Alexandrescu via Digitalmars-d
On 05/24/2016 02:48 PM, Xinok wrote: One point I've never seen mentioned though is that these ideas would probably have limited usage in the real world. I agree. I'd be hard pressed to find a use for swap/rotate with more than three arguments. It's just that generalization that seems natural

Re: Idea: swap with multiple arguments

2016-05-24 Thread Xinok via Digitalmars-d
On Monday, 23 May 2016 at 20:01:08 UTC, Andrei Alexandrescu wrote: ... I wish to make a different point which is more general regarding ideas like these. I see a lot of proposals to add this or that to the standard library and a lot of debate pursues. One point I've never seen mentioned thou

Re: Idea: swap with multiple arguments

2016-05-24 Thread NynnFR via Digitalmars-d
On Tuesday, 24 May 2016 at 14:49:20 UTC, Wyatt wrote: In the APL family, we have dyadic ⌽ and ⊖: 3⌽⍳9 ⍝ left 4 5 6 7 8 9 1 2 3 ¯3⌽⍳9 ⍝ right 7 8 9 1 2 3 4 5 6 [...] -Wyatt Wow: I didn't see any APL code for years ! ;) That's fine but maybe not a very good example of what should be

Re: Idea: swap with multiple arguments

2016-05-24 Thread Wyatt via Digitalmars-d
On Tuesday, 24 May 2016 at 12:22:01 UTC, H. S. Teoh wrote: And why would you assume that it would rotate right? The default assumption, unless stated clearly and widely followed everywhere, is unclear and leads to misunderstandings. I'd rather unambiguously name them rotateRight and rotateLef

Re: Idea: swap with multiple arguments

2016-05-24 Thread H. S. Teoh via Digitalmars-d
On Tue, May 24, 2016 at 09:21:07AM +, ixid via Digitalmars-d wrote: > On Tuesday, 24 May 2016 at 01:18:05 UTC, Jonathan M Davis wrote: > > Hmmm. And I would have assumed that it rotated in the other > > direction. This is really going to need a very specific name like > > rotateLeft or rotateR

Re: Idea: swap with multiple arguments

2016-05-24 Thread Adrian Matoga via Digitalmars-d
On Tuesday, 24 May 2016 at 02:40:24 UTC, Observer wrote: As for utility, if you're a PostScript programmer, where keeping track of data is done via a stack-oriented model, this capability gets used all the time, to bring relevant arguments to the top of the stack to be operated upon, or to shov

Re: Idea: swap with multiple arguments

2016-05-24 Thread Piotr Szturmaj via Digitalmars-d
On 2016-05-24 02:16, H. S. Teoh via Digitalmars-d wrote: On Mon, May 23, 2016 at 04:01:08PM -0400, Andrei Alexandrescu via Digitalmars-d wrote: So swap(a, b) swaps the contents of a and b. This could be easily generalized to multiple arguments such that swap(a1, a2, ..., an) arranges things suc

Re: Idea: swap with multiple arguments

2016-05-24 Thread ixid via Digitalmars-d
On Tuesday, 24 May 2016 at 01:18:05 UTC, Jonathan M Davis wrote: Hmmm. And I would have assumed that it rotated in the other direction. This is really going to need a very specific name like rotateLeft or rotateRight in order for it not to be error-prone. - Jonathan M Davis Why would you as

Re: Idea: swap with multiple arguments

2016-05-24 Thread Jonathan M Davis via Digitalmars-d
On Tuesday, May 24, 2016 02:40:24 Observer via Digitalmars-d wrote: > If you don't see value in it, you've neglected to learn > PostScript. I wasn't aware that postscript was a programming language. All I know about it is that it's what printers talk (sometimes), and I assumed that it was a protoc

Re: Idea: swap with multiple arguments

2016-05-23 Thread Observer via Digitalmars-d
On Monday, 23 May 2016 at 21:38:54 UTC, Jonathan M Davis wrote: One thing that screams out to me: this should be called rotate, not swap. That would probably be better. My immediate thought on reading Andrei's suggestion for swap was that it would be way too easy to forget what's actually bei

Re: Idea: swap with multiple arguments

2016-05-23 Thread Jonathan M Davis via Digitalmars-d
On Monday, May 23, 2016 18:10:02 Steven Schveighoffer via Digitalmars-d wrote: > On 5/23/16 5:47 PM, Ali Çehreli wrote: > > On 05/23/2016 01:27 PM, Steven Schveighoffer wrote: > >> On 5/23/16 4:01 PM, Andrei Alexandrescu wrote: > >>> So swap(a, b) swaps the contents of a and b. This could be easily

Re: Idea: swap with multiple arguments

2016-05-23 Thread H. S. Teoh via Digitalmars-d
On Mon, May 23, 2016 at 04:01:08PM -0400, Andrei Alexandrescu via Digitalmars-d wrote: > So swap(a, b) swaps the contents of a and b. This could be easily > generalized to multiple arguments such that swap(a1, a2, ..., an) > arranges things such that a1 gets an, a2 gets a1, a3 gets a2, etc. I > do

Re: Idea: swap with multiple arguments

2016-05-23 Thread Steven Schveighoffer via Digitalmars-d
On 5/23/16 6:22 PM, Andrei Alexandrescu wrote: On 05/23/2016 04:27 PM, Steven Schveighoffer wrote: On 5/23/16 4:01 PM, Andrei Alexandrescu wrote: So swap(a, b) swaps the contents of a and b. This could be easily generalized to multiple arguments such that swap(a1, a2, ..., an) arranges things s

Re: Idea: swap with multiple arguments

2016-05-23 Thread Era Scarecrow via Digitalmars-d
On Monday, 23 May 2016 at 21:47:31 UTC, Ali Çehreli wrote: Yes, rotate(), but then I would never remember what direction it rotates. If we take a cue from assembly instructions, there's rol and ror (rotate left/right). These are other instructions are normally unreachable in languages; Altho

Re: Idea: swap with multiple arguments

2016-05-23 Thread Andrei Alexandrescu via Digitalmars-d
On 05/23/2016 04:27 PM, Steven Schveighoffer wrote: On 5/23/16 4:01 PM, Andrei Alexandrescu wrote: So swap(a, b) swaps the contents of a and b. This could be easily generalized to multiple arguments such that swap(a1, a2, ..., an) arranges things such that a1 gets an, a2 gets a1, a3 gets a2, etc

Re: Idea: swap with multiple arguments

2016-05-23 Thread Steven Schveighoffer via Digitalmars-d
On 5/23/16 5:47 PM, Ali Çehreli wrote: On 05/23/2016 01:27 PM, Steven Schveighoffer wrote: On 5/23/16 4:01 PM, Andrei Alexandrescu wrote: So swap(a, b) swaps the contents of a and b. This could be easily generalized to multiple arguments such that swap(a1, a2, ..., an) arranges things such that

Re: Idea: swap with multiple arguments

2016-05-23 Thread Xinok via Digitalmars-d
On Monday, 23 May 2016 at 20:01:08 UTC, Andrei Alexandrescu wrote: So swap(a, b) swaps the contents of a and b. This could be easily generalized to multiple arguments such that swap(a1, a2, ..., an) arranges things such that a1 gets an, a2 gets a1, a3 gets a2, etc. I do know applications for th

Re: Idea: swap with multiple arguments

2016-05-23 Thread Ali Çehreli via Digitalmars-d
On 05/23/2016 01:27 PM, Steven Schveighoffer wrote: On 5/23/16 4:01 PM, Andrei Alexandrescu wrote: So swap(a, b) swaps the contents of a and b. This could be easily generalized to multiple arguments such that swap(a1, a2, ..., an) arranges things such that a1 gets an, a2 gets a1, a3 gets a2, etc

Re: Idea: swap with multiple arguments

2016-05-23 Thread Jonathan M Davis via Digitalmars-d
On Monday, May 23, 2016 16:27:43 Steven Schveighoffer via Digitalmars-d wrote: > On 5/23/16 4:01 PM, Andrei Alexandrescu wrote: > > So swap(a, b) swaps the contents of a and b. This could be easily > > generalized to multiple arguments such that swap(a1, a2, ..., an) > > arranges things such that a

Re: Idea: swap with multiple arguments

2016-05-23 Thread Q. Schroll via Digitalmars-d
On Monday, 23 May 2016 at 20:27:43 UTC, Steven Schveighoffer wrote: On 5/23/16 4:01 PM, Andrei Alexandrescu wrote: So swap(a, b) swaps the contents of a and b. This could be easily generalized to multiple arguments such that swap(a1, a2, ..., an) arranges things such that a1 gets an, a2 gets a1

Re: Idea: swap with multiple arguments

2016-05-23 Thread Tourist via Digitalmars-d
On Monday, 23 May 2016 at 20:27:43 UTC, Steven Schveighoffer wrote: On 5/23/16 4:01 PM, Andrei Alexandrescu wrote: So swap(a, b) swaps the contents of a and b. This could be easily generalized to multiple arguments such that swap(a1, a2, ..., an) arranges things such that a1 gets an, a2 gets a1

Re: Idea: swap with multiple arguments

2016-05-23 Thread Steven Schveighoffer via Digitalmars-d
On 5/23/16 4:01 PM, Andrei Alexandrescu wrote: So swap(a, b) swaps the contents of a and b. This could be easily generalized to multiple arguments such that swap(a1, a2, ..., an) arranges things such that a1 gets an, a2 gets a1, a3 gets a2, etc. I do know applications for three arguments. Thought

Idea: swap with multiple arguments

2016-05-23 Thread Andrei Alexandrescu via Digitalmars-d
So swap(a, b) swaps the contents of a and b. This could be easily generalized to multiple arguments such that swap(a1, a2, ..., an) arranges things such that a1 gets an, a2 gets a1, a3 gets a2, etc. I do know applications for three arguments. Thoughts? -- Andrei