There’s a very common functional programming pattern, usually called flip;
its implementation in Haskell is simply:

flip       :: (a -> b -> c) -> b -> a -> cflip f x y =  f y x

Getting the same behavior out of a bespoke function in Perl 6 would be easy
for any particular case, but writing a general version of flip that would
work universally with all binary operators would be a pain to get right
(while maintaining *exactly* the same behavior and errors as the original
in all conditions), wouldn’t it?

If so, R is syntactic sugar, but very helpful syntactic sugar.

On Tue, Sep 6, 2016 at 12:59 PM Aaron Sherman <aaronjsher...@gmail.com>
wrote:

Oh, and note that you can pass R'd reductions as if they were normal prefix
> ops:
>
> $ perl6 -e 'sub dueet(&op, *@list) { op @list }; say dueet &prefix:<[R-]>,
> 1..100'
> -4850
>
>
>
> On Tue, Sep 6, 2016 at 12:51 PM, Aaron Sherman <aaronjsher...@gmail.com>
> wrote:
>
>>
>>
>> $ perl6 -e 'my @numbers = 1..100; say [-] @numbers; say [R-] @numbers'
>> -5048
>> -4850
>>
>> In general, it's kind of pointless with bare infix ops, as you can just
>> reverse the arguments, but when reducing or the like, it becomes much more
>> valuable.
>>
>>
>>
>> On Tue, Sep 6, 2016 at 12:43 PM, Parrot Raiser <1parr...@gmail.com>
>> wrote:
>>
>>> I've just stumbled across "reversed operators", e.g. say 4 R/ 12; # 3
>>> in the documentation. I'm curious to know why the language includes
>>> them? I'm having trouble understanding where they would be useful.
>>>
>>
>>
> ​

Reply via email to