# New Ticket Created by fREW Schmidt # Please include the string: [perl #63784] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=63784 >
Hopefully this does the trick :-) -- fREW Schmidt http://blog.afoolishmanifesto.com
>From 74a32c28a969b1ce497a3a50bdbf8bf5f8858658 Mon Sep 17 00:00:00 2001 From: Arthur Axel "fREW" Schmidt <[email protected]> Date: Mon, 9 Mar 2009 20:53:51 -0500 Subject: [PATCH] pop method in perl6 --- src/classes/Array.pir | 21 +-------------------- src/setting/Array.pm | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/classes/Array.pir b/src/classes/Array.pir index 872f4b6..56b094b 100644 --- a/src/classes/Array.pir +++ b/src/classes/Array.pir @@ -14,7 +14,7 @@ src/classes/Array.pir - Perl 6 Array class and related functions arrayproto.'!MUTABLE'() $P0 = get_hll_namespace ['Perl6Array'] - '!EXPORT'('delete,exists,pop,push,shift,unshift', 'from'=>$P0) + '!EXPORT'('delete,exists,push,shift,unshift', 'from'=>$P0) .end =head2 Methods @@ -104,25 +104,6 @@ Return invocant as a List. .tailcall self.'values'() .end - -=item pop() - -Remove the last item from the array and return it. - -=cut - -.sub 'pop' :method :multi(Perl6Array) - .local pmc x - unless self goto empty - x = pop self - goto done - empty: - x = '!FAIL'('Undefined value popped from empty array') - done: - .return (x) -.end - - =item push(args :slurpy) Add C<args> to the end of the Array. diff --git a/src/setting/Array.pm b/src/setting/Array.pm index c37799b..8f7094b 100644 --- a/src/setting/Array.pm +++ b/src/setting/Array.pm @@ -13,6 +13,21 @@ class Array is also { @array = @spliced; return @deleted; } + +=begin item pop() + +Remove the last item from the array and return it. + +=end item + + multi method pop ( @array is rw: ) is export { + # maybe a .empty method should be defined... + fail if @array == (); + my $last = @array[*-1]; + @array = @array[0..*-2]; + return $last; + } + } # vim: ft=perl6 -- 1.5.6.3
