← Back to team overview

ooc-dev team mailing list archive

Re: Back/front methods for Iterable (and reverse iterators)

 

I still disagree with the usage of templates/generics for anything like
that, and would rather leave that to C++/D, but just for the record, there's
no need at all to add anything to the language to achieve what you asked.

one could declare iterator as:

iterator: func <T> (T: Class) -> T {}


Implement it like:

iterator: func <T> (T: Class) -> T {
  match(T) {
    case BackIterator =>
      return MyBackIterator new(this)
    case AdvanceIterator =>
      return MyAdvanceIterator new(this)
    case =>
      Exception new("Asked for unsupported iterator type: %s" format(T
name)) throw(); null
  }
}

And then call it like:

iter := list iterator(BackIterator) // iter is now a BackIterator
iter next()
iter prev()

etc.

And you could have a default property in you list implementation that calls
iterator(AdvanceIterator) or something

But as I said, that's really overkill.

Just showing off the language's power.

Amos

2010/6/3 Iván Hernández <ivanhv77@xxxxxxxxxxx>

> El jue, 03-06-2010 a las 05:59 -0700, Noel Cower escribió:
> > Responding to what Iván said, so apologies for having Amos's response
> > in there too.
> >
> Thanks for the explanation in the rest of your message about Iterators.
> I think I'm now a bit more clear about their design.
>
> > That said, the generic function really seems like overkill to me, and
> > I'd prefer not to ever have to type so much just for an iterator.
>
> I'd prefer that, too. But I think a language can be tweaked to simplfy
> the way it uses it's own core libraries (a great example of that is C#
> events, that are syntax sugar for a big bunch of code lines using
> event's dispatcher objects). As ooc syntax is not fully stabilized yet
> (pr so I thought), now is the time to do that kind of improvements, if
> the need for them is found. Later, it will be not so easy to do this
> kind of changes. That's why I proposed to have a for syntax that
> transparently inserts the expansion to a generic call.
>
> >
> > Anyhow, in short, I think we've got enough base iterator types to last
> > us, don't think anymore are needed right now, and really don't want to
> > use generics for the sake of using generics (or templates, in this
> > case).  I'd use C++ if I wanted that.
>
> I apologized to Amos for my proposal about something is already
> stablished. Blame my ignorance (and the pile of messages pending to be
> read on my localbox from ooc mailing list). Agein, I'm sorry.
>
>
> > Hopefully that makes sense, since I started writing this a while ago
> > and I'm not sure about the coherency of my e-mails after I've tweaked
> > them for so long.
> >
> It helped me a lot, thanks.
>
>
>
>

References