[groovy-user] a dummy question

classic Classic list List threaded Threaded
7 messages Options
tog
Reply | Threaded
Open this post in threaded view
|

[groovy-user] a dummy question

tog
What am I doing wrong with this, I get the following error::

$ groovy benchmark2.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException:
startup failed, benchmark2.groovy: 5: Unexpected node type: ELIST
found when expecting type: an identifier at line: 5 column: 6. File:
benchmark2.groovy @ line 5, column 6.
   for (j=0; j < 20; j++) {



long t=System.currentTimeMillis();
double seed=0.5
int j, i
for (j=0; j < 20; j++) {
  for (i=0; i < 1000000; i++) {
    seed = Math.cos(seed + i)
  }
}

println System.currentTimeMillis() - t
println seed

cheers
tog

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: [groovy-user] a dummy question

Edward Povazan
There should be a list for bug fixing :) so much easier to spot bugs in other
peoples code: Groovy doesn't support the Java 'for' statement. You need:
for (j in 0..<20) { ... }
-Ed

tog wrote:

> What am I doing wrong with this, I get the following error::
>
> $ groovy benchmark2.groovy
> org.codehaus.groovy.control.MultipleCompilationErrorsException:
> startup failed, benchmark2.groovy: 5: Unexpected node type: ELIST
> found when expecting type: an identifier at line: 5 column: 6. File:
> benchmark2.groovy @ line 5, column 6.
>   for (j=0; j < 20; j++) {
>
>
>
> long t=System.currentTimeMillis();
> double seed=0.5
> int j, i
> for (j=0; j < 20; j++) {
>  for (i=0; i < 1000000; i++) {
>    seed = Math.cos(seed + i)
>  }
> }
>
> println System.currentTimeMillis() - t
> println seed
>
> cheers
> tog
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: [groovy-user] a dummy question

paulk_asert
In reply to this post by tog

The following worked for me (after removing the unsupported 'for' syntax):
-------
long t = System.currentTimeMillis()
double seed = 0.5
(0..<20).each {
 for (i in 0..<1000000) {
   seed = Math.cos(seed + i)
 }
}

println System.currentTimeMillis() - t
println seed
--------

Not that I am a fan of the missing syntax but I guess it was
argued out before my time.

A subtle one, replacing '(0..<20).each' with '0..<20.each' didn't work.
I guess '.' has higher precedence than '..'.

Cheers, Paul.


tog wrote:

> What am I doing wrong with this, I get the following error::
>
> $ groovy benchmark2.groovy
> org.codehaus.groovy.control.MultipleCompilationErrorsException:
> startup failed, benchmark2.groovy: 5: Unexpected node type: ELIST
> found when expecting type: an identifier at line: 5 column: 6. File:
> benchmark2.groovy @ line 5, column 6.
>   for (j=0; j < 20; j++) {
>
>
>
> long t=System.currentTimeMillis();
> double seed=0.5
> int j, i
> for (j=0; j < 20; j++) {
>  for (i=0; i < 1000000; i++) {
>    seed = Math.cos(seed + i)
>  }
> }
>
> println System.currentTimeMillis() - t
> println seed
>
> cheers
> tog
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: [groovy-user] a dummy question

Scott Hickey-3
In reply to this post by tog

 
Scott


----- Original Message ----
From: tog <[hidden email]>
To: [hidden email]
Sent: Friday, June 2, 2006 5:07:52 PM
Subject: [groovy-user] a dummy question

What am I doing wrong with this, I get the following error::

$ groovy benchmark2.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException:
startup failed, benchmark2.groovy: 5: Unexpected node type: ELIST
found when expecting type: an identifier at line: 5 column: 6. File:
benchmark2.groovy @ line 5, column 6.
   for (j=0; j < 20; j++) {



long t=System.currentTimeMillis();
double seed=0.5
int j, i
for (j=0; j < 20; j++) {
  for (i=0; i < 1000000; i++) {
    seed = Math.cos(seed + i)
  }
}

println System.currentTimeMillis() - t
println seed

cheers
tog

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: [groovy-user] a dummy question

Scott Hickey-3
In reply to this post by tog
def t=System.currentTimeMillis();
def seed = 0.5d
20.times{
 1000000.times { seed = Math.cos(seed + it) }
}
println System.currentTimeMillis() - t
println seed


 
Scott


----- Original Message ----
From: tog <[hidden email]>
To: [hidden email]
Sent: Friday, June 2, 2006 5:07:52 PM
Subject: [groovy-user] a dummy question

What am I doing wrong with this, I get the following error::

$ groovy benchmark2.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException:
startup failed, benchmark2.groovy: 5: Unexpected node type: ELIST
found when expecting type: an identifier at line: 5 column: 6. File:
benchmark2.groovy @ line 5, column 6.
   for (j=0; j < 20; j++) {



long t=System.currentTimeMillis();
double seed=0.5
int j, i
for (j=0; j < 20; j++) {
  for (i=0; i < 1000000; i++) {
    seed = Math.cos(seed + i)
  }
}

println System.currentTimeMillis() - t
println seed

cheers
tog

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

tog
Reply | Threaded
Open this post in threaded view
|

Re: [groovy-user] a dummy question

tog
In reply to this post by Edward Povazan
thanks a lot Ed ...grrr I should have remember this ;-)

On 6/3/06, Edward Povazan <[hidden email]> wrote:

> There should be a list for bug fixing :) so much easier to spot bugs in other
> peoples code: Groovy doesn't support the Java 'for' statement. You need:
> for (j in 0..<20) { ... }
> -Ed
>
> tog wrote:
> > What am I doing wrong with this, I get the following error::
> >
> > $ groovy benchmark2.groovy
> > org.codehaus.groovy.control.MultipleCompilationErrorsException:
> > startup failed, benchmark2.groovy: 5: Unexpected node type: ELIST
> > found when expecting type: an identifier at line: 5 column: 6. File:
> > benchmark2.groovy @ line 5, column 6.
> >   for (j=0; j < 20; j++) {
> >
> >
> >
> > long t=System.currentTimeMillis();
> > double seed=0.5
> > int j, i
> > for (j=0; j < 20; j++) {
> >  for (i=0; i < 1000000; i++) {
> >    seed = Math.cos(seed + i)
> >  }
> > }
> >
> > println System.currentTimeMillis() - t
> > println seed
> >
> > cheers
> > tog
> >
> > ---------------------------------------------------------------------
> > To unsubscribe from this list please visit:
> >
> >    http://xircles.codehaus.org/manage_email
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

tog
Reply | Threaded
Open this post in threaded view
|

Re: [groovy-user] a dummy question

tog
In reply to this post by Scott Hickey-3
Hi Scott,
I knew about this one but actually the for loop if far more efficient
than the times
(spped up by a factor of 1.4 to 2)

cheers
tog

On 6/3/06, Scott Hickey <[hidden email]> wrote:

>
> def t=System.currentTimeMillis();
> def seed = 0.5d
> 20.times{
>  1000000.times { seed = Math.cos(seed + it) }
>
> }
> println System.currentTimeMillis() - t
> println seed
>
>
>
> Scott
>
>
>
> ----- Original Message ----
> From: tog <[hidden email]>
> To: [hidden email]
> Sent: Friday, June 2, 2006 5:07:52 PM
> Subject: [groovy-user] a dummy question
>
>
> What am I doing wrong with this, I get the following error::
>
> $ groovy benchmark2.groovy
> org.codehaus.groovy.control.MultipleCompilationErrorsException:
> startup failed, benchmark2.groovy: 5: Unexpected node type: ELIST
> found when expecting type: an identifier at line: 5 column: 6. File:
> benchmark2.groovy @ line 5, column 6.
>    for (j=0; j < 20; j++) {
>
>
>
> long t=System.currentTimeMillis();
> double seed=0.5
> int j, i
> for (j=0; j < 20; j++) {
>   for (i=0; i < 1000000; i++) {
>     seed = Math.cos(seed + i)
>   }
> }
>
> println System.currentTimeMillis() - t
> println seed
>
> cheers
> tog
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email