Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

More on slices and iterators

5 views
Skip to first unread message

Dan Sugalski

unread,
Jun 15, 2004, 12:57:13 PM6/15/04
to perl6-i...@perl.org
Okay, before we go any further, I think it's important to note that
we're going to restrict ourselves to unidimensional slices for the
time being. Yes, I know, we probably need to deal with
multidimensional slices at some point (and I say probably since there
are quite a number of different ways to specify and iterate over
multidimensional slices--I don't think there'll be any one true way
for those, which makes me think perhaps slices aren't the way to go
there) but for now unidimensional slices are enough of an issue.

I can see the point of having each list element of a slice being an
iterator rather than a set of discreet start/end pairs. That'd be
handy in some cases, and avoid having the perl 6 compiler having to
construct iterators by hand rather with slices. (On the other hand,
I'm perfectly fine with that, too)

So, given that, should plain scalars act as iterators holding a
single value and implement the iterator protocol? That'd make slice
implementation easier, but there's that whole nasty complexity thing
there. (Though without it there's the issue of complexity
elsewhere--no real win here, just a matter of deciding where to lose
less)
--
Dan

--------------------------------------it's like this-------------------
Dan Sugalski even samurai
d...@sidhe.org have teddy bears and even
teddy bears get drunk

mar...@kurahaupo.gen.nz

unread,
Jun 16, 2004, 7:55:08 PM6/16/04
to perl6-i...@perl.org
On Tue, 15 Jun 2004, Dan Sugalski wrote:
> So, given that, should plain scalars act as iterators holding a single
> value and implement the iterator protocol?

That'd be messy if two things tried to take an iterator over the same scalar
as the same time. On the other hand if it created an iterator as a separate
PMC then can see that would save having to construct an anonymous singleton
array, and then an iterator over that.

I would envisage that when the Perl6 compiler sees

@foo[2, 3..7 :by(2), 11, 13, 17]

it would create four iterators: one each over [2], [3..7:/2] and [11,13,17],
and a concatenation iterator over those. Whether the iterator over [2] is
created over a singleton array or directly from the scalar would seem to be
simply a matter of economy.

-Martin


0 new messages