"Joe Gottman" <[EMAIL PROTECTED]> writes:
> In perl 6, the statement
>
> @foo = (1.. 5) ;
>
> is equivalent to
>
> @foo = (1, 2, 3, 4, 5);
>
>
>
> Is there similar shorthand to set @foo = (5, 3, 3, 2, 1) ? I know you can
> go
>
> @foo = reverse (1 ..5);
>
> but this has the major disadvantage that it cannot be evaluated lazily;
> reverse has to see the entire list before it can emit the first element of
> the reversed list. Would
>
> @foo = (5 .. 1 :by(-1));
>
> do the trick? If so, would the same trick work for
>
> @bar = ('e' .. 'a' :by(-1)); ?
@foo = 5.down_to(1)
Where down_to is
method Number::down_to ($self : Number $target) {
return if $self < $target;
return $self, ($self - 1).down_to($target);
}
You might have to do some monkeying around with a range object or
something to make it appropriately lazy, but that's a mere detail. Or
you could implement it as an operator. Or...