Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!ames!sun-barr!decwrl!decvax!ima!cfisun!lakart!dg From: dg@lakart.UUCP (David Goodenough) Newsgroups: comp.lang.c Subject: Re: swap(x,y) Message-ID: <678@lakart.UUCP> Date: 1 Sep 89 17:00:07 GMT References: <14479@haddock.ima.isc.com> Organization: Lakart Corporation, Newton, MA Lines: 29 karl@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@lakart.UUCP - David Goodenough +---+ IHS | +-+-+ ....... !harvard!xait!lakart!dg +-+-+ | AKA: dg%lakart.uucp@xait.xerox.com +---+