[EMAIL PROTECTED] (Larry Wall) writes:

> On Fri, Oct 14, 2005 at 08:38:55AM +0200, Peter Makholm wrote:
> : Yesterday I spend some hours getting pugs to understand
> : translitterations with multiple ranges in each pair. E.g. 
> : 
> :   "foobar".trans( "a-z" => "n-za-n" );
> : 
> : By accident I tested something like:
> : 
> :   "foobar".trans( ['a' .. 'z'] => "n-za-m" );
> : 
> : and it didn't work.
> : 
> : The problem is that ['a' .. 'z'] gets stringified to 'a b c d ...'
> : which gets 'b' translated to the third letter in the right hand side.
>
> Hmm, why is stringification getting involved at all?  We're intending
> transliteration to work with multi-codepoint sequences of various
> sorts, so the canonical representation of the data structure can't
> be simple strings.
>
> Actually, it looks like the bug is probably that => is forcing stringification
> on its left argument too agressively.  It should only do that for an 
> identifier.

The code I'm lookin at is in pugs/src/perl6/Prelude.pm around line 380:

    method trans (Str $self: *%intable) is primitive is safe {
        
        my sub expand (Str $string is copy) {
            ...
        }

        my sub expand_arrayref ( $arr is copy ) {
            ...
        }

        my %transtable;
        for %intable.kv -> $k, $v {
            # $k is stringified by the => operator.
            my @ks = expand($k);
            my @vs = $v.isa(Str) ?? expand($v) !! expand_arrayref($v);
            [EMAIL PROTECTED] = @vs;
        }
    
        [~] map { %transtable{$_} // $_ } $self.split('');
    }

> One other quibble is that we're switching ranges in character classes to
> use ".." instead of "-", so trans should use the same convention.

Ok.

> : Is this supposed to work and if so how should the code differ between 
> : 
> :   "foobar".trans( ['a' .. 'b'] => '12'); # a=>1, b=>2
> :   "foobar".trans( "a b" => "123" ) # a=>1, ' '=>2, b=>3
>
> Actually, the [...] is somewhat gratuitous.  Should work with parens too.
> In fact, it should work with a bare range object on the left:
>
>   "foobar".trans( 'a' .. 'b' => '12'); # a=>1, b=>2

Works too.


> Thanks for working on this!  Do you know any more people like you?  :-)

No, after seeing what happend to Lintilla I've kept clear from cloning
companies.

-- 
 Peter Makholm     |                                              What if:
 [EMAIL PROTECTED] |     IBM bought Xenix from Microsoft instead of buying
 http://hacking.dk |                                                  DOS?

Reply via email to