Details
-
Type:
Wish
-
Status:
Closed
-
Priority:
Major
-
Resolution: Won't Fix
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
Number of attachments :
Description
Generators (like list comprehensions but without the list) rock. We need to add something like this to the language...
e.g.
Issue Links
- is depended upon by
-
GROOVY-762
implement syntax improvements
-
- relates to
-
GROOVY-2046
MethodClosure iterators could loop forever
-
-
GROOVY-4105
List Comprehensions are Missing from Groovy
-
Activity
james strachan
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Fix Version/s | 1.0-beta-3 [ 10242 ] |
james strachan
made changes -
| Fix Version/s | 1.0-beta-3 [ 10242 ] | |
| Fix Version/s | 1.0-beta-4 [ 10243 ] |
james strachan
made changes -
| Fix Version/s | 1.0-beta-4 [ 10243 ] | |
| Fix Version/s | 1.1 [ 10436 ] |
Stepan Koltsov
made changes -
| Attachment | Generator.java [ 11872 ] |
blackdrag blackdrag
made changes -
| Link |
This issue is depended upon by |
blackdrag blackdrag
made changes -
| Link |
This issue is depended upon by |
blackdrag blackdrag
made changes -
| Link |
This issue is depended upon by |
Guillaume Laforge
made changes -
| Fix Version/s | 1.1-beta-2 [ 10436 ] |
Guillaume Laforge
made changes -
| Fix Version/s | 2.0 [ 13489 ] |
Russel Winder
made changes -
| Link | This issue relates to GROOVY-4105 [ GROOVY-4105 ] |
Paul King
made changes -
| Link |
This issue relates to |
blackdrag blackdrag
made changes -
| Status | Open [ 1 ] | Closed [ 6 ] |
| Assignee | Jochen Theodorou [ blackdrag ] | |
| Fix Version/s | 2.0 [ 13489 ] | |
| Resolution | Won't Fix [ 2 ] |
Is anybody alive here? I tried to comment other issues but didn't get any answers
Comment for this issue: as far as I understand, generators must be executed in another stack (not current). The one way to create new stack in Java is to create Thread. So generators should be executed in another thread. So code like:
def f() {
{ yield factorial(i); }for (i: 0..3)
}
should be compiled to something like:
class Generator implements Iterator {
yieldValue;
next() {
{ returnValue = yieldValue; thread.notify(); // object has been read return returnValue; }if (!hasNext())
throw new NoSuchElementException();
synchronized (thread)
}
hasNext()
{ ... }class GeneratorThread extends Thread {
{ yieldValue = factorial(i); thread.wait(); // wait object has been read }synchornized run() {
for (i: 0..3)
}
}
GeneratorThread thread;
Generator()
{ thread = new GeneratorThread(); thread.start(); }}
def f() {
return new Generator();
}
Real code is harder to understand. I'll attach working Generator class, written in Java in 5 minutes.
I'm right? So I'd like to implements this in Groovy...