Both Luke and I missed the fact that my mail and his response went only to each other so, with his permission, here it is as a forward.

--Dks


Begin forwarded message:

From: Luke Palmer <[EMAIL PROTECTED]>
Date: October 5, 2005 1:48:54 AM EDT
To: David Storrs <[EMAIL PROTECTED]>
Subject: Re: zip: stop when and where?
Reply-To: Luke Palmer <[EMAIL PROTECTED]>


On 10/4/05, David Storrs <[EMAIL PROTECTED]> wrote:

How about:

@foo = ('a', 'b', 'c');

for @foo ¥ 1..6 :fillin(undef) # a 1 b 2 c 3 undef 4 undef 5 undef 6
for @foo ¥ 1..6 :fillin('')       # a 1 b 2 c 3 '' 4 '' 5 '' 6
for @foo ¥ 1..6 :fillin(0)        # a 1 b 2 c 3 0 4 0 5 0 6
for @foo ¥ 1..6 :fillin(return)   # same as:  return ('a', 1, 'b', 2
'c', 3);

A couple of things bother me about this, though:

- Bad endweight on the adverb.  It looks like you are modifying the
second list, not the ¥ op


That's because you are.  I can't seem to find the document that
describes this, but as far as I recall (and my memory may be fuzzy
here), infix operators with adverbs look roughly like this:

   rule infixop { <term> <op> <term> <adverb>? }

Where <adverb> is, of course, greedy.  So since .. is tighter than Y:

    for @foo Y 1..6 :fillin(undef) {...}

Is equivalent to:

    for @foo Y (1..6 :fillin(undef)) {...}

And to get it modifying Y you need to do:

    for (@foo) Y (1..6) :fillin(undef) {...}

(Parens added around @foo for symmetry).


for @foo ¥ 1..6 :fillin(last)     # a 1 b 2 c 3


Uh, I don't think that works.  First off, it would have to be:

    for (@foo) Y (1..6) :fillin{ last } {...}

But I don't think that works either, since you want that last to be
associated with the for loop, which it is not lexically inside.
Honestly, I just don't think it's an option, and that :short/:long (or
:min/:max) is a better option.  However, I wonder how you would get
behavior like this:

    for (@foo) Y (@bar, undef xx Inf) Y (1...) :short -> $foo, $bar,
$index {...}

Hmm, probably just like that :-)


Could something like this syntax be made to work?

for (@foo ¥:fillin(undef) 1..6) but true      # a but true, 1 but
true...undef but true, 6 but true


I think you've stumbled upon the reason why we made adverbs come after
operators.  The important thing is the zip, not the fact that you're
filling in with undef.

Luke


Reply via email to