Re: Proposed new string methods: trim-rw, trim-leading-rw, trim-trailing-rw

2015-09-09 Thread Tom Browder
Thanks, Aristotle.

-Tom


Re: Proposed new string methods: trim-rw, trim-leading-rw, trim-trailing-rw

2015-09-09 Thread Aristotle Pagaltzis
* Tom Browder  [2015-08-14 14:10]:
> On Fri, Aug 14, 2015 at 6:48 AM, Philip Hazelden
>  wrote:
> > Correct me if I'm wrong, can't you do
> >
> > $s .= trim
>
> Um, I saw that usage in an earlier thread but didn't try it because it
> didn't "look right" given my experience with the ".=" operator as I'm
> used to it. (Note I have now seen that behavior clearly documented at
> .)

Maybe because in Perl 5 that would mean what is written in Perl 6 as

$s ~= trim

which itself “looks wrong” in turn. The whole getup take some getting
used to.

But remember that . in Perl 6 is the method call operator. Then it makes
sense if you follow the logic of mutating meta-ops:

$s = $s + 1;   ==> $s += 1;
$s = $s - 1;   ==> $s -= 1;
$s = $s .trim; ==> $s .= trim;

But yeah, it still looks weird to me too. I’ve understood it rationally
but it’ll be a while before I stop second-guessing myself for a split
second every time I write it.

> Note that the same behavior applies to the 'substr' string method so
> that begs the question of why is the 'substr-rw' method justified and
> 'trim-rw' not? It seems at first glance that the 'substr-rw' method
> should be removed.

They would not be at all similar, though: substr-rw doesn’t modify the
value it’s being called on. This code does absolutely nothing:

$s.substr-rw(1, 1);

What substr-rw does is give you a reference to part of the string. *You*
can then modify that, e.g.

$s.substr-rw(1, 1) = 'x';

That’s totally different from how your proposed .trim-rw would work. For
that need, the .= mutating method call operator is the generic solution,
which obviates the endless writing of both a .trim and a .trim-rw, and
so on, for every single method. (Or .sort vs .sort! etc etc ad nauseam…)

Regards,
-- 
Aristotle Pagaltzis // 


Re: Proposed new string methods: trim-rw, trim-leading-rw, trim-trailing-rw

2015-08-14 Thread Tom Browder
On Aug 14, 2015 8:46 AM, "Brandon Allbery"  wrote:
> On Fri, Aug 14, 2015 at 8:07 AM, Tom Browder  wrote:
...
>> now).  Note that the same behavior applies to the 'substr' string
>> method so that begs the question of why is the 'substr-rw' method
>> justified and 'trim-rw' not?  It seems at first glance that the
>> 'substr-rw' method should be removed.
...
> IIRC substr-rw is a performance hack because substr was being slowed
> in all cases in order to accommodate the rw use case. trim doesn't
> have the same issue.

Thanks for the enlightenment, Brandon.

-Tom


Re: Proposed new string methods: trim-rw, trim-leading-rw, trim-trailing-rw

2015-08-14 Thread Brandon Allbery
On Fri, Aug 14, 2015 at 8:07 AM, Tom Browder  wrote:

> But I've tried it and it works (but the syntax still bothers me for
> now).  Note that the same behavior applies to the 'substr' string
> method so that begs the question of why is the 'substr-rw' method
> justified and 'trim-rw' not?  It seems at first glance that the
> 'substr-rw' method should be removed.
>

IIRC substr-rw is a performance hack because substr was being slowed in all
cases in order to accommodate the rw use case. trim doesn't have the same
issue.

-- 
brandon s allbery kf8nh   sine nomine associates
allber...@gmail.com  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net


Re: Proposed new string methods: trim-rw, trim-leading-rw, trim-trailing-rw

2015-08-14 Thread Tom Browder
On Fri, Aug 14, 2015 at 6:48 AM, Philip Hazelden
 wrote:
> Correct me if I'm wrong, can't you do
>
> $s .= trim

Um, I saw that usage in an earlier thread but didn't try it because it
didn't "look right" given my experience with the ".=" operator as I'm
used to it. (Note I have now seen that behavior clearly documented at
.)

But I've tried it and it works (but the syntax still bothers me for
now).  Note that the same behavior applies to the 'substr' string
method so that begs the question of why is the 'substr-rw' method
justified and 'trim-rw' not?  It seems at first glance that the
'substr-rw' method should be removed.

Thanks, Philip.

Best regards,

-Tom


Re: Proposed new string methods: trim-rw, trim-leading-rw, trim-trailing-rw

2015-08-14 Thread Philip Hazelden
Correct me if I'm wrong, can't you do

$s .= trim

?

On 12:45pm, Fri, 14 Aug 2015 Tom Browder  wrote:

> In an earlier thread of mine on this list seeking help, Liz mentioned
> one string method that has now been dcoumented, 'substr-rw', which
> allows in-place modification of a string variable.
>
> In my journey with Perl 6 I have enjoyed the string 'trim' method so I
> can do this:
>
>   my $s = '   blah ';
>   $s = $s.trim;
>   say $s; # 'blah'
>
> Using 'substr-rw' as precedent, I am proposing a similar set of
> methods for 'trim' so that I can do this:
>
>   my $s = '  blah ';
>   $s.trim-rw;
>   say $s; # 'blah';
>
> (and similarly for 'trim-leading-rw' and 'trim-trailing-rw').
>
> If there is no objection, I would like to add a feature request but
> where to do it?  The immediate place I thought of is the Rakudo git
> site but isn't this more of a language feature?
>
> Best regards,
>
> -Tom
>