On Fri, Oct 14, 2005 at 08:49:50PM +0200, Peter Makholm wrote:
: 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.

Interesting comment.  I wonder if it's true.  The key shouldn't
be stringified by => unless it's an identifier, but even if => is
behaving itself, shoving it into a hash key will stringify for
a normal hash.

:             my @ks = expand($k);
:             my @vs = $v.isa(Str) ?? expand($v) !! expand_arrayref($v);

Nit: that probably wants to be an MMD dispatch eventually so we can handle
things that aren't quite Str or Array.

:             [EMAIL PROTECTED] = @vs;
:         }
:     
:         [~] map { %transtable{$_} // $_ } $self.split('');
:     }

I think the sig is abusing slurpy hashes, which are really intended
only to sop up unbound named arguments, not a list of object pairs
like this.  Filtering through an unshaped hash is going to force
string context on the keys.  So either we need to declare a shape
on the hash that allows for non-Str keys (which I'm not sure Pugs
implements yet), or we need to protect these pairs from being processed
as named parameters.

Also, if we go with the syntactic definition of named args we've
been discussing lately on p6l, we'll need to put an extra set of
parens around the pair list, or prefix with "<==" to force it into
the list zone, or pass inside [...].  (And for syntactic named args,
a => probably *should* be enforcing string context on the key.)

Larry

Reply via email to