Raku / old-issue-tracker

Tickets from RT
https://github.com/Raku/old-issue-tracker/issues
2 stars 1 forks source link

Replace PIR map with a P6 version #750

Closed p6rt closed 15 years ago

p6rt commented 15 years ago

Migrated from rt.perl.org#63702 (status was 'resolved')

Searchable as RT63702$

p6rt commented 15 years ago

From @cspencer

This patch adds a Perl 6 version of map to the setting.

p6rt commented 15 years ago

From @cspencer

0001-Squashed-commit-of-the-following.patch ```diff From d3fa1181ed6dcb1b3a45bad8e560a772092881e0 Mon Sep 17 00:00:00 2001 From: Cory Spencer Date: Sat, 7 Mar 2009 19:07:17 -0800 Subject: [PATCH] Squashed commit of the following: commit cc76a676174b883e5b9025d36fdd34e9b7e13fe0 Merge: f1d4f77... ed4cd14... Author: Cory Spencer Date: Sat Mar 7 19:03:50 2009 -0800 Merge branch 'master' of git://github.com/rakudo/rakudo into any-pm Conflicts: src/setting/Any-list.pm commit f1d4f77de8c5a46ecfed86bf9060d2eb5dc9072a Author: Cory Spencer Date: Sat Mar 7 18:09:59 2009 -0800 Remove the PIR map method and replace with a Perl 6 version. commit a8824fac6d139c91352ee9f775a5e37eca4d446c Author: Cory Spencer Date: Sat Mar 7 12:55:10 2009 -0800 Removed PIR of grep and replaced with P6 version. --- src/builtins/any-list.pir | 55 --------------------------------------------- src/setting/Any-list.pm | 21 +++++++++++++++++ 2 files changed, 21 insertions(+), 55 deletions(-) diff --git a/src/builtins/any-list.pir b/src/builtins/any-list.pir index 1967fbf..d43a414 100644 --- a/src/builtins/any-list.pir +++ b/src/builtins/any-list.pir @@ -168,61 +168,6 @@ Return a List with the keys of the invocant. .return (result) .end - -=item map() - -=cut - -.namespace [] -.sub 'map' :multi('Sub') - .param pmc expression - .param pmc values :slurpy - .tailcall values.'map'(expression) -.end - -.namespace ['Any'] -.sub 'map' :method :multi(_, 'Sub') - .param pmc expression - .local pmc res, elem, block, mapres, iter, args - .local int i, arity - - arity = expression.'arity'() - if arity > 0 goto body - arity = 1 - body: - res = new 'List' - iter = self.'iterator'() - map_loop: - unless iter goto done - - # Creates arguments for closure - args = new 'ResizablePMCArray' - - i = 0 - args_loop: - if i == arity goto invoke - unless iter goto elem_undef - elem = shift iter - goto push_elem - elem_undef: - elem = new 'Failure' - push_elem: - push args, elem - inc i - goto args_loop - - invoke: - (mapres :slurpy) = expression(args :flat) - unless mapres goto map_loop - mapres.'!flatten'() - $I0 = elements res - splice res, mapres, $I0, 0 - goto map_loop - - done: - .return(res) -.end - =item min =cut diff --git a/src/setting/Any-list.pm b/src/setting/Any-list.pm index 3849a86..9492c54 100644 --- a/src/setting/Any-list.pm +++ b/src/setting/Any-list.pm @@ -4,10 +4,31 @@ class Any is also { take $_ if $test($_) for $values.list; } } + + our List of Capture multi method map(List @values: Code *&expr) { + gather { + my $i = 0; + while ($i <= @values.end) { + my @args; + @args.push(($i <= @values.end) ?? @values[$i++] !! undef) + for (1..&expr.arity || 1); + + take &expr(|@args); + } + } + } + + our List of Capture multi method map($value: Code *&expr) { + ($value,).map: &expr + } } our List multi grep(Code $test, *@values) { @values.grep($test) } +our List of Capture multi map(Code $expr, *@values) { + @values.map($expr) +} + # vim: ft=perl6 -- 1.6.1.3 ```
p6rt commented 15 years ago

From @moritz

Applied (with slightly improved commit message) as 137dcfa6c3f660eb1fb3da4dd07cd6b2fcf369dd.

Cheers, Moritz

p6rt commented 15 years ago

The RT System itself - Status changed from 'new' to 'open'

p6rt commented 15 years ago

@moritz - Status changed from 'open' to 'resolved'