New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementation of Hash.reverse. #344
Comments
From @bacekHello. There is implementation of Hash.reverse -- |
From @bacekmapping_reverse.patchdiff --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
@@ -114,6 +114,24 @@ Returns elements of hash as array of C<Pair(key, value)>
.end
+=item reverse
+
+=cut
+
+.sub 'reverse' :method :multi('Hash')
+ .local pmc result, iter
+ result = new 'Perl6Hash'
+ iter = new 'Iterator', self
+ iter_loop:
+ unless iter goto iter_end
+ $S0 = shift iter
+ $S1 = self[$S0]
+ result[$S1] = $S0
+ goto iter_loop
+ iter_end:
+ .return (result)
+.end
+
=item pairs (method)
Returns elements of hash as array of C<Pairs>
|
From @moritzVasily Chekalkin (via RT) wrote:
Thanks, applied as r22430. (But put method in alphabetical order) Moritz -- |
The RT System itself - Status changed from 'new' to 'open' |
@moritz - Status changed from 'open' to 'resolved' |
From @pmichaudOn Sat, Sep 27, 2008 at 12:31:08AM -0700, Vasily Chekalkin wrote:
It feels a little weird to have 'reverse' as an exported symbol my $str = 'abc'; my %hash = { a=>1, b=>2, c=>3 }; It just seems a bit odd to me that adding an extra argument causes Pm |
From @moritzPatrick R. Michaud via RT wrote:
5abc
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 Perl 5: Maybe the solution is to avoid name conflicts in this case, maybe name Str.mirror (I've never been good with names, so there might be much better ones). Moritz -- |
Migrated from rt.perl.org#59396 (status was 'resolved')
Searchable as RT59396$
The text was updated successfully, but these errors were encountered: