This is exactly what I wanted .= for. @array .= splice(2,0,$element); # in-place, @array = @array.splice @new = @array.splice(2,0,$element);
$sentence .= lcfirst; The semantics are pretty clear, then it's just up to the compiler to optimize it for in-place. Perhaps functions could override the default method splice (...) { #general function for making a new string method splice (...) is inplace { #overloading to optimize for in-place but that might be going a bit too far. > I would, however, point out that other methods could > potentially have modify-in-place and a copy-and-modify > variants: > > @array.splice(2,0,$element); # in-place > @new = @array.splice(2,0,$element); # on copy > > $str.chomp; # in-place > $new = $str.chomp; # on copy > > $str.lcfirst; # in-place > $new = $str.lcfirst; # on copy > > @array.map({ %trans{$^a} }); # in-place > @new = @array.map({ %trans{$^a} }); # on copy > > So we might want to look for a more general solution. > > Unfortunately, one can't just generalize and use > void/non-void context to determine the correct behaviour, > since in-place matches and substitutions still need to > return their match object: > > $matched = $str.replace(/foo/ -> { 'bar' }); # in-place > $newstr = $str.replace(/foo/ -> { 'bar' }); # on copy > > One could perhaps change the verb to a participle: > > @array.splice(2,0,$element); # in-place > @new = @array.spliced(2,0,$element); # on copy > > $str.chomp; # in-place > $new = $str.chomped; # on copy > > $str.lcfirst; # in-place > $new = $str.lcfirsted; # on copy > > @array.map({ %trans{$^a} }); # in-place > @new = @array.mapped({ %trans{$^a} }); # on copy > > $matched = $str.replace(/foo/ -> { 'bar' }); # in-place > $newstr = $str.replaced(/foo/ -> { 'bar' }); # on copy > > but I doubt that would be well accepted. ;-) > > Or one could define a copy-the-invoke method call operator (say, C<+.>): > > @array.splice(2,0,$element); # in-place > @new = @array+.splice(2,0,$element); # on copy > > $str.chomp; # in-place > $new = $str+.chomp; # on copy > > $str.lcfirst; # in-place > $new = $str+.lcfirst; # on copy > > @array.map({ %trans{$^a} }); # in-place > @new = @array+.map({ %trans{$^a} }); # on copy > > $matched = $str.replace(/foo/ -> { 'bar' }); # in-place > $newstr = $str+.replace(/foo/ -> { 'bar' }); # on copy > > > > In typical topical string usage, that leaves us with > > > > if .subst/a/b/ {...} > > $result = .where/a/b/ > > > > That's quite livable, though the second is a bit odd, English-wise. > > We could even keep around > > > > s/a/b/ > > > > as a shorthand for .subst/a/b/. > > Oh, I definitely think so! > > > > And maybe even add > > > > w/a/b/ > > > > as a synonym for .where/a/b/. > > Hmmmmm. *s*ubstitute and *w*eplace. ;-) > > Damian > -- Adam Lopresto ([EMAIL PROTECTED]) http://cec.wustl.edu/~adam/ ....I just want a plate and a fork and a bunny...