April 26, 2013
Tyro[17]:

> > While flip2 does:
> >
> > flip2!foo(a, b, c) === foo(b, a, c)
> > flip2!foo(a, b, c, d) === foo(b, a, c, d)
>
> and this rotate....

Really? Just swapping the first two arguments and leaving the others at their place is for a "rotate"?


> Why flip in the first place?

I don't know, it's the name used in the Haskell Prelude.

Bye,
bearophile
April 26, 2013
On 04/26/2013 10:15 PM, bearophile wrote:
> Tyro[17]:
>
>> > While flip2 does:
>> >
>> > flip2!foo(a, b, c) === foo(b, a, c)
>> > flip2!foo(a, b, c, d) === foo(b, a, c, d)
>>
>> and this rotate....
>
> Really? Just swapping the first two arguments and leaving the others at
> their place is for a "rotate"?
>
>
>> Why flip in the first place?
>
> I don't know, it's the name used in the Haskell Prelude.
>

And there it flips the first two arguments (of a curried function, since this is the standard for Haskell).

April 26, 2013
On 4/26/13 4:15 PM, bearophile wrote:
> Tyro[17]:
>
>> > While flip2 does:
>> >
>> > flip2!foo(a, b, c) === foo(b, a, c)
>> > flip2!foo(a, b, c, d) === foo(b, a, c, d)
>>
>> and this rotate....
>
> Really? Just swapping the first two arguments and leaving the others at
> their place is for a "rotate"?
>

Actually, by brain was thinking it but my eyes saw something completely different. You are correct, this what I would expect flip to do. Thanks.

>> Why flip in the first place?
>
> I don't know, it's the name used in the Haskell Prelude.
>
> Bye,
> bearophile

April 26, 2013
On 4/26/13 5:09 PM, Tyro[17] wrote:
> On 4/26/13 4:15 PM, bearophile wrote:
>> Tyro[17]:
>>
>>> > While flip2 does:
>>> >
>>> > flip2!foo(a, b, c) === foo(b, a, c)
>>> > flip2!foo(a, b, c, d) === foo(b, a, c, d)
>>>
>>> and this rotate....
>>
>> Really? Just swapping the first two arguments and leaving the others at
>> their place is for a "rotate"?
>>
>
> Actually, by brain was thinking it but my eyes saw something completely
> different. You are correct, this what I would expect flip to do. Thanks.
>
>>> Why flip in the first place?
>>
>> I don't know, it's the name used in the Haskell Prelude.
>>
>> Bye,
>> bearophile
>

With that clarification, I just have one more question, since flip does what is intuitively implied by a reverse function and flip2 does what is intuitively implied by a flip function, why not name them as such? Understand the Haskell influence and all but, influence notwithstanding, this is D so why not designate functions in a manner that intuitively imply functionality?

I would expect a flip and flip2 if both accomplish the exact same thing but both outperforms the other in certain scenarios thus warranting both to be present.

Andrew
April 26, 2013
Tyro[17]:

> With that clarification, I just have one more question, since flip does what is intuitively implied by a reverse function

OK, better to name it reversedArgs :-)


> and flip2 does what is intuitively implied by a flip function,

flip2 swaps just the fist two arguments and leaves the others at their place.


> I would expect a flip and flip2 if both accomplish the exact same thing but both outperforms the other in certain scenarios thus warranting both to be present.

I think that the caos of this thread shows that keeping both will cause confusion :-(


> why not name them as such? Understand the Haskell influence and all but, influence notwithstanding, this is D so why not designate functions in a manner that intuitively imply functionality?

I am starting to agree with Andrei. Short function names are handy, but in many situations the semantic confusion they can bring is not worth it. More food for thought for me.

Bye,
bearophile
1 2
Next ›   Last »