Re: Look-ahead arguments in for loops

2005-10-03 Thread Austin Hastings
Miroslav Silovic wrote: > [EMAIL PROTECTED] wrote: > >> And that was never quite resolved. The biggest itch was with >> operators that have no identity, and operators whose codomain is not >> the same as the domain (like <, which takes numbers but returns >> bools). >> >> Anyway, that syntax was

Re: Look-ahead arguments in for loops

2005-10-03 Thread Miroslav Silovic
[EMAIL PROTECTED] wrote: And that was never quite resolved. The biggest itch was with operators that have no identity, and operators whose codomain is not the same as the domain (like <, which takes numbers but returns bools). Anyway, that syntax was $sum = [+] @items; And the more genera

Re: Look-ahead arguments in for loops

2005-10-01 Thread John Macdonald
On Sat, Oct 01, 2005 at 02:22:01PM -0600, Luke Palmer wrote: > And the more general form was: > > $sum = reduce { $^a + $^b } @items; > > Yes, it is called reduce, because "foldl" is a miserable name. So, the target of running a loop with both the current and previous elements accessible cou

Re: Look-ahead arguments in for loops

2005-10-01 Thread Damian Conway
Austin Hastings wrote: 1. Requirement to repeat the possibly complex expression for the list. 2. Possible high cost of generating the list. 3. Possible unique nature of the list. The subroutine addresses #1, but not 2 or 3. It does address 2. The list is generated once (wherever) and only pa

Re: Look-ahead arguments in for loops

2005-10-01 Thread Austin Hastings
Damian Conway wrote: > Austin Hastings wrote: > >> All of these have the same solution: >> >> @list = ... >> for [undef, @list[0...]] ¥ @list ¥ [EMAIL PROTECTED], undef] -> $last, $curr, >> $next { >> ... >> } >> >> Which is all but illegible. > > > Oh, no! You mean I might have to write a...sub

Re: Look-ahead arguments in for loops

2005-10-01 Thread Luke Palmer
On 10/1/05, John Macdonald <[EMAIL PROTECTED]> wrote: > I forget what the final choice was for syntax for the reduce > operator (it was probably even a different name from reduce - > that's the APL name), but it would be given a list and an > operator and run as: > > my $running = op.identity;

Re: Look-ahead arguments in for loops

2005-10-01 Thread John Macdonald
On Fri, Sep 30, 2005 at 08:39:58PM -0600, Luke Palmer wrote: > Incidentally, the undef problem just vanishes here (being replaced by > another problem). Which reminds me that this same issue came up a while ago in a different guise. There was a long discussion about the reduce functionality that

RE: Look-ahead arguments in for loops

2005-10-01 Thread Joe Gottman
> -Original Message- > From: Damian Conway [mailto:[EMAIL PROTECTED] > Sent: Saturday, October 01, 2005 8:53 AM > To: perl6-language@perl.org > Subject: Re: Look-ahead arguments in for loops > > Austin Hastings wrote: > > > All of these have th

Re: Look-ahead arguments in for loops

2005-10-01 Thread Damian Conway
Austin Hastings wrote: All of these have the same solution: @list = ... for [undef, @list[0...]] ¥ @list ¥ [EMAIL PROTECTED], undef] -> $last, $curr, $next { ... } Which is all but illegible. Oh, no! You mean I might have to write a...subroutine!?? sub contextual (@list) { ret

Re: Look-ahead arguments in for loops

2005-10-01 Thread Austin Hastings
Damian Conway wrote: > Rather than addition Yet Another Feature, what's wrong with just using: > > for @list ¥ @list[1...] -> $curr, $next { > ... > } > > ??? 1. Requirement to repeat the possibly complex expression for the list. 2. Possible high cost of generating the list. 3. Po

Re: Look-ahead arguments in for loops

2005-09-30 Thread Dave Whipp
Damian Conway wrote: Rather than addition Yet Another Feature, what's wrong with just using: for @list ¥ @list[1...] -> $curr, $next { ... } ??? There's nothing particularly wrong with it -- just as ther's nothing particularly wrong with any number of other "we don't need thi

Re: Look-ahead arguments in for loops

2005-09-30 Thread Mark A. Biggar
Mark A. Biggar wrote: Damian Conway wrote: Rather than addition Yet Another Feature, what's wrong with just using: for @list ¥ @list[1...] -> $curr, $next { ... } ??? Damian Shouldn't that be: for [EMAIL PROTECTED], undef] ¥ @list[1...] -> $curr, $next { ... } As

Re: Look-ahead arguments in for loops

2005-09-30 Thread Mark A. Biggar
Damian Conway wrote: Rather than addition Yet Another Feature, what's wrong with just using: for @list ¥ @list[1...] -> $curr, $next { ... } ??? Damian Shouldn't that be: for [EMAIL PROTECTED], undef] ¥ @list[1...] -> $curr, $next { ... } As I remember it zip hrows

Re: Look-ahead arguments in for loops

2005-09-30 Thread Luke Palmer
On 9/30/05, Damian Conway <[EMAIL PROTECTED]> wrote: > Rather than addition Yet Another Feature, what's wrong with just using: > > for @list ¥ @list[1...] -> $curr, $next { > ... > } > > ??? Thanks. I missed that one. However, I think your point is pretty much the sam

Re: Look-ahead arguments in for loops

2005-09-30 Thread Damian Conway
Rather than addition Yet Another Feature, what's wrong with just using: for @list ¥ @list[1...] -> $curr, $next { ... } ??? Damian

Re: Look-ahead arguments in for loops

2005-09-30 Thread Matt Fowles
Austin~ On 9/29/05, Austin Hastings <[EMAIL PROTECTED]> wrote: > Matt Fowles wrote: > > >Austin~ > > > >On 9/29/05, Austin Hastings <[EMAIL PROTECTED]> wrote: > > > > > >>Plus it's hard to talk about backwards. If you say > >> > >>for @l -> ?$prev, $curr, ?$next {...} > >> > >>what happens when yo

Re: Look-ahead arguments in for loops

2005-09-29 Thread Austin Hastings
Matt Fowles wrote: >Austin~ > >On 9/29/05, Austin Hastings <[EMAIL PROTECTED]> 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: option

Re: Look-ahead arguments in for loops

2005-09-29 Thread Luke Palmer
On 9/29/05, Austin Hastings <[EMAIL PROTECTED]> wrote: > Luke Palmer wrote: > >>This is an interesting idea. Perhaps "for" (and "map") shift the > >>minimum arity of the block from the given list and bind the maximum > >>arity. Of course, the minimum arity has to be >= 1 lest an infinite > >>loop

Re: Look-ahead arguments in for loops

2005-09-29 Thread Matt Fowles
Austin~ On 9/29/05, Austin Hastings <[EMAIL PROTECTED]> 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 disagre

Re: Look-ahead arguments in for loops

2005-09-29 Thread Austin Hastings
Luke Palmer wrote: >>On 9/29/05, Dave Whipp <[EMAIL PROTECTED]> wrote: > > for grep {defined} @in -> $item, ?$next { print $item unless defined $next && $item eq $next; } >> >> > >>This is an interesting idea. Perhaps "for" (and "map") shift the >>minimu

Re: Look-ahead arguments in for loops

2005-09-29 Thread Luke Palmer
On 9/29/05, Dave Whipp <[EMAIL PROTECTED]> wrote: >for grep {defined} @in -> $item, ?$next { > print $item unless defined $next && $item eq $next; >} This is an interesting idea. Perhaps "for" (and "map") shift the minimum arity of the block from the given list and bind the maximum a

Re: Look-ahead arguments in for loops

2005-09-29 Thread Austin Hastings
Dave Whipp wrote: > Imagine you're writing an implementation of the unix "uniq" function: > >my $prev; >for grep {defined} @in -> $x { >print $x unless defined $prev && $x eq $prev; >$prev = $x; >} > > This feels clumsy. $prev seems to get in the way of what I'm trying