Ideas from the Chapel language (swap)

renoX renosky at free.fr
Thu Oct 4 10:19:39 PDT 2007


Derek Parnell a écrit :
> On Thu, 04 Oct 2007 17:55:05 +0900, Bill Baxter wrote:
> 
>> I find it hard to believe that a compiler couldn't recognize that this 
>> is a swap operation:
>>     tmp = a;
>>     a = b;
>>     b = tmp;
>>
>> If it's not harder than I think for some reason, then it's not really 
>> needed in the language.
> 
> Maybe it could, but that's not the point of a programming language. A
> programming language is for people, not computers, to read. It is whole lot
> easy to recognise "swap(a,b)" or even "a<->b" as a swapping operation than
> three lines of code.

Uh? If 'swap(a,b)' is ok, then you put swap as a function call, that the 
compiler inline, or as a macro if you want to be sure that it will be 
inlined.

As for an operator, given that I don't remember the last time that I 
needed to swap variables, I would vote against it.

renoX





More information about the Digitalmars-d mailing list