jastrachan | 18 Apr 09:53 2005
Picon

Re: [groovy-dev] Generators and stuff

I think this might work if you use

foo.&myGenerator

On 16 Apr 2005, at 09:54, Russel Winder wrote:
> Some time ago there was a debate about generators and someone posted 
> the
> code (which I think used to compile and run):
>
>         class Foo {
>           myGenerator ( yield ) {
>             yield "A"
>             yield "B"
>             yield ( "C" )
>           }
>
>           static void main ( args ) {
>             foo = new Foo ( )
>             for ( x in foo.myGenerator ) {
>               println x
>             }
>           }
>         }
>
>         foo = new Foo ( )
>         for ( x in foo.myGenerator ) {
>           print ( "${x}-" )
>         }
>
> Compiling this gives one of those horrible parser error messages:
>
>         Caught: General error during parsing: unexpected token: 
> myGenerator
>
>         /home/users/russel/Progs/Groovy/./testing.groovy:4:3: 
> unexpected token: myGenerator
>
> (stack trace deleted) which I understand, we have a missing 'def' but I
> think the parser should report something is missing in this situation 
> --
> isn't that the whole point of using def?
>
> Anyway add the def and we get the new error:
>
>         Caught: groovy.lang.MissingPropertyException: No such 
> property: myGenerator for class: Foo
>                 at 
> Foo.getProperty(/home/users/russel/Progs/Groovy/./testing.groovy)
>                 at 
> testing.run(/home/users/russel/Progs/Groovy/./testing.groovy:19)
>                 at 
> testing.main(/home/users/russel/Progs/Groovy/./testing.groovy)
>
> so clearly foo.myGenerator no longer has the semantic interpretation it
> used to.  The question is, of course, have we lost some functionality 
> or
> is the new idiom to make this code work something that I have just
> missed.
>
> Thanks.
>
> PS  Still not sure about having that last line about testing.main.
> -- 
> Russel.
> ====================================================
> Dr Russel Winder                +44 20 7585 2200
> 41 Buckmaster Road              +44 7770 465 077
> London SW11 1EN, UK             russel@...
>

James
-------
http://radio.weblogs.com/0112098/


Gmane