<Moved to perl6-language-data from PDL Porters>

Robin Williams wrote:
> "Jeremy Howard" writes:-
>
> > The first version of this
> > RFC had a
> >
> >   @start..$end:&gen
> >
> > but it just seems too dangerous, so I removed it. I'm still willing to
be
> > convinced though...
>
> as well as @start..&gen:$num_steps ?  Yes, I'd agree you'd have to
> choose one!!
>
No, *instead* of.

> But `@start..$end:&gen' still seems the more natural choice to me --
> easier to remember, maybe even easier to parse, a scalar in any
> position always means the same thing...
>
Yes, I like it too, but the problem is that $end may not be reached:

  @weird = (0..5: ^0 mod 2);

is an infinite loop under this proposal. That's not necessarily a dead-end,
but it seems pretty dangerous. The $num_steps proposal could be a lot faster
too, because a fast loop could be generated (particularly if we define some
functions that are easily optimised, like ufuncs in Numeric Python):

  http://starship.python.net/~da/numtut/array.html#SEC13

> Any other ideas?
>
> o Use the `:' as a kind of `modifier' syntax (cf shell environment
> variables)
> 2..10:(n,&gen)
> -- ugly, & I still don't like the 10 being $num_steps, but might allow
> some kind of regexp-like optimization hints.
>
> o Just allow &gen to do what it likes with the 2nd argument to `..'
> and return undefined at termination -- probably just _too_ laissez
> faire.  Or, along similar lines, allow the second argument to be a
> test, so
> @start : &test : &inc
> is more like
> for (i=1; i<=10; i++)
> -- with some way of accessing element number as well as values.
>
Yes, when I had the $end notation, I was planning to provide an &test syntax
too--I think if you had one you'd want both. BTW, the element number is
always available as the first argument to the list generation function.

> o Or even
> 2 x 10 : &gen
> -- at least, I'd _expect_ to get 10 things here!  2x10 <=> 2..sub{0}:10
> as TMTOWTDI seems a tad curious, on reflection.
>
Hmmm... an interesting one. Starting to look more Perlish and less
Matlabish, which may be a good or a bad thing depending on where you're
coming from...


Reply via email to