Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[perl #59396] [PATCH] Implementation of Hash.reverse.

0 views
Skip to first unread message

Vasily Chekalkin

unread,
Sep 27, 2008, 3:31:08 AM9/27/08
to bugs-bi...@netlabs.develooper.com
# New Ticket Created by Vasily Chekalkin
# Please include the string: [perl #59396]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=59396 >


Hello.

There is implementation of Hash.reverse

--
Bacek

mapping_reverse.patch

Moritz Lenz

unread,
Sep 27, 2008, 7:56:26 AM9/27/08
to perl6-c...@perl.org
Vasily Chekalkin (via RT) wrote:
> There is implementation of Hash.reverse

Thanks, applied as r22430. (But put method in alphabetical order)

Moritz

--
Moritz Lenz
http://perlgeek.de/ | http://perl-6.de/ | http://sudokugarden.de/

Patrick R. Michaud

unread,
Sep 27, 2008, 12:17:48 PM9/27/08
to perl6-c...@perl.org

> 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

Moritz Lenz

unread,
Sep 27, 2008, 12:32:19 PM9/27/08
to perl6-bug...@perl.org, ba...@bacek.com, Patrick R. Michaud, Perl6
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

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).

0 new messages