Idea: swap with multiple arguments

Observer via Digitalmars-d digitalmars-d at puremagic.com
Wed May 25 19:17:20 PDT 2016


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

There's something about this notation that immediately makes
me think more generally.  swap is just the degenerate form
of a more-general circular-shift operation in two different
dimensions.  This form assumes that the shifting stops after only
a single shift position (or more generally, that the number of
shift positions is odd); and having just two operands makes it
unnecessary to specify whether the shifting is to the left or to
the right.  But even a circular-shift operation is itself just a
degenerate form of a more-general arbitrary-permutation operation.
Other permutations have common applicability in computer science,
such as the bit-reversed addressing used on DSP chips to support
butterfly operations in FFT (actually, DFT) algorithms.  All of
which makes me wonder:  if we want to generalize swap, should we 
go
farther than just one algorithmic stage?  How about a very general
routine that accepts a permutation mapping and a set of arguments,
and scrambles the arguments according to the mapping?



More information about the Digitalmars-d mailing list