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

Re: Look-ahead arguments in for loops

Thread Previous | Thread Next
From:
Matt Fowles
Date:
September 30, 2005 09:47
Subject:
Re: Look-ahead arguments in for loops
Message ID:
f2601a7f0509300947h7c4396d5x838873516144215b@mail.gmail.com
Austin~

On 9/29/05, Austin Hastings <Austin_Hastings@yahoo.com> wrote:
> Matt Fowles wrote:
>
> >Austin~
> >
> >On 9/29/05, Austin Hastings <Austin_Hastings@yahoo.com> wrote:
> >
> >
> >>Plus it's hard to talk about backwards. If you say
> >>
> >>for @l -> ?$prev, $curr, ?$next {...}
> >>
> >>what happens when you have two items in the list? I think we're best off using signature rules: optional stuff comes last.
> >>
> >>
> >
> >I disagree, I think that is an easy call
> >
> >for (1, 2) -> ?$prev, $cur, ?$next {
> >   say "$prev  -> $cur" if $prev;
> >   say $cur;
> >   say "$cur -> $next" if $next;
> >   say "next";
> >}
> >
> >should print
> >
> >1
> >1 -> 2
> >next
> >1 -> 2
> >2
> >next
> >
> >
> >
> Did you mean:
>
> next
> 1  -> 2 # two spaces
>
> there?

No, my logic is that the loop is run through twice, once with (undef,
1, 2) and once with (1, 2, undef).

Matt
--
"Computer Science is merely the post-Turing Decline of Formal Systems Theory."
-Stan Kelly-Bootle, The Devil's DP Dictionary

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