swap(x,y)
David Goodenough
dg at lakart.UUCP
Sat Sep 2 03:00:07 AEST 1989
karl at haddock.ima.isc.com (Karl Heuer) sez:
> I think if I were proposing a *language change* to solve this problem, I
> wouldn't ask for a builtin swap operator; it's too limited. Might as well
> invent something that has other applications as well, .....
Why not use the BCPL comma operator:
x, y = y, x;
I'd just suggest some other separator ('$' pops readily to mind), so you'd
have:
x $ y = y $ x;
Now, when used in an expression, what value does it return, nex x or new y??
This could (of course) be expanded to things such as:
x $ y $ z = y $ z $ x;
to do a three way rotation of variables.
Well, enough rambling from a deranged mind (just because I cut my teeth on
BCPL :-) ).
--
dg at lakart.UUCP - David Goodenough +---+
IHS | +-+-+
....... !harvard!xait!lakart!dg +-+-+ |
AKA: dg%lakart.uucp at xait.xerox.com +---+
More information about the Comp.lang.c
mailing list