--- Damian Conway <[EMAIL PROTECTED]> wrote:
> Austin Hastings asked:
> > That is, can I say 
> > 
> > for (@squares)
> > {
> >   ...
> >   if $special.instructions eq 'Advance three spaces'
> >   {
> >     $_.next.next.next;
> >   }
> >   ...
> > }
> > 
> > or some other suchlike thing that will enable me to consistently
> > perform iterator-like things within a loop, regardless of origin?
> 
> If, by C<$_.next.next.next;> you mean "skip the next three elements
> of @squares", then no. $_ isn't an alias to the implicit iterator
> over @squares; it's an alias for the element of @squares currently
> being iterated.
> 
> You want (in my formulation):
> 
>      my $dance = Iterator.new(@squares);
>      for $dance {
>         ...
>         if $special.instructions eq 'Advance three spaces' {
>            $dance.next.next.next;
>         }
>         ...
>      }

How'zat, again? What is the means for extracting the actual VALUE of
$dance? And why is that different for $_-as-iterator?

IOW:

my Iterator $dance = ...;
for <$dance> {
  print $_; # should this print the current dance, -> $_ by default?

  print $dance;
  
  # Should the above be ".value()" 
  # or ".next()"
  # or ".toString()" ?

  print <$dance>; # Obviously "get next value and advance" a la p5

}

Also, in your formulation:

>      my $dance = Iterator.new(@squares);
>      for $dance {

What happens when iterators require magic state info? It seems more
appropriate to define a CLASS.iterator method, which overloads a
simplistic default. ("fail" in scalar cases, iterative for Array and
Hash)

> > (Oh please! Let there be one, and for love of humanity, let it be
> > called "bork". Pleasepleaseplease!!! It's a shorthand form of "bind
> or
> > kontinue", really it is.  :-) :-) :-))
> 
> "Brain on raw krack" more like it ;-)

Whatever! As long as I get to say:

for my <@Swedish> -> $chef {
  $chef.bork.bork.bork;
}

Perlmuppets, anyone?

> > So in general, diamonded-function-call implies
> coroutine/continuation?
> 
> That's the problem. I can't see how that works syntactically.

I was thinking in terms of "reading", not "parsing" -- that is, "when a
coder reads diamonded-function-call, the reflex will be 'this is a
continuation'" -- valuable clues.


> > To disagree, vile Aussie! To be looking at perl5's adornmentless
> > diamond:
>  >
> > If I say: while (<>) {print;} I'm asking for file-scan behavior.
> 
> Yes. Special case.

But a special case of WHAT?

> > If I say: for (<@ARGV>) { print; } I'm asking for trouble?
> 
> <grin> Under my proposal, you're saying:
> 
>       * Grab next element of @ARGV
>       * Iterate that element.

That's the problem. Why would the second point "* Iterate that element"
happen? We've already GOT a flattener. If I want recursive iteration I
can say:

for (<*@ARGV>) { print; }

or maybe 

for (*<@ARGV>) { print; }

I can't be sure.

> *Unless* the elements of @ARGV in Perl 6 are actually special
> Iterator-ish,
> filehandle-ish objects that happen to also stringify to the
> command-line
> strings. Hmmmmm.

I thought of that one first, but discarded it.
> > Proposal:
> 
> Seemed very complex to me.

It's because I discarded the "@ARGV is magic that stringifies" option.
In other words, let @ARGV be normal, first and foremost. Then apply
magic to it. 

That way, I can argue for being able to apply the SAME magic to
something else, rather than trying to fight with having to reimplement
the @ARGV magic class.

my @file_names = ( list of strings );
my FileIterator @argv_alike := @file_names;

while (<@argv_alike>) {
 ...
}

Now the question is, how do I get it into $_/@_/whatever_, so that I
can use <> instead of <@argv_alike>? (I avoid simply slapping it into
@_ because I vaguely recall something about the inevitable demise of
@_-as-arglist etc. But that was before the weekend, when there were
more brain cells.)


> <GROAN>

Warning: File iterator used in void context. Possible loss of data.

=Austin



__________________________________________________
Do you Yahoo!?
Yahoo! Web Hosting - Let the expert host your site
http://webhosting.yahoo.com

Reply via email to