Smylers wrote:
> Jon Lang writes:
>> Approaching this with the notion firmly in mind that infix:<..> is
>> supposed to be used for matching ranges while infix:<...> should be
>> used to generate series:
>> With series, we want C< $LHS ... $RHS > to generate a list of items
>> starting with $LHS and ending with $RHS.  If $RHS > $LHS, we want it
>> to increment one step at a time; if $RHS < $LHS, we want it to
>> decrement one step at a time.
> Do we?

Yes, we do.

> I'm used to generating lists and iterating over them (in Perl 5)
> with things like like:
>  for (1 .. $max)
> where the intention is that if $max is zero, the loop doesn't execute at
> all. Having the equivalent Perl 6 list generation operator, C<...>,
> start counting backwards could be confusing.
> Especially if Perl 6 also has a range operator, C<..>, which would Do
> The Right Thing for me in this situation, and where the Perl 6 operator
> that Does The Right Thing is spelt the same as the Perl 5 operator that
> I'm used to; that muddles the distinction you make above about matching
> ranges versus generating lists.

It does muddy the difference, which is why my own gut instinct would
have been to do away with infix:<..>'s ability to generate lists.
Fortunately, I'm not in charge here, and wiser heads than mine have
decreed that infix:<..>, when used in list context, will indeed
generate a list in a manner that closely resembles Perl 5's range
operator: start with the LHS, then increment until you equal or exceed
the RHS - and if you start out exceeding the RHS, you've got yourself
an empty list.

You can do the same thing with the infix:<...> operator, too; but
doing so will be bulkier (albeit much more intuitive).  For example,
the preferred Perl 6 approach to what you described would be:

    for 1, 2 ... $x

The two-element list on the left of the series operator invokes a bit
of magic that tells it that the algorithm for generating the next step
in the series is to invoke the increment operator.  This is all
described in S03 in considerable detail; I suggest rereading the
section there concerning the series operator before passing judgment
on it.  .

Jonathan "Dataweaver" Lang

Reply via email to