On Sat, Mar 12, 2005 at 10:26:51PM -0600, Rod Adams wrote:
: You could easily write the above as
: 
:    say (($n1, $n2, $n3)».as('%d')).join;
: 
: What I'm not certain about is if
: 
:    say ($n1, $n2, $n3)».as('%d').join;
: 
: does the same thing, but I think it does.

Yes, hyper only modifies one operator, not all the rest of them, the
operator in this case being ".as('%d')".  On the other hand, it may
be that .as automatically iterates formats when it needs to, so maybe
the hyper mod is unnecessary.  On the gripping hand, it's then not clear
whether

    @foo.as(Bar)

is intending to convert each element to a Bar or the array as a whole.

: >And this:
: >
: > say [ $num => '%d', $str => '%s' ] >>.key.as(.value);
: >
: > 
: >
: No. .key returns a string, which you call the .as method of, which is 
: fine, but the .value is a separate expression, and references the 
: current topic, which is not tied to the array.

Probably need something with an explicit closure (or loop) to make
that work right, but I could be wrong.  As it stands now it doesn't
seem like it would become common idiom.

: Related to what I'm not sure about above is that I think you'd have to 
: say C< [...]».key».as($pattern) > to get it working correctly.

If .as() autohypers then the second hyper is not necessary.

We could go as far as to define .keys on a list of pairs.  If we did that,
then a non-pair might be assumed to match either undef or 1.  The only
problem I see with doing that is that, in a sense, the keys of an array
are the integers.  But that'd presumably be easy to get with [EMAIL PROTECTED]
That only works for a named array, though.

: >(4) use square brackets in
: >this instance (to make sure my list doesn't form a parameter list to
: >C<say>)?
: >
: Yes, but whitespace between the "say" and "(" should do the trick as 
: well. Might generate a warning, however.

I hope not.  We'll have to see how quickly people learn to internalize
the new whitespace dependencies.  It's going to be harder for some
people than others.  For some people it may be impossible.  :-)

Larry

Reply via email to