Open p6rt opened 8 years ago
From #perl6 today:
21:42:01 \
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
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.
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-archive.perl.org/perl6/Ticket/Display.html?id=129172 >
From #perl6 today:
21:42:01 \
m: say "test.foo".trans('.' => '::'); 21:42:01 \<+camelia> rakudo-moar d2b115: OUTPUT«test:foo» 21:42:11 \ m: say "test.foo".trans(['.'] => ['::']); 21:42:12 \<+camelia> rakudo-moar d2b115: OUTPUT«test::foo» 21:42:16 \ 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
The RT System itself - Status changed from 'new' to 'open'
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«ABAdABAdabcdabcd» (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«ABBdABBdabcdabcd»
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(" <>&".trans( ([' ', '<', '>', '&'] => [' ', '\<', '>', '&' ])), " \<>&","The array version can map one characters to one-or-more characters");
is(" <>&".trans( ([' ', ' <', '<', '>', '&'] => [' ', '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
Migrated from rt.perl.org#129172 (status was 'open')
Searchable as RT129172$