Skip Menu |
Report information
Id: 129172
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: hanenkamp <sterling [at] hanenkamp.com>
Cc:
AdminCc:

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)



To: "rakudobug [...] perl.org" <rakudobug [...] perl.org>
Subject: .trans different behavior for Str Pairs versus List Pairs
Date: Fri, 02 Sep 2016 02:59:22 +0000
From: Sterling Hanenkamp <sterling [...] hanenkamp.com>
Download (untitled) / with headers
text/plain 1009b
From #perl6 today:

21:42:01 <zostay> m: say "test.foo".trans('.' => '::');
21:42:01 <+camelia> rakudo-moar d2b115: OUTPUT«test:foo␤»
21:42:11 <zostay> m: say "test.foo".trans(['.'] => ['::']);
21:42:12 <+camelia> rakudo-moar d2b115: OUTPUT«test::foo␤»
21:42:16 <zostay> that seems like a bug

This appears to be documented as a feature in the spec tests, but is not really documented on docs.perl6.org.

Assuming my quick read of the spec is correct, I propose either of the following solutions, with the first getting my vote:

1. Change the spec and make the behavior between the two calling styles consistent so I don't have to remember this bit minutia about a subroutine I use every once in a long while.

2. Fix the documentation on docs.perl6.org AND modify the Str => Str variety of .trans so that any attempt to use multiple chars results in a warning or you risk getting this bug report again by others in the future.
--
Sterling Hanenkamp
785-370-4454
From: Elizabeth Mattijsen <liz [...] dijkmat.nl>
Date: Fri, 2 Sep 2016 07:29:11 +0200
Subject: Re: [perl #129172] .trans different behavior for Str Pairs versus List Pairs
To: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 1.5k
I would suggest 2, as the [] => [] way exists exactly for the reason that you think it’s a bug: when you want to translate a single char into zero or more chars. Show quoted text
> On 02 Sep 2016, at 04:59, hanenkamp (via RT) <perl6-bugs-followup@perl.org> wrote: > > # New Ticket Created by hanenkamp > # Please include the string: [perl #129172] > # in the subject line of all future correspondence about this issue. > # <URL: https://rt.perl.org/Ticket/Display.html?id=129172 > > > > From #perl6 today: > > 21:42:01 <zostay> m: say "test.foo".trans('.' => '::'); > 21:42:01 <+camelia> rakudo-moar d2b115: OUTPUT«test:foo␤» > 21:42:11 <zostay> m: say "test.foo".trans(['.'] => ['::']); > 21:42:12 <+camelia> rakudo-moar d2b115: OUTPUT«test::foo␤» > 21:42:16 <zostay> that seems like a bug > > This appears to be documented as a feature in the spec tests, but is not > really documented on docs.perl6.org. > > Assuming my quick read of the spec is correct, I propose either of the > following solutions, with the first getting my vote: > > 1. Change the spec and make the behavior between the two calling styles > consistent so I don't have to remember this bit minutia about a subroutine > I use every once in a long while. > > 2. Fix the documentation on docs.perl6.org AND modify the Str => Str > variety of .trans so that any attempt to use multiple chars results in a > warning or you risk getting this bug report again by others in the future. > -- > Sterling Hanenkamp > http://sterling.hanenkamp.com/stfl/ > 785-370-4454
Download (untitled) / with headers
text/plain 1.5k
Turns out there is actually a (possibly bug) difference in behavior here: (02:58:53 AM) skids: m: my $str = "abcdabcd"; $str.trans("abc" => "AB").say; $str.say; (02:58:54 AM) camelia: rakudo-moar 6977b8: OUTPUT«ABAdABAd␤abcdabcd␤» (02:59:07 AM) skids: m: my $str = "abcdabcd"; $str.trans("abc" => ("A","B")).say; $str.say; (02:59:07 AM) camelia: rakudo-moar 6977b8: OUTPUT«ABBdABBd␤abcdabcd␤» Other things I noted while looking at roast to see what was tested behavior: these tests are either not doing what they are supposed to or not saying what they are doing: is("abcde".trans( ('a..e' => 'A'..'E') ), "ABCDE", "Using string range on one side and array reference on the other"); is("&nbsp;&lt;&gt;&amp;".trans( (['&nbsp;', '&lt;', '&gt;', '&amp;'] => [' ', '<', '>', '&' ])), " <>&","The array version can map one characters to one-or-more characters"); is("&nbsp;&lt;&gt;&amp;".trans( (['&nbsp;', '&nbsp;&lt;', '&lt;', '&gt;', '&amp;'] => [' ', 'AB', '<', '>', '&' ])), "AB>&", "The array version can map one characters to one-or-more characters, using leftmost longest match"); As to the original ticket subject matter, I'm not sure warning is a good idea for two reasons: 1) it's complicated logic to figure out if the target Str contains ranges longer than needed 2) it's possibly useful behavior, say for something like: $thing.trans($/[]>>.Str, "0123456789") # when $/[].elems is unknown


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org