On Thu, 18 Jul 2002, darren chamberlain wrote:

> This will return (some example data, too):
> 
>   [% mylist = [ 1 2 3 4 5 6 7 8 9 0 ];
>     "'$l' " FOREACH l = mylist.first(-2) %]
>   '1' '2' '3' '4' '5' '6' '7' '8' 

No, that makes sense.  I was getting confused and thinking.  first(-2) 
would be the same as last(2), which it isn't.  Writing too many tests will 
do that ;-)



> Why would we make it work differently from Perl?

Because it's not Perl ;-)  Okay, back to work...



> list ops applied to scalars end up with the scalars being promoted to 1
> element lists,

Essentally yes.



> I'd be most inclined to not try any cleverness in the vmeths, and keep
> the implementation as close as possibly to Perl's splice behaviors.  At
> least that way, it's not a surprise to everyone, just the people who
> don't already know Perl (as opposed to other ways, which everyone would
> have to relearn.)

Okay, and that makes our lives easier.  Since there's another way to do 
it (without any suprises) let's leave that out and DWPM (Do What Perl 
Means)



> I struggled with this for a while myself, and figured that, since most
> vmeths (with the exceptions of push, pop, shift, and unshift) are
> non-destructive, it made more sense to continue with this trend.

Ah, but splice has always been a distructive inplace operation in Perl.  I 
don't follow your logic here - this isn't to say I disagree with the idea 
though.

> And in my implementation above, I'm explicitly returning a copied array:

Yes, though this is different to the implementation you proposed earlier 
in this thread where you were returning the @results.



> Since the other versions of splice are non-destructive, making this
> version an exception rubs me the wrong way.  However, it also goes
> against my earlier statement of "we should do it the way Perl does it",
> because CORE::splice modifies the list.

Well, If we implement slice seperatly from splice then we could have

 - slice used for getting at selections of bits of the list.  i.e. it
   is used in a similar way to you'd use splice when you get the
   results

 - splice used to get at a copy of the original list with the bits
   deleted/replaced.   i.e. it's like using splice in perl without
   getting the results and just looking at the original list (except
   in TT rather than modifying the existing list we copy a list and 
   then modify that one.)

Does this make sense?



> Yeah, but this is Perl; you probably shouldn't be worried about memory.
> We're creating and deleting AV's all over the place. :)

fair enough.  If it was that important you should be doing it in perl
yourself I guess.


Mark.

-- 
s''  Mark Fowler                                     London.pm   Bath.pm
     http://www.twoshortplanks.com/              [EMAIL PROTECTED]
';use Term'Cap;$t=Tgetent Term'Cap{};print$t->Tputs(cl);for$w(split/  +/
){for(0..30){$|=print$t->Tgoto(cm,$_,$y)." $w";select$k,$k,$k,.03}$y+=2}





Reply via email to