[groovy-user] Closure tutorial...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[groovy-user] Closure tutorial...

John Sanabria
Hi, users list

i'm reading the closure section in http://groovy.codehaus.org/Closures,
and i try the example:

------------------------ GVector.groovy -------------------------
package example;

public class GVector extends java.lang.Vector {

  public GVector(){
      super();
  }

  public void apply( c ){
     for(int I = 0; I < this.size(); I++){

         old_element = this.elementAt(i);
         new_element = c.call(old_element);
         this.set( I, new_element);

     }
  }
}
------------------------ GVector.groovy -------------------------
and when i compile this file i got this message:

josanabr@linux:~/Documents/Groovy/testing/closure> groovyc
example/GVector.groovy
example/GVector.groovy: 9: Unexpected node type: TYPE found when expecting
type: an identifier at line: 9 column: 18. File: example/GVector.groovy @
line 9, column 18.
                                                                for (int I
= 0; I <
this.size();
I++) {
                    ^

1 Error

thanks for your help.

regards.

                    (`'`'`'`'`)
                     |       |
                     |       |
                     |       |
    -----..        (()----   |
   |        ||     (_        |
   |        ||       |       |
   |        ||       |       |
   |        ||       /\   ..--
   '--------''   /\  ||-''    \
      /   \      \ \//   ,,   \---.
   .---------.    \./ |~| /__\  \  |
___|_________|__|""-.___ / ||   |  |
|               | .-----'  ||   |  |
|               |CC.-----.      |  |
|               |  '-----'      |  |-ABG
                                |  |
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [groovy-user] Closure tutorial...

Jochen Theodorou
[hidden email] schrieb:
> Hi, users list
>
> i'm reading the closure section in http://groovy.codehaus.org/Closures,
> and i try the example:

ah... we have to change this.

  package example;

  public class GVector extends Vector {

    public void apply( c ){
       for(i in o..<size()){
           def old_element = this[i]
           this[i] = c(old_element)
       }
    }
  }

bye blackdrag
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [groovy-user] Closure tutorial...

Martin C. Martin


Jochen Theodorou wrote:

> [hidden email] schrieb:
>
>> Hi, users list
>>
>> i'm reading the closure section in http://groovy.codehaus.org/Closures,
>> and i try the example:
>
>
> ah... we have to change this.
>
>  package example;
>
>  public class GVector extends Vector {
>
>    public void apply( c ){
>       for(i in o..<size()){
>           def old_element = this[i]
>           this[i] = c(old_element)
>       }
>    }
>  }
>
> bye blackdrag

Although, this fails when the GVector is of size 0.  I'll change the web
page to:

package example;

  public class GVector extends Vector {

    public void apply( c ){
       if (size() > 0) {
          for(i in o..size()){
             def old_element = this[i]
             this[i] = c(old_element)
          }
       }
    }
  }

- Martin
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [groovy-user] Closure tutorial...

Jochen Theodorou
Martin C. Martin schrieb:

[...]
> Although, this fails when the GVector is of size 0.

0..<0 is not empty? sound like a bug... ahh I remember... wasn't there a
entry for that ;)

bye blackdrag
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: [groovy-user] Closure tutorial...

Dierk König
this is fixed meanwhile

> -----Original Message-----
> From: Jochen Theodorou [mailto:[hidden email]]
> Sent: Mittwoch, 2. November 2005 15:09
> To: [hidden email]
> Subject: Re: [groovy-user] Closure tutorial...
>
>
> Martin C. Martin schrieb:
>
> [...]
> > Although, this fails when the GVector is of size 0.
>
> 0..<0 is not empty? sound like a bug... ahh I remember... wasn't there a
> entry for that ;)
>
> bye blackdrag
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [groovy-user] Closure tutorial...

Martin C. Martin


Dierk Koenig wrote:

>this is fixed meanwhile
>  
>
Cool!

>>-----Original Message-----
>>From: Jochen Theodorou [mailto:[hidden email]]
>>
>>
>>Martin C. Martin schrieb:
>>
>>[...]
>>    
>>
>>>Although, this fails when the GVector is of size 0.
>>>      
>>>
>>0..<0 is not empty? sound like a bug... ahh I remember... wasn't there a
>>entry for that ;)
>>
;)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [groovy-user] Closure tutorial...

Jochen Theodorou
In reply to this post by Dierk König
Dierk Koenig schrieb:

> this is fixed meanwhile

thought so ;)

bye blackdrag
Loading...