Speaking as a non-p6-coder "proposal sounds good to me" though the
spec raises some other questions.

>The tr/// quote-like operator now also has a method form called
> trans(). Its argument is a list of pairs. You can use anything
> that produces a pair list:
>
>     $str.trans( %mapping.pairs );

Does Perl 6 guarantee the order in which pairs are returned from a
hash? If not, then the following code won't always return the same
thing:

my %mapping = 'a' => 'x', 'x' => 'b'; say 'ax'.trans(%mapping);

It might say 'bb' or 'xb', depending on how the pairs are returned.
That might be considered a programmer's error, but it seems
less-than-optimal that these two lines have the same result in my
somewhat dated Rakudo install:

> say 'ax'.trans("a" => "x", "x" => "b")
xb
> say 'ax'.trans("x" => "b", "a" => "x")
xb

- even if it is completely in accord with spec.

And since mapping is a hash, it prevents a series of transl{ations
iterations} with the same "from" in a single call.
trans('A..J'=>'0..9', 'a..z'=>'A..Z', 'A..J'=>'zyxjihcba');
- which is a contrived example that could be rewritten to avoid the
clash, but it shows the idea.

So if you're going to alter the spec, I suggest changing the method
from accepting a hash of pairs, to accepting an array of pairs.

I still really like the idea of passing 'from' => 'to' as a pair, and
think even 'subst' should accept a pair because it looks good in the
source!

Reply via email to