May 24, 2016
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 or not be in D...
I agree that swap isn't a good name for a rotating operator and that rotateLeft / rotateRight are long names too.
And why not swap!"1342"(a, b, c, d) giving (a, c, d, b) ?
May 24, 2016
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 though is that these ideas would probably have limited usage in the real world. I think a good rule of thumb to consider is that the standard library should be *general purpose* and mostly contain common functionality, with some exceptions of course. We should consider whether these things will actually see common usage or just add bloat to the standard library. Also consider that once it's incorporated into Phobos, the responsibility of maintaining that code falls on the community rather than those few individuals who actually desire that functionality.

I'm sure this feature has some useful application in some specific domain but I question it's value in the community at large. I personally see no value in having a swap which can rotate three or more arguments to the left, or however we may choose to incorporate this functionality. On the other hand, I use swap() with two arguments all the time; it's very common functionality that most of us has likely used at least a few times.



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
May 24, 2016
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 yet with limited applicability has worked nicely in a few instances in the past. -- Andrei

May 24, 2016
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 original discussion was about rotating a fixed and compile-time-known number of values, not a range. -- Andrei
May 24, 2016
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_mutation.html#.bringToFront
>
> This may be a misunderstanding. The original discussion was about rotating a fixed and compile-time-known number of values, not a range. -- Andrei

No misunderstanding; I realize that what you're proposing is a variadic function which takes some arbitrary set of variables/l-values passed by reference. The message was directed at those discussing rotate/roll/etc from other languages. It seemed nobody was aware this functionality was already available in Phobos though understandable since bringToFront is an unusual name for this function.
May 24, 2016
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 what printers talk (sometimes), and I assumed that it was a protocol.

It is a full-fledged programming language, and quite nice for
manipulating graphic output to raster devices.  There was even
a Display PostScript version that targeted output to screens,
though Adobe eventually dropped support for it.  The PLRM book
(PostScript Language Reference Manual) I mentioned earlier is
the definitive description of the language.  There is also a
separate book, "Mathematical Illustrations:  A Manual of Geometry
and PostScript", by Bill Casselman, that describes how to use it
to draw 3D models.

Anyway, with respect to the current discussion, PostScript has a
rich and elegant set of operators, to handle stack operations,
math operations, array operations, dictionary (hash) operations,
string operations, control operations, file operations, graphics
operations (of course), and more.  It's definitely worth a look
for inspiration both when designing language features, and for
the clarity of its documentation (the PLRM).
May 24, 2016
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 implement than rotate right..? And could include tail optimizations? If i consider a purely functional language where you have access to the left-side of the argument list but not the right side...

//Should probably heavily incorporate move as well...
//best if only bitwise-copies are necessary to swap/rotate values
void rotate(T...)(T[] arr) {
  T temp = arr[0];

  void inner(T[] vars) {
    if (arr.length > 1) {
      vars[0] = vars[1];
      inner(vars[1 .. $]);
    } else {
      vars[0] = temp;
    }
  }
  inner(arr);
}
May 25, 2016
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.

May 25, 2016
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 three arguments. Thoughts? -- Andrei

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 design?

Best regards mt.
May 25, 2016
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