I would see this benefit more in the case where the arguments were
arrays or large structures. The user could avoid the temp declaration,
and the source would look simpler.
After a couple of Fortran standard revisions that were pretty
significant (OOP in F2003 and parallelism in F2008), there is some
sentiment for changes in the next standard to be focused more on "small"
features. A simple, clean SWAP would fit into that category.
On 1/6/11 11:20 AM, Tom Clune wrote:
> I'd definitely like to see SWAP. Actually, from my point of view the
> optimization aspect would be secondary to the greater clarity afforded
> by this mechanism. Swapping is typically important in algorithms that
> are already relatively complicated, and any improved clarity in those
> cases is of great value.
> - Tom
> On Jan 6, 2011, at 11:59 AM, Loren P Meissner wrote:
>> Another operation, whose Fortran history I can’t remember, would be an
>> intrinsic function “SWAP (A, B)” that “simultaneously” assigns A to B
>> and B to A, subject to all the constraints and interpretations of
>> assignment? Wouldn’t a compiler be able to optimize in some cases, as
>> when one or both are in a register, and make it more efficient than
>> “Temp = A; A = B; B = Temp”?
>> Or spell it some other way like <=> ?
>> Or is it there already?
>> I seem to remember some language(s) that did it.
>> Loren P Meissner
>> “Truth depends on a quest to discover what’s really out there, what
>> really happened. It isn’t given over to you by simply following a set
>> of rules.” – Errol Morris
>> “Math education is not something you can dictate. The way to make a
>> tree grow is not to yank it upward by the branches. ” – Professor
>> Hung-Hsi Wu, UC Berkeley
>> -----Original Message-----
>> From: Fortran 90 List [mailto:[log in to unmask]] On
>> Behalf Of Bill Long
>> Sent: Thursday, January 06, 2011 8:52 AM
>> To:[log in to unmask] <mailto:[log in to unmask]>
>> Subject: Re: Composite assignment operators in Fortran?
>> Hi Alistair,
>> This has been requested more than once. The operator "/=" already has
>> a different meaning, but it is probably possible to work around that.
>> People seem to mostly want += and *= anyway. The past arguments
>> against the idea have been more stylistic than technical, and evolving
>> programming habits (particularly multi-part derived type references)
>> might tip the balance the next time around.
>> On 1/6/11 4:05 AM, Alistair Hart wrote:
>> > Hi,
>> > Is there a reason why C-style composite assignment operators (+=
>> etc.) are not supported in Fortran?
>> > I've certainly spent a lot of time over the years looking for bugs in
>> lines like:
>> > res_tmp(1:npoints,2,3) = res_tmp(1:npoints,2,3) +&
>> > data_y_qqg_alg_basic(1:npoints) * tmp(1:npoints)
>> > where different slices of res_tmp were (mistakenly) specified on each
>> side of the assignment. Using "+=" would also make the code more compact.
>> > Apologies if the answer is an old story - Googling for symbols is
>> > Thanks in anticipation,
>> > Alistair Hart.
>> Bill Long [log in to unmask] <mailto:[log in to unmask]>
>> Fortran Technical Support & voice: 651-605-9024
>> Bioinformatics Software Development fax: 651-605-9142
>> Cray Inc./Cray Plaza, Suite 210/380 Jackson St./St. Paul, MN 55101
> <[log in to unmask] <mailto:[log in to unmask]>>
Bill Long [log in to unmask]
Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9142
Cray Inc./Cray Plaza, Suite 210/380 Jackson St./St. Paul, MN 55101