Boo
  1. Boo
  2. BOO-366

Remove one level of indirection from generators and allow generator methods to use IEnumerator as the return type

    Details

    • Type: Improvement Improvement
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.5
    • Fix Version/s: 0.7
    • Component/s: Compiler
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Today is not possible to use yield to implement IEnumerable.GetEnumerator() because generators must be declared as returning IEnumerable.

      Another problem is that we always have one level of indirection from the enumerator which makes very hard to consume a generator() incrementally like:

      generator =

      { yield 1; yield 2 }

      e = generator()
      item, = e
      assert 1 == item
      item, = e
      assert 2 == item

      1. generator exhausted here

        Activity

        Hide
        Sorin Ionescu added a comment -

        Please cast the generators to the interface in question before you return them.
        Seeing __________generator1 is not pretty; we shouldn't have to type "GetEnumerator() as IEnumerator" to get around that.

        Show
        Sorin Ionescu added a comment - Please cast the generators to the interface in question before you return them. Seeing __________generator1 is not pretty; we shouldn't have to type "GetEnumerator() as IEnumerator" to get around that.
        Hide
        Rodrigo B. de Oliveira added a comment -

        If the method in question belongs to an implemented interface its return type will be preserved.

        The anonymous types are necessary to preserve type informaiton.

        Show
        Rodrigo B. de Oliveira added a comment - If the method in question belongs to an implemented interface its return type will be preserved. The anonymous types are necessary to preserve type informaiton.
        Hide
        Rodrigo B. de Oliveira added a comment -

        I didn't remove the level of indirection but simply allowed generator methods to declare their return type as IEnumerator directly. This has the advantage of not breaking any code while still allowing to easily implement IEnumerable.GetEnumerator.

        Show
        Rodrigo B. de Oliveira added a comment - I didn't remove the level of indirection but simply allowed generator methods to declare their return type as IEnumerator directly. This has the advantage of not breaking any code while still allowing to easily implement IEnumerable.GetEnumerator.

          People

          • Assignee:
            Rodrigo B. de Oliveira
            Reporter:
            Rodrigo B. de Oliveira
          • Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: