develooper Front page | perl.perl6.language | Postings from September 2005

Re: skippable arguments in for loops

Thread Previous | Thread Next
From:
TSa
Date:
September 22, 2005 05:07
Subject:
Re: skippable arguments in for loops
Message ID:
43329E72.4050104@orthogon.com
HaloO,

Carl Mäsak wrote:
> But what if I don't care about the elements 1,4,7? Would the following
> be a sane syntax?
> 
> my @a = 1..9;
> for @a -> undef, $x, $y { say $x }

I think that, if the concept of lazy list evaluation is running
deep in Perl 6 than the obvious solution to me is:

   for @a -> $x, $y, $z { say $y }

and $x and $z are never evaluated. Other ways that come to my mind
are:

   for @a ->  $,$y,$ { say $y }
   for @a ->  (,$y,) { say $y }
   for @a ->   ,$y,  { say $y }  # same? unparseable?

All the above depend on really lazy lists that somehow hook onto
what they are susposed to contain in a very lightweight, shallow
fashion. And it must be possible to iterate lists in several
modes. Here this would be (:skip,:fetch,:skip) or whatever the
syntax could be.

Or in a non-native-attempt-to-sound-funny-with-deep-philosophical-meaning
way I would say: "If Carl doesn't want to care about the first and last
item of the three element list, he should do so! And Perl6 cares for his
carelessness not beeing punished with a performance penalty." :)

Here's a lengthy version that also comes to my mind:

   for @a -> @three is shape(Void,Item,Void)  { say @three[1] }

if this is not how the shape trait works s/shape/tuple/.
Actually, it could as well just be @three:(Void,Item,Void).
Hmm, or with typing the topic:

   for @a -> $_:(Void,Item,Void) { say }
-- 
$TSa.greeting := "HaloO"; # mind the echo!


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About