# New Ticket Created by  "Carl Mäsak" 
# Please include the string:  [perl #82108]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=82108 >


<masak> rakudo: sub y2i($adjective is copy) { s/y$/i/ given $adjective
}; sub compare($adjective) { [$_, .&y2i ~ "er", .&y2i ~
"est"].fmt("%s", ", ") given $adjective }; say compare("funny")
<p6eval> rakudo ea8c88: OUTPUT«funny, funnier, funniest␤»
<tadzik> s/y$/i/ given $adjective – nice one
<tadzik> but why not just $adjective ~~ s/y$/i/?
<masak> rakudo: sub y2i($adjective is copy) { $adjective ~~ s/y$/i/ };
sub compare($adjective) { join(", ", $adjective, $adjective.&y2i ~
"er", $adjective.&y2i ~ "est") }; say compare("funny")
<p6eval> rakudo ea8c88: OUTPUT«funny, Bool::Trueer, Bool::Trueest␤»
<masak> o.O
<jnthn> lol
* masak submits rakudobug
<jnthn> masak: Is it bug?
<masak> jnthn: I declare it a bug.
<jnthn> rakudo: my $x = "lol"; say $x ~~ s/o/0/;
<p6eval> rakudo ea8c88: OUTPUT«Bool::True␤»
<masak> based on tadzik's expectations, and the lack of spec.
<jnthn> That's...curious. :)
<tadzik> it certainly isn't DWIM
<jnthn> No
<jnthn> wtf. :/
<jnthn> rakudo: my $x = "lol"; say ($x ~~ s/o/0/).WHAT;
<p6eval> rakudo ea8c88: OUTPUT«Bool()␤»
<jnthn> Wow
<jnthn> I thought it was doing something with a match object that it
was getting back somehow
<jnthn> But...not even that.
<masak> definitely something for RT.
<jnthn> aye
<jnthn> Not sure what the spec is, but the above outcome is awfulest.
<moritz_> p5 people want to write   if $x ~~ s/foo/bar/ { ... }
<masak> I understand moritz_' explanation, but I don't like it.
<tadzik> anyways, won't Match object evaluate to true anyway?
<tadzik> and if the match fails, there will be no object, no?
<jnthn> Yes
<tadzik> jnthn: good too
<masak> tadzik: I don't want it to return the match object. I'd like
it to return the resulting Str.
<masak> tadzik: if it returned the match object in my case above, it'd
stringify to 'y'
<jnthn> masak: I'm sure you know the counter case though. $x = 'x'; if
$x ~~ s/x// { ... }
<masak> right.  [22:31]
<jnthn> It successfully substituted, but the resulting string is empty
and thus false.
<masak> I see that.
<jnthn> Maybe we just gotta choose our wart.
<masak> and an obvious patch to that would be to do 'but True' on the Str...
<masak> ...but I am reluctant to propose that.
<jnthn> I was gonna suggest that but then didn't because I worry about
it propagating, or confusion over "the return value of it is now true
but $x isn't...wtf" :)
<masak> right.
<jnthn> And because I don't really want to create a mixed-in string
for every substitution.
<jnthn> Given that but is a clone.
<masak> nodnod
<jnthn> (yes, it'd re-use the string buffer, but still...)
<masak> honestly, I could live with the Str sometimes boolifying to false.
<masak> that might even come in handy once in a while.
<jnthn> True
<masak> while s/(.)$// { ... }
<jnthn> I can imagine use cases where that's actually nice.

Reply via email to