Hello.
There is implementation of Hash.reverse
--
Bacek
Thanks, applied as r22430. (But put method in alphabetical order)
Moritz
--
Moritz Lenz
http://perlgeek.de/ | http://perl-6.de/ | http://sudokugarden.de/
> diff --git a/languages/perl6/src/classes/Mapping.pir b/languages/perl6/src/classes/Mapping.pir
> index ec9824f..7b9aace 100644
> --- a/languages/perl6/src/classes/Mapping.pir
> +++ b/languages/perl6/src/classes/Mapping.pir
> @@ -18,7 +18,7 @@ src/classes/Mapping.pir - Perl 6 hash class and related functions
> mappingproto = p6meta.'new_class'('Mapping', 'parent'=>'Hash Any')
> p6meta.'register'('Hash', 'parent'=>mappingproto, 'protoobject'=>mappingproto)
> $P0 = get_hll_namespace ['Mapping']
> - '!EXPORT'('keys kv values', $P0)
> + '!EXPORT'('keys kv values reverse', $P0)
> .end
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.
Pm
5abc
> 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
nonetheless.
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:
Str.mirror
List.reverse
Hash.inverse (or Hash.flip)
(I've never been good with names, so there might be much better ones).