Groovy JSR-05 released!

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

Groovy JSR-05 released!

Guillaume Laforge
Administrator
Dear users, and dear developers,


I'm pleased to announce the release of Groovy JSR-05. This is the last
release of the JSR-xx line. The next release will be the first RC-x
release before the final 1.0.

You can read more about our updated roadmap here:
http://groovy.codehaus.org/Roadmap

We're planning to release RC-1 in about two months, and the final
Groovy 1.0 release should be out in about three months.

As you might know, and as decided during the last Groovy conference in
Paris, the two main tasks towards the final version of the projects
are the rework of the scoping algorithms, and the rewrite and
enhancements of the Meta-Object Protocol. JSR-05 contains these new
scoping algorithms. A lot of very old bugs regarding nested closures
or creation of variables shadowing other variables have been fixed, as
well as bugs regarding visibility of fields, among other things. The
next step before RC-1 is the work on the MOP and name resolution
algorithms.

Apart from the work on scoping, a few important bugs or enhancements
have found their way in this release:

* multidimensional arrays are now fully supported
* Groovysh supports multiline scripts again
* an experimental feature has been added to GroovyClassLoader to allow
reloading of classes when changed
* small improvements to GroovyShell and GroovyScriptEngine
* possibility to call methods with method names defined in Strings or
GStrings: "foo-bar"(), or "$baz"()

Warning: there is an important change in scripts between "def-ed"
variables and not "def-ed" variables. Defining a variable with the def
keyword or with a concrete type creates a local variable which won't
be stored in the binding. However, if you assign a variable which
wasn't defined in your script, it will be stored in the binding of the
script.

For further details about the release notes, please have a look at the
JIRA release notes:
http://jira.codehaus.org/secure/ReleaseNote.jspa?projectId=10242&styleName=Text&version=12102

You can download the Groovy distribution at the usual place:
http://dist.codehaus.org/groovy/distributions/groovy-1.0-jsr-05.zip

Thanks to everybody who helped on this release, and a very big thank
you to Jochen Theodorou who made very important improvements to our
rusty and limited scoping algorithms.


Enjoy!


--
Guillaume Laforge
Groovy Project Manager
http://glaforge.free.fr/blog/groovy
Reply | Threaded
Open this post in threaded view
|

Re: Groovy JSR-05 released!

krsmes
Guillaume Laforge <glaforge@...> writes:

>
>
> Warning: there is an important change in scripts between "def-ed"
> variables and not "def-ed" variables. Defining a variable with the def
> keyword or with a concrete type creates a local variable which won't
> be stored in the binding. However, if you assign a variable which
> wasn't defined in your script, it will be stored in the binding of the
> script.
>
>
> Enjoy!
>


This issue you warned on below has broken all of my groovy 'scripts'.

How can one access script variables inside a method?

For example, here is part of a file named http.groovy:

def session = null

def init() {
  if (session==null || defaults.resetSession)
    session = new org.apache.commons.httpclient.HttpClient()
  //...
}

def parseEvaluate() {
  //...
  evaluate(lineIReadFromFile)
}

init()
parseEvaluate()
session.executeMethod(method)


Now I get errors "No such property: session for class: http"

I don't understand how to use groovy now to make simple scripts with method
definitions as the methods do not have access to any of the 'global' variables.
 Nor can I dynamically evaluate chunks of groovy code to alter my state/'global'
variables.


I've tried to put these all in a class (class http {...) but still cannot get
the 'evaluate' to work.  I've tried having the class extend GroovyShell but that
didn't work either.  How come groovy is no longer usable for simple scripts?

Any ideas?


Reply | Threaded
Open this post in threaded view
|

Re: Re: Groovy JSR-05 released!

Guillaume Laforge
Administrator
Hello,

Inside a script, if you want your session variable to be available to
all functions of your script, you should just remove the def in front
of the session declaration:

session = null

(instead of def session = null)

Un-def-ined variables will go into the binding as they used to before
that change.

On 4/19/06, K S <[hidden email]> wrote:

> Guillaume Laforge <glaforge@...> writes:
> >
> >
> > Warning: there is an important change in scripts between "def-ed"
> > variables and not "def-ed" variables. Defining a variable with the def
> > keyword or with a concrete type creates a local variable which won't
> > be stored in the binding. However, if you assign a variable which
> > wasn't defined in your script, it will be stored in the binding of the
> > script.
> >
> >
> > Enjoy!
> >
>
>
> This issue you warned on below has broken all of my groovy 'scripts'.
>
> How can one access script variables inside a method?
>
> For example, here is part of a file named http.groovy:
>
> def session = null
>
> def init() {
>   if (session==null || defaults.resetSession)
>     session = new org.apache.commons.httpclient.HttpClient()
>   //...
> }
>
> def parseEvaluate() {
>   //...
>   evaluate(lineIReadFromFile)
> }
>
> init()
> parseEvaluate()
> session.executeMethod(method)
>
>
> Now I get errors "No such property: session for class: http"
>
> I don't understand how to use groovy now to make simple scripts with method
> definitions as the methods do not have access to any of the 'global' variables.
>  Nor can I dynamically evaluate chunks of groovy code to alter my state/'global'
> variables.
>
>
> I've tried to put these all in a class (class http {...) but still cannot get
> the 'evaluate' to work.  I've tried having the class extend GroovyShell but that
> didn't work either.  How come groovy is no longer usable for simple scripts?
>
> Any ideas?
>
>
>


--
Guillaume Laforge
Groovy Project Manager
http://glaforge.free.fr/blog/groovy
Reply | Threaded
Open this post in threaded view
|

Re: Re: Groovy JSR-05 released!

spullara.1684899
In reply to this post by Guillaume Laforge
Ok, I have to speak up about this one.  This is ridiculous and totally violates
the principle of least surprise.  Why wouldn't I be able to see def'd variables
from the script within methods defined in the same script?  Now not only can
I not cut and paste code from java to groovy I can't even cut and paste code
from groovy classes to groovy scripts!



Sam



--- [hidden email]
wrote:

Hello,

>

> Inside a script, if you want your session variable to
be available to

> all functions of your script, you should just remove the
def in front

> of the session declaration:

>

> session = null

>

> (instead
of def session = null)

>

> Un-def-ined variables will go into the binding
as they used to before

> that change.

>
Reply | Threaded
Open this post in threaded view
|

Re: Re: Groovy JSR-05 released!

tugwilson

On 20 Apr 2006, at 07:14, [hidden email] wrote:

> Ok, I have to speak up about this one.  This is ridiculous and  
> totally violates
> the principle of least surprise.  Why wouldn't I be able to see  
> def'd variables
> from the script within methods defined in the same script?  Now not  
> only can
> I not cut and paste code from java to groovy I can't even cut and  
> paste code
> from groovy classes to groovy scripts!

We have discussed this on the dev list and I rather agree with you, Sam.

I have suggested that defed variables at the outermost level of a  
script become instance variables on the script object (and, when we  
get rid of @Property, become properties).

An alternative suggestion is to move these variable onto the heap  
using the same trick we use for closures.

I don't think we have it quite right yet

def x = 0

def f1 = {println x}

def f2() { println x}

f1() // works

f2() // fails


John Wilson
The Wilson Partnership
web http://www.wilson.co.uk
blog http://eek.ook.org


Reply | Threaded
Open this post in threaded view
|

Re: Re: Groovy JSR-05 released!

Eric Armstrong-2
In reply to this post by spullara.1684899
Can anyone tell me why I am still on this list??

The email message lists "Sender" as
jsr-return-1473-Eric.Armstrong=[hidden email]

That makes no sense at all to me. I unsubscribed a
month ago, at least. At first, I thought someone
was doing a reply all to a thread I happened to
comment on, so I overlooked the occasional message.

But now it appears that my attempted unsubscribe
did not take effect.

[hidden email] wrote:

> Ok, I have to speak up about this one.  This is ridiculous and totally violates
> the principle of least surprise.  Why wouldn't I be able to see def'd variables
> from the script within methods defined in the same script?  Now not only can
> I not cut and paste code from java to groovy I can't even cut and paste code
> from groovy classes to groovy scripts!
>
> Sam
>
> --- [hidden email]
> wrote:
> Hello,
>> Inside a script, if you want your session variable to
> be available to
>> all functions of your script, you should just remove the
> def in front
>> of the session declaration:
>>
>> session = null
>>
>> (instead
> of def session = null)
>> Un-def-ined variables will go into the binding
> as they used to before
>> that change.
>>