Patrick R. Michaud via RT wrote:
> It feels a little weird to have 'reverse' as an exported symbol
> here.  Based on S29, the exports on 'reverse' mean that we get:
>     my $str = 'abc';
>     say reverse $str;              # cba
>     say reverse $str, 5;           # 2abc


>     my %hash = { a=>1, b=>2, c=>3 };
>     say reverse %hash;             # 1   a\n2   b\n3   c\n
>     say reverse %hash, 5;          # 5\na   1\nb   2\nc   3\n
>                                    # note keys and values are not reversed
> It just seems a bit odd to me that adding an extra argument causes
> the meaning of 'reverse' to change for hashes and strings.

It is weird indeed, but from my grasp of the synopsis it's correct

But IMHO it feels a bit less weird than the Perl 5 behaviour where the
context decides.

Perl 5:
say reverse "abc";        # abc\n
say scalar reverse "abc"; # cba\n

Maybe the solution is to avoid name conflicts in this case, maybe name
the methods like this:

Hash.inverse (or Hash.flip)

(I've never been good with names, so there might be much better ones).


Moritz Lenz | |

Reply via email to