[nem-bug] [Nemerle 0000643]: Iterator as local fanction

feedback at nemerle.org feedback at nemerle.org
Mon Apr 3 23:28:53 CEST 2006


A NOTE has been added to this issue.
======================================================================
<http://nemerle.org/bugs/view.php?id=643> 
======================================================================
Reported By:                VladD2
Assigned To:                
======================================================================
Project:                    Nemerle
Issue ID:                   643
Category:                   Compiler
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     new
======================================================================
Date Submitted:             04-02-2006 19:16 CEST
Last Modified:              04-03-2006 23:28 CEST
======================================================================
Summary:                    Iterator as local fanction
Description: 
If try to implement the iterator as local function:
def FromTo(from : int, to : int) : IEnumerable[int]
{
  for (mutable i = from; i <= to; ++i)
    yield i;
}

ngg generate this error:
error : yield used in a function returning void (it should be
System.Collections.Generic.IEnumerator[T] or
System.Collections.Generic.IEnumerable[T])
error : yield used in a function returning void (it should be
System.Collections.Generic.IEnumerator[T] or
System.Collections.Generic.IEnumerable[T])


======================================================================

----------------------------------------------------------------------
 nazgul - 04-02-06 23:27 
----------------------------------------------------------------------
I guess it is designed this way:

foo () : IEnumerable [int]
{
  def several (x) {
      yield x;
      yield x + 1;
      yield x + 3;
  } 
  several (3);
  seveal (100);
}

so you use local function just as an utility to make a generator from your
global function

----------------------------------------------------------------------
 VladD2 - 04-03-06 15:09 
----------------------------------------------------------------------
If local function cannot implement iterators by design, it's necessary to
write about this in docs and tutorials, and certainly correct the error
message, because error message "...in a function returning void" is
confusing.

----------------------------------------------------------------------
 nazgul - 04-03-06 21:39 
----------------------------------------------------------------------
I fixed the message.

But if the global method type is correct and you use yield insie local
function, then error message is even worse:

t.n:8:7:8:12: error: non local goto (block return?) detected (l1036)
t.n:5:8:5:28: error: non local goto (block return?) detected (l1027)


for

class A {
  public foo () : IEnumerable [int]
  {
    def several (x) {
      yield x;
      yield x + 1;
      yield x + 3;
    }
    several (3);
    several (100);
  }  
}

----------------------------------------------------------------------
 VladD2 - 04-03-06 23:28 
----------------------------------------------------------------------
Hm... If I understand you correctly, you told about another situation.
I told about situation when programmer try to implement iterator directly 
in the local function. i.e. in situation like this:
module App
{
  Main() void
  {
    def F() : IEnumerable [int]
    {
      yield 1;
    } 
  }
}

the user taken error message:
error : yield used in a function returning void (it should be
System.Collections.Generic.IEnumerator[T] or
System.Collections.Generic.IEnumerable[T])

he will be confused.  

PS
BTW...How get SVN version of Nemerle?

Issue History
Date Modified  Username       Field                    Change              
======================================================================
04-02-06 19:16 VladD2         New Issue                                    
04-02-06 23:27 nazgul         Note Added: 0001140                          
04-03-06 15:09 VladD2         Note Added: 0001142                          
04-03-06 21:39 nazgul         Note Added: 0001151                          
04-03-06 23:28 VladD2         Note Added: 0001156                          
======================================================================




More information about the bugs mailing list