Jochen Theodorou | 26 Jun 2012 13:17
Picon
Gravatar

[groovy-user] Groovy 3

Hi all,

soon Groovy 2 will be released and I will start on working for Groovy 3, 
which is supposed to get released next year. Groovy 3 will contain a new 
MOP and some semantic changes. I thought I start a GEP (GEP-11) for this 
to make it more easy for people to contribute. I only just started the 
with some things I want not to have anymore in Groovy3. I will soon try 
to describe the new MOP. But most probably that will be in constant 
flux, since I will have to see if things work out right or not while I 
implement it.

So anyone who wants something absolutely in Groovy3 regarding semantics 
or the new MOP.. it would be a good time to speak now... for example in 
this thread. I will collect the ideas on the wiki page of the GEP and 
possibly make them part of that "design document".

Those who want some syntactic changes, sorry, they will not be part of 
that GEP.

 <at> see 
http://docs.codehaus.org/display/GroovyJSR/GEP+11+-+Groovy+3+semantics+and+new+MOP

bye blackdrag

--

-- 
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org

(Continue reading)

Gavin Grover | 26 Jun 2012 14:56
Picon
Favicon

Re: [groovy-user] Groovy 3

Jochen,

will VMWare assign the budget for you to make semantic changes to Groovy and upgrade the MOP? The project
management don't seem to want to change anything 
e.g. the reply at http://groovy.329449.n5.nabble.com/Closures-closures-and-lambda-functions-tt5573493.html#a5573628

Gavin Grover
blog: http://groovy.codeplex.com/wikipage?title=Blog02
 email: gvgrover@...

----- Original Message -----
> From: Jochen Theodorou <blackdrag@...>
> To: user@...
> Cc: 
> Sent: Tuesday, June 26, 2012 7:17 PM
> Subject: [groovy-user] Groovy 3
> 
> Hi all,
> 
> soon Groovy 2 will be released and I will start on working for Groovy 3, which 
> is supposed to get released next year. Groovy 3 will contain a new MOP and some 
> semantic changes. I thought I start a GEP (GEP-11) for this to make it more easy 
> for people to contribute. I only just started the with some things I want not to 
> have anymore in Groovy3. I will soon try to describe the new MOP. But most 
> probably that will be in constant flux, since I will have to see if things work 
> out right or not while I implement it.
> 
> So anyone who wants something absolutely in Groovy3 regarding semantics or the 
> new MOP.. it would be a good time to speak now... for example in this thread. I 
> will collect the ideas on the wiki page of the GEP and possibly make them part 
(Continue reading)

Guillaume Laforge | 26 Jun 2012 15:14
Gravatar

Re: [groovy-user] Groovy 3

The mail you refer to has nothing to do with the current discussion. It was about a terminology aspect, where it might be confusing for users if we tell them Groovy "closures" aren't "closures" or should change name.

Here we speak about moving Groovy forward, fixing odd corner cases of the language and APIs, making the MOP more efficient, saner, etc.


On Tue, Jun 26, 2012 at 2:56 PM, Gavin Grover <gvgrover-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:
Jochen,

will VMWare assign the budget for you to make semantic changes to Groovy and upgrade the MOP? The project management don't seem to want to change anything 
e.g. the reply at http://groovy.329449.n5.nabble.com/Closures-closures-and-lambda-functions-tt5573493.html#a5573628

Gavin Grover
blog: http://groovy.codeplex.com/wikipage?title=Blog02
 email: gvgrover-/E1597aS9LQAvxtiuMwx3w@public.gmane.org



----- Original Message -----
> From: Jochen Theodorou <blackdrag-BA+cFGlbTmA@public.gmane.org>
> To: user-i9PBDF1N6cxnkHa44VUL02GXanvQGlWp@public.gmane.orgrg
> Cc:
> Sent: Tuesday, June 26, 2012 7:17 PM
> Subject: [groovy-user] Groovy 3
>
> Hi all,
>
> soon Groovy 2 will be released and I will start on working for Groovy 3, which
> is supposed to get released next year. Groovy 3 will contain a new MOP and some
> semantic changes. I thought I start a GEP (GEP-11) for this to make it more easy
> for people to contribute. I only just started the with some things I want not to
> have anymore in Groovy3. I will soon try to describe the new MOP. But most
> probably that will be in constant flux, since I will have to see if things work
> out right or not while I implement it.
>
> So anyone who wants something absolutely in Groovy3 regarding semantics or the
> new MOP.. it would be a good time to speak now... for example in this thread. I
> will collect the ideas on the wiki page of the GEP and possibly make them part
> of that "design document".
>
> Those who want some syntactic changes, sorry, they will not be part of that GEP.
>
> <at> see
> http://docs.codehaus.org/display/GroovyJSR/GEP+11+-+Groovy+3+semantics+and+new+MOP
>
> bye blackdrag
>
> -- Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
> blog: http://blackdragsview.blogspot.com/
> german groovy discussion newsgroup: de.comp.lang.misc
> For Groovy programming sources visit http://groovy-lang.org
>
>
>
> ---------------------------------------------------------------------
> 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





--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one
Gavin Grover | 26 Jun 2012 16:05
Picon
Favicon

Re: [groovy-user] Groovy 3

The rest of the referred thread, a discussion between Russel and Jochen, is another semantic change that
some might want in GEP-11, and has everything to do with the current discussion.

I was questioning whether the discussion will amount to any action if Jochen is writing "Groovy 3 will
contain a new MOP" below, but you're writing "moving Groovy forward, [...] making the MOP more efficient,
saner, etc."

Gavin Grover

>________________________________
> From: Guillaume Laforge <glaforge@...>
>To: user@... 
>Sent: Tuesday, June 26, 2012 9:14 PM
>Subject: Re: [groovy-user] Groovy 3
> 
>
>The mail you refer to has nothing to do with the current discussion. It was about a terminology aspect,
where it might be confusing for users if we tell them Groovy "closures" aren't "closures" or should change name.
>Here we speak about moving Groovy forward, fixing odd corner cases of the language and APIs, making the MOP
more efficient, saner, etc.
>
>
>
>On Tue, Jun 26, 2012 at 2:56 PM, Gavin Grover <gvgrover@...> wrote:
>
>Jochen,
>>
>>will VMWare assign the budget for you to make semantic changes to Groovy and upgrade the MOP? The project
management don't seem to want to change anything 
>>e.g. the reply at http://groovy.329449.n5.nabble.com/Closures-closures-and-lambda-functions-tt5573493.html#a5573628
>>
>>Gavin Grover
>>blog: http://groovy.codeplex.com/wikipage?title=Blog02
>> email: gvgrover@...
>>
>>
>>
>>
>>----- Original Message -----
>>> From: Jochen Theodorou <blackdrag@...>
>>> To: user@...
>>> Cc:
>>> Sent: Tuesday, June 26, 2012 7:17 PM
>>> Subject: [groovy-user] Groovy 3
>>>
>>> Hi all,
>>>
>>> soon Groovy 2 will be released and I will start on working for Groovy 3, which
>>> is supposed to get released next year. Groovy 3 will contain a new MOP and some
>>> semantic changes. I thought I start a GEP (GEP-11) for this to make it more easy
>>> for people to contribute. I only just started the with some things I want not to
>>> have anymore in Groovy3. I will soon try to describe the new MOP. But most
>>> probably that will be in constant flux, since I will have to see if things work
>>> out right or not while I implement it.
>>>
>>> So anyone who wants something absolutely in Groovy3 regarding semantics or the
>>> new MOP.. it would be a good time to speak now... for example in this thread. I
>>> will collect the ideas on the wiki page of the GEP and possibly make them part
>>> of that "design document".
>>>
>>> Those who want some syntactic changes, sorry, they will not be part of that GEP.
>>>
>>>  <at> see
>>> http://docs.codehaus.org/display/GroovyJSR/GEP+11+-+Groovy+3+semantics+and+new+MOP
>>>
>>> bye blackdrag
>>>
>>> -- Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
>>> blog: http://blackdragsview.blogspot.com/
>>> german groovy discussion newsgroup: de.comp.lang.misc
>>> For Groovy programming sources visit http://groovy-lang.org
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
>>
>
>
>
>-- 
>Guillaume Laforge
>Groovy Project Manager
>Head of Groovy Development at SpringSource
>http://www.springsource.com/g2one
>
>
>

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

    http://xircles.codehaus.org/manage_email

Guillaume Laforge | 26 Jun 2012 17:06
Gravatar

Re: [groovy-user] Groovy 3

I'm not sure I understand the polemical you're trying to create here, as Jochen and myself are all on the same wavelength.

The MOP needs to be rewritten, if that's a clearer statement you want to hear?

On Tue, Jun 26, 2012 at 4:05 PM, Gavin Grover <gvgrover-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:
The rest of the referred thread, a discussion between Russel and Jochen, is another semantic change that some might want in GEP-11, and has everything to do with the current discussion.

I was questioning whether the discussion will amount to any action if Jochen is writing "Groovy 3 will contain a new MOP" below, but you're writing "moving Groovy forward, [...] making the MOP more efficient, saner, etc."

Gavin Grover

>________________________________
> From: Guillaume Laforge <glaforge-yCVjj/EcxBJg9hUCZPvPmw@public.gmane.org>
>To: user-i9PBDF1N6cxnkHa44VUL08Xa4x6EXUF0@public.gmane.orgg
>Sent: Tuesday, June 26, 2012 9:14 PM
>Subject: Re: [groovy-user] Groovy 3
>
>
>The mail you refer to has nothing to do with the current discussion. It was about a terminology aspect, where it might be confusing for users if we tell them Groovy "closures" aren't "closures" or should change name.
>Here we speak about moving Groovy forward, fixing odd corner cases of the language and APIs, making the MOP more efficient, saner, etc.
>
>
>
>On Tue, Jun 26, 2012 at 2:56 PM, Gavin Grover <gvgrover-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:
>
>Jochen,
>>
>>will VMWare assign the budget for you to make semantic changes to Groovy and upgrade the MOP? The project management don't seem to want to change anything 
>>e.g. the reply at http://groovy.329449.n5.nabble.com/Closures-closures-and-lambda-functions-tt5573493.html#a5573628
>>
>>Gavin Grover
>>blog: http://groovy.codeplex.com/wikipage?title=Blog02
>> email: gvgrover-/E1597aS9LQAvxtiuMwx3w@public.gmane.org
>>
>>
>>
>>
>>----- Original Message -----
>>> From: Jochen Theodorou <blackdrag-BA+cFGlbTmA@public.gmane.org>
>>> To: user-i9PBDF1N6cxhl2p70BpVqQ@public.gmane.orgdehaus.org
>>> Cc:
>>> Sent: Tuesday, June 26, 2012 7:17 PM
>>> Subject: [groovy-user] Groovy 3
>>>
>>> Hi all,
>>>
>>> soon Groovy 2 will be released and I will start on working for Groovy 3, which
>>> is supposed to get released next year. Groovy 3 will contain a new MOP and some
>>> semantic changes. I thought I start a GEP (GEP-11) for this to make it more easy
>>> for people to contribute. I only just started the with some things I want not to
>>> have anymore in Groovy3. I will soon try to describe the new MOP. But most
>>> probably that will be in constant flux, since I will have to see if things work
>>> out right or not while I implement it.
>>>
>>> So anyone who wants something absolutely in Groovy3 regarding semantics or the
>>> new MOP.. it would be a good time to speak now... for example in this thread. I
>>> will collect the ideas on the wiki page of the GEP and possibly make them part
>>> of that "design document".
>>>
>>> Those who want some syntactic changes, sorry, they will not be part of that GEP.
>>>
>>> <at> see
>>> http://docs.codehaus.org/display/GroovyJSR/GEP+11+-+Groovy+3+semantics+and+new+MOP
>>>
>>> bye blackdrag
>>>
>>> -- Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
>>> blog: http://blackdragsview.blogspot.com/
>>> german groovy discussion newsgroup: de.comp.lang.misc
>>> For Groovy programming sources visit http://groovy-lang.org
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
>>
>
>
>
>--
>Guillaume Laforge
>Groovy Project Manager
>Head of Groovy Development at SpringSource
>http://www.springsource.com/g2one
>
>
>

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

   http://xircles.codehaus.org/manage_email





--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one
Mohamed Seifeddine | 26 Jun 2012 17:21
Picon

Re: [groovy-user] Groovy 3

Is Groovy 3 going to be backwards compatible? Have Groovy been backwards compatibile so far for each release? 

Do you consider backwards compatibility to be important? 

// Moe


On Tue, Jun 26, 2012 at 5:06 PM, Guillaume Laforge <glaforge-yCVjj/EcxBJg9hUCZPvPmw@public.gmane.org> wrote:
I'm not sure I understand the polemical you're trying to create here, as Jochen and myself are all on the same wavelength.
The MOP needs to be rewritten, if that's a clearer statement you want to hear?


On Tue, Jun 26, 2012 at 4:05 PM, Gavin Grover <gvgrover-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:
The rest of the referred thread, a discussion between Russel and Jochen, is another semantic change that some might want in GEP-11, and has everything to do with the current discussion.

I was questioning whether the discussion will amount to any action if Jochen is writing "Groovy 3 will contain a new MOP" below, but you're writing "moving Groovy forward, [...] making the MOP more efficient, saner, etc."

Gavin Grover

>________________________________
> From: Guillaume Laforge <glaforge-yCVjj/EcxBJg9hUCZPvPmw@public.gmane.org>
>To: user <at> groovy.codehaus.org
>Sent: Tuesday, June 26, 2012 9:14 PM
>Subject: Re: [groovy-user] Groovy 3
>
>
>The mail you refer to has nothing to do with the current discussion. It was about a terminology aspect, where it might be confusing for users if we tell them Groovy "closures" aren't "closures" or should change name.
>Here we speak about moving Groovy forward, fixing odd corner cases of the language and APIs, making the MOP more efficient, saner, etc.
>
>
>
>On Tue, Jun 26, 2012 at 2:56 PM, Gavin Grover <gvgrover-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:
>
>Jochen,
>>
>>will VMWare assign the budget for you to make semantic changes to Groovy and upgrade the MOP? The project management don't seem to want to change anything 
>>e.g. the reply at http://groovy.329449.n5.nabble.com/Closures-closures-and-lambda-functions-tt5573493.html#a5573628
>>
>>Gavin Grover
>>blog: http://groovy.codeplex.com/wikipage?title=Blog02
>> email: gvgrover-/E1597aS9LQAvxtiuMwx3w@public.gmane.org
>>
>>
>>
>>
>>----- Original Message -----
>>> From: Jochen Theodorou <blackdrag-BA+cFGlbTmA@public.gmane.org>
>>> To: user-i9PBDF1N6cxnkHa44VUL00B+6BGkLq7r@public.gmane.org
>>> Cc:
>>> Sent: Tuesday, June 26, 2012 7:17 PM
>>> Subject: [groovy-user] Groovy 3
>>>
>>> Hi all,
>>>
>>> soon Groovy 2 will be released and I will start on working for Groovy 3, which
>>> is supposed to get released next year. Groovy 3 will contain a new MOP and some
>>> semantic changes. I thought I start a GEP (GEP-11) for this to make it more easy
>>> for people to contribute. I only just started the with some things I want not to
>>> have anymore in Groovy3. I will soon try to describe the new MOP. But most
>>> probably that will be in constant flux, since I will have to see if things work
>>> out right or not while I implement it.
>>>
>>> So anyone who wants something absolutely in Groovy3 regarding semantics or the
>>> new MOP.. it would be a good time to speak now... for example in this thread. I
>>> will collect the ideas on the wiki page of the GEP and possibly make them part
>>> of that "design document".
>>>
>>> Those who want some syntactic changes, sorry, they will not be part of that GEP.
>>>
>>> <at> see
>>> http://docs.codehaus.org/display/GroovyJSR/GEP+11+-+Groovy+3+semantics+and+new+MOP
>>>
>>> bye blackdrag
>>>
>>> -- Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
>>> blog: http://blackdragsview.blogspot.com/
>>> german groovy discussion newsgroup: de.comp.lang.misc
>>> For Groovy programming sources visit http://groovy-lang.org
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
>>
>
>
>
>--
>Guillaume Laforge
>Groovy Project Manager
>Head of Groovy Development at SpringSource
>http://www.springsource.com/g2one
>
>
>

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

   http://xircles.codehaus.org/manage_email





--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one

Guillaume Laforge | 26 Jun 2012 17:26
Gravatar

Re: [groovy-user] Groovy 3

Hi Mohamed,


We've always tried to stay backward-compatible as much as possible, but there has been a few compatibility issues between certain versions.
Sometimes on purpose to fix issues, and a few times non desired.
But Groovy 3 will not be fully backward compatible, most probably around the usage of the runtime metaprogramming techniques, plus the various bits of semantic we want to fix (some of them already listed by Jochen on the linked page).

Guillaume

On Tue, Jun 26, 2012 at 5:21 PM, Mohamed Seifeddine <mseifeddo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
Is Groovy 3 going to be backwards compatible? Have Groovy been backwards compatibile so far for each release? 
Do you consider backwards compatibility to be important? 

// Moe


On Tue, Jun 26, 2012 at 5:06 PM, Guillaume Laforge <glaforge-yCVjj/EcxBJg9hUCZPvPmw@public.gmane.org> wrote:
I'm not sure I understand the polemical you're trying to create here, as Jochen and myself are all on the same wavelength.
The MOP needs to be rewritten, if that's a clearer statement you want to hear?


On Tue, Jun 26, 2012 at 4:05 PM, Gavin Grover <gvgrover-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:
The rest of the referred thread, a discussion between Russel and Jochen, is another semantic change that some might want in GEP-11, and has everything to do with the current discussion.

I was questioning whether the discussion will amount to any action if Jochen is writing "Groovy 3 will contain a new MOP" below, but you're writing "moving Groovy forward, [...] making the MOP more efficient, saner, etc."

Gavin Grover

>________________________________
> From: Guillaume Laforge <glaforge-yCVjj/EcxBJg9hUCZPvPmw@public.gmane.org>
>To: user <at> groovy.codehaus.org
>Sent: Tuesday, June 26, 2012 9:14 PM
>Subject: Re: [groovy-user] Groovy 3
>
>
>The mail you refer to has nothing to do with the current discussion. It was about a terminology aspect, where it might be confusing for users if we tell them Groovy "closures" aren't "closures" or should change name.
>Here we speak about moving Groovy forward, fixing odd corner cases of the language and APIs, making the MOP more efficient, saner, etc.
>
>
>
>On Tue, Jun 26, 2012 at 2:56 PM, Gavin Grover <gvgrover-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:
>
>Jochen,
>>
>>will VMWare assign the budget for you to make semantic changes to Groovy and upgrade the MOP? The project management don't seem to want to change anything 
>>e.g. the reply at http://groovy.329449.n5.nabble.com/Closures-closures-and-lambda-functions-tt5573493.html#a5573628
>>
>>Gavin Grover
>>blog: http://groovy.codeplex.com/wikipage?title=Blog02
>> email: gvgrover-/E1597aS9LQAvxtiuMwx3w@public.gmane.org
>>
>>
>>
>>
>>----- Original Message -----
>>> From: Jochen Theodorou <blackdrag-BA+cFGlbTmA@public.gmane.org>
>>> To: user-i9PBDF1N6cxnkHa44VUL00B+6BGkLq7r@public.gmane.org
>>> Cc:
>>> Sent: Tuesday, June 26, 2012 7:17 PM
>>> Subject: [groovy-user] Groovy 3
>>>
>>> Hi all,
>>>
>>> soon Groovy 2 will be released and I will start on working for Groovy 3, which
>>> is supposed to get released next year. Groovy 3 will contain a new MOP and some
>>> semantic changes. I thought I start a GEP (GEP-11) for this to make it more easy
>>> for people to contribute. I only just started the with some things I want not to
>>> have anymore in Groovy3. I will soon try to describe the new MOP. But most
>>> probably that will be in constant flux, since I will have to see if things work
>>> out right or not while I implement it.
>>>
>>> So anyone who wants something absolutely in Groovy3 regarding semantics or the
>>> new MOP.. it would be a good time to speak now... for example in this thread. I
>>> will collect the ideas on the wiki page of the GEP and possibly make them part
>>> of that "design document".
>>>
>>> Those who want some syntactic changes, sorry, they will not be part of that GEP.
>>>
>>> <at> see
>>> http://docs.codehaus.org/display/GroovyJSR/GEP+11+-+Groovy+3+semantics+and+new+MOP
>>>
>>> bye blackdrag
>>>
>>> -- Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
>>> blog: http://blackdragsview.blogspot.com/
>>> german groovy discussion newsgroup: de.comp.lang.misc
>>> For Groovy programming sources visit http://groovy-lang.org
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
>>
>
>
>
>--
>Guillaume Laforge
>Groovy Project Manager
>Head of Groovy Development at SpringSource
>http://www.springsource.com/g2one
>
>
>

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

   http://xircles.codehaus.org/manage_email





--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one




--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one
Wujek Srujek | 26 Jun 2012 18:35
Picon

Re: [groovy-user] Groovy 3

1. I found this part really confusing once, and it stole me a lot of time:


class Foo {
    Foo(whatever) {
        println "whatever is: $whatever" 
    }
}

new Foo() // prints 'whatever is: null'

I think the call should simply fail. This has something to do with another constructor being generated, that takes a map, which is empty, or maybe with the automatic method call with nulls that Jochen already mentioned on the page? All in all, I would like this one to be fixed.

2. I would really like real named parameters, not a Map. This can be achieved (the JVM doesn't support it) by changing this:
def method(a, b, c) { ... }
into
def method( <at> Param('a') a, <at> Param('b') b, <at> Param('c') c) { ... }
with <at> Param being a runtime-retained annotation. This information is then available during runtime, so a call:
method(c=1, b=2, a=3)
would trigger lookup of parameter names and call the method correctly. I believe scala / ceylon do it this way, maybe others as well. You could also add default values:
def method(a=1+2+3) { ... }
which ends up being:
def method( <at> Param('a', defVal=Param_a_value.class) a) { ... }

where the expression gets compiled into a class, that ges saved, and executed upon execution. The defVal must be a class now, as JVM only expects constants as annotation values, I guess, but that should work. Upon a call that doesn't define the parameter, the default value class is looked up and executed, to complement the arguments.
This is just a rough idea, which surely is not ripe and there are edge cases, but this seems doable (again, I think ceylon has the possibility to execute ordinary code for parameters).

3. I don't know if you already include that or not, but the fact that GroovyObject has getProperty and invokeMethod, but not propertyMissing and methodMissng (which are then magically used in MetaClassImpl, I think) is pure inconsistency. They should be defined by the same means. Unless you just want to get rid of this stuff ;d and the MOP change is all about that.

4. I would like to be able to use a category that I instantiate myself:

use(new MyCategory('with arguments')) {
    //
}

My use case was that the category would get some arguments that I had dependency-injected into the class that had the above code. It would have made my design simpler in a few cases.


BTW, I would like to use the occasion and thank you guys for the tremendous job your are doing on implementig, supporting and pushing Groovy forward. It has become my favorite language for the JVM, I can't imagine not having it to employ it here or there for specific tasks I must do, especially DSL implementation. I also really like gradle ;d which exists thanks to Groovy.

wujek

On Tue, Jun 26, 2012 at 5:26 PM, Guillaume Laforge <glaforge-yCVjj/EcxBJg9hUCZPvPmw@public.gmane.org> wrote:
Hi Mohamed,

We've always tried to stay backward-compatible as much as possible, but there has been a few compatibility issues between certain versions.
Sometimes on purpose to fix issues, and a few times non desired.
But Groovy 3 will not be fully backward compatible, most probably around the usage of the runtime metaprogramming techniques, plus the various bits of semantic we want to fix (some of them already listed by Jochen on the linked page).

Guillaume


On Tue, Jun 26, 2012 at 5:21 PM, Mohamed Seifeddine <mseifeddo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
Is Groovy 3 going to be backwards compatible? Have Groovy been backwards compatibile so far for each release? 
Do you consider backwards compatibility to be important? 

// Moe


On Tue, Jun 26, 2012 at 5:06 PM, Guillaume Laforge <glaforge-yCVjj/EcxBJg9hUCZPvPmw@public.gmane.org> wrote:
I'm not sure I understand the polemical you're trying to create here, as Jochen and myself are all on the same wavelength.
The MOP needs to be rewritten, if that's a clearer statement you want to hear?


On Tue, Jun 26, 2012 at 4:05 PM, Gavin Grover <gvgrover-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:
The rest of the referred thread, a discussion between Russel and Jochen, is another semantic change that some might want in GEP-11, and has everything to do with the current discussion.

I was questioning whether the discussion will amount to any action if Jochen is writing "Groovy 3 will contain a new MOP" below, but you're writing "moving Groovy forward, [...] making the MOP more efficient, saner, etc."

Gavin Grover

>________________________________
> From: Guillaume Laforge <glaforge-yCVjj/EcxBJg9hUCZPvPmw@public.gmane.org>
>To: user <at> groovy.codehaus.org
>Sent: Tuesday, June 26, 2012 9:14 PM
>Subject: Re: [groovy-user] Groovy 3
>
>
>The mail you refer to has nothing to do with the current discussion. It was about a terminology aspect, where it might be confusing for users if we tell them Groovy "closures" aren't "closures" or should change name.
>Here we speak about moving Groovy forward, fixing odd corner cases of the language and APIs, making the MOP more efficient, saner, etc.
>
>
>
>On Tue, Jun 26, 2012 at 2:56 PM, Gavin Grover <gvgrover-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:
>
>Jochen,
>>
>>will VMWare assign the budget for you to make semantic changes to Groovy and upgrade the MOP? The project management don't seem to want to change anything 
>>e.g. the reply at http://groovy.329449.n5.nabble.com/Closures-closures-and-lambda-functions-tt5573493.html#a5573628
>>
>>Gavin Grover
>>blog: http://groovy.codeplex.com/wikipage?title=Blog02
>> email: gvgrover-/E1597aS9LQAvxtiuMwx3w@public.gmane.org
>>
>>
>>
>>
>>----- Original Message -----
>>> From: Jochen Theodorou <blackdrag-BA+cFGlbTmA@public.gmane.org>
>>> To: user-i9PBDF1N6cxnkHa44VUL00B+6BGkLq7r@public.gmane.org
>>> Cc:
>>> Sent: Tuesday, June 26, 2012 7:17 PM
>>> Subject: [groovy-user] Groovy 3
>>>
>>> Hi all,
>>>
>>> soon Groovy 2 will be released and I will start on working for Groovy 3, which
>>> is supposed to get released next year. Groovy 3 will contain a new MOP and some
>>> semantic changes. I thought I start a GEP (GEP-11) for this to make it more easy
>>> for people to contribute. I only just started the with some things I want not to
>>> have anymore in Groovy3. I will soon try to describe the new MOP. But most
>>> probably that will be in constant flux, since I will have to see if things work
>>> out right or not while I implement it.
>>>
>>> So anyone who wants something absolutely in Groovy3 regarding semantics or the
>>> new MOP.. it would be a good time to speak now... for example in this thread. I
>>> will collect the ideas on the wiki page of the GEP and possibly make them part
>>> of that "design document".
>>>
>>> Those who want some syntactic changes, sorry, they will not be part of that GEP.
>>>
>>> <at> see
>>> http://docs.codehaus.org/display/GroovyJSR/GEP+11+-+Groovy+3+semantics+and+new+MOP
>>>
>>> bye blackdrag
>>>
>>> -- Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
>>> blog: http://blackdragsview.blogspot.com/
>>> german groovy discussion newsgroup: de.comp.lang.misc
>>> For Groovy programming sources visit http://groovy-lang.org
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
>>
>
>
>
>--
>Guillaume Laforge
>Groovy Project Manager
>Head of Groovy Development at SpringSource
>http://www.springsource.com/g2one
>
>
>

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

   http://xircles.codehaus.org/manage_email





--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one




--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one

Jochen Theodorou | 26 Jun 2012 19:11
Picon
Gravatar

Re: [groovy-user] Groovy 3

Am 26.06.2012 18:35, schrieb Wujek Srujek:
> 1. I found this part really confusing once, and it stole me a lot of time:
>
> class Foo {
>      Foo(whatever) {
>          println "whatever is: $whatever"
>      }
> }
>
> new Foo() // prints 'whatever is: null'

hehe, yes, I think it is point 1 of the things to be changed and removed 
in Groovy 3 in the linked wiki page ;)

[...]
> 2. I would really like real named parameters, not a Map. This can be
> achieved (the JVM doesn't support it) by changing this:
> def method(a, b, c) { ... }
> into
> def method( <at> Param('a') a,  <at> Param('b') b,  <at> Param('c') c) { ... }
> with  <at> Param being a runtime-retained annotation. This information is
> then available during runtime, so a call:
> method(c=1, b=2, a=3)
> would trigger lookup of parameter names and call the method correctly. I
> believe scala / ceylon do it this way, maybe others as well. You could
> also add default values:
> def method(a=1+2+3) { ... }
> which ends up being:
> def method( <at> Param('a', defVal=Param_a_value.class) a) { ... }
>
> where the expression gets compiled into a class, that ges saved, and
> executed upon execution. The defVal must be a class now, as JVM only
> expects constants as annotation values, I guess, but that should work.
> Upon a call that doesn't define the parameter, the default value class
> is looked up and executed, to complement the arguments.
> This is just a rough idea, which surely is not ripe and there are edge
> cases, but this seems doable (again, I think ceylon has the possibility
> to execute ordinary code for parameters).

I see overlap with http://jira.codehaus.org/browse/GROOVY-3520 here... 
And you would scrap the old optional parameters logic for that? I dare 
you to make a GEP for this ;)
Surely overriding methods would get more difficult and the user 
experience from Java would get lower.

> 3. I don't know if you already include that or not, but the fact that
> GroovyObject has getProperty and invokeMethod, but not propertyMissing
-Ä''''''> and methodMissng (which are then magically used in 
MetaClassImpl, I
> think) is pure inconsistency. They should be defined by the same means.
> Unless you just want to get rid of this stuff ;d and the MOP change is
> all about that.

Not all about that, but yes, I am thinking of getting rid of this stuff.

> 4. I would like to be able to use a category that I instantiate myself:
>
> use(new MyCategory('with arguments')) {
>      //
> }

you mean a category that operates on an instance?

> My use case was that the category would get some arguments that I had
> dependency-injected into the class that had the above code. It would
> have made my design simpler in a few cases.

and how far should the change minimally reach for your use case? only 
the block or beyond?

> BTW, I would like to use the occasion and thank you guys for the
> tremendous job your are doing on implementig, supporting and pushing
> Groovy forward. It has become my favorite language for the JVM, I can't
> imagine not having it to employ it here or there for specific tasks I
> must do, especially DSL implementation. I also really like gradle ;d
> which exists thanks to Groovy.

thanks, good to hear ;)

bye blackdrag

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

    http://xircles.codehaus.org/manage_email

Wujek Srujek | 26 Jun 2012 20:01
Picon

Re: [groovy-user] Groovy 3


2. I would really like real named parameters, not a Map. This can be
achieved (the JVM doesn't support it) by changing this:
def method(a, b, c) { ... }
into
def method( <at> Param('a') a, <at> Param('b') b, <at> Param('c') c) { ... }
with <at> Param being a runtime-retained annotation. This information is
then available during runtime, so a call:
method(c=1, b=2, a=3)
would trigger lookup of parameter names and call the method correctly. I
believe scala / ceylon do it this way, maybe others as well. You could
also add default values:
def method(a=1+2+3) { ... }
which ends up being:
def method( <at> Param('a', defVal=Param_a_value.class) a) { ... }

where the expression gets compiled into a class, that ges saved, and
executed upon execution. The defVal must be a class now, as JVM only
expects constants as annotation values, I guess, but that should work.
Upon a call that doesn't define the parameter, the default value class
is looked up and executed, to complement the arguments.
This is just a rough idea, which surely is not ripe and there are edge
cases, but this seems doable (again, I think ceylon has the possibility
to execute ordinary code for parameters).

I see overlap with http://jira.codehaus.org/browse/GROOVY-3520 here... And you would scrap the old optional parameters logic for that? I dare you to make a GEP for this ;)
Surely overriding methods would get more difficult and the user experience from Java would get lower.

I am not sure, the issue still mangles Mas.
Why do you think this would make overriding more difficult, and Java interop worse? I think that calling Java methods from Groovy just has to use positional parameters (I don't think I can succesfully use the Map workaround that exists now? the java method would need to take a Map, and I don't know if it would work anyways, just like POJO setProperty doesn't work). What about overriding? When a method is overridden, you generate its own <at> Params and value classes, not overridden methods use the old ones. The problem might arise when you override and change the param names, and don't know the runtime type (have a reference to the superclass but actually a subclass is used), which is one of the edge cases I mentioned (but scala / ceylon do manage to get it working) - there could be a restriction that you can't change the names or sth, but this seems stupid.
 

4. I would like to be able to use a category that I instantiate myself:

use(new MyCategory('with arguments')) {
    //
}

you mean a category that operates on an instance?

Yes. The added methods are instance methods (not static) that take self as the first argument. My use case: we had a DSL that could evaluate 'paths' against objects via Unified EL (pimped a lot and extended). The type of the object doesn't matter as long as there are correct resolvers (that's the standard way in EL, which is a standard part of Java EE). We had a Java engine that takes a path, the root, and returns value(s). I wanted to have it so I can take the instance that I get into the script (I don't know the type, neither do I need to, as far as I know it's just 'something'), and call a method on it, which uses the engine inside. Normally, in Java, you use the engine like this:
engine.evaluate(root, 'some.path')
In groovy I wanted:
root.'some.path'
where I use methodMissing for the 'some.path' part. I did it with messing around with the metaClass, but that adds the methods for ever (for the current groovy), whereas after the evaluation (like further in the process) I would like the method to disappear and not leave trace. As far as I know, there is no clear way to remove a method from a metaClass, you can only set it to something else (like sth that throws an exception), but that's not clean, imho. BTW, maybe this could be in the new MOP as well?
The engine gets passed to the groovy process as a script binding, as it is a pretty expensive thing to create. I want / need to use our DI framework (CDI) for that. It all works beautifully except for the metaClass part.

To sum up: I would like to be able to apply a category (maybe something new?) to a block of code, and I would like to be able to initialize it somehow myself with dependencies, not rely on static methods / state, and that I can use to add methodMissing to classes.


My use case was that the category would get some arguments that I had
dependency-injected into the class that had the above code. It would
have made my design simpler in a few cases.

and how far should the change minimally reach for your use case? only the block or beyond?

The block. The code that is inside (which might be a call to GroovyScriptEngine recursively, as the scripts might call evaluate() and others) or deeply nested methods should see the changes. Mind that such use blocks might be called by multiple threads, so static state is not really an option (unless you mess around with ThreadLocals...).

wujek
Bob Brown | 27 Jun 2012 00:50
Picon
Favicon

RE: [groovy-user] Groovy 3

My bugbears:

1. I'd like to see a version of Ruby's case statement:

def manufacturer = match(car) {
  when "Focus",     "Ford"
  when "Navigator", "Lincoln"
  when "Camry",     "Toyota"
  when "Civic",     "Honda"
  when "Patriot",   "Jeep"
  when "Jetta",     "VW"
  when "Ceyene",    "Porsche"
  when "Outback",   "Subaru"
  when "520i",      "BMW"
  when "Tundra",    "Nissan"
  otherwise         "Unknown"
}

This construct is incredibly useful (converting to/from database-y stuff,
for example). I probably need it once a day (and I DO know about the various
facilities provided in enums).

I remember having a nice discussion about this with Guillame Laforge and
subsequently wrote this up (there's more):
http://wordpress.transentia.com.au/wordpress/2009/03/11/inventing-a-new-stat
ement-for-groovy-in-10-minutes/.

I also recall having a discussion with Paul King about this....trying to
create an AST transform, but we couldn't quite get there. It needs to be in
the language.

2. I'd like to:

println "An error occurred on ${__LINE__} of ${__FILE__}"

3. I'd like a facility analogous to bash's xtrace option:

bash -x command.sh

These latter two hark back to the idea of "Groovy as scripting tool", rather
than "Groovy as programming language" and are more pie-in-the sky and MUCH
harder to do for Groovy than for bash, of course. But you guys DID ask ;-)

Cheers.

BOB

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

    http://xircles.codehaus.org/manage_email

Bob Brown | 27 Jun 2012 00:59
Picon
Favicon

RE: [groovy-user] Groovy 3

With respect to the cumbersome nature of:

println a?.b?.c?.e?.f

I dimly recall another discussion around this a while back. I seem to
remember people considering:

println a??.b.c.d.e.f

as a useful shortcut syntax.

The compiler would generate something like:

def tmp = a
tmp = tmp ? tmp.a : null
tmp = tmp ? tmp.b : null
tmp = tmp ? tmp.c : null
tmp = tmp ? tmp.d : null
tmp = tmp ? tmp.e : null
if (tmp) tmp =tmp.f

Can't find anything to support my lousy memory, though...

Cheers,

Bob

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

    http://xircles.codehaus.org/manage_email

Jochen Theodorou | 27 Jun 2012 08:34
Picon
Gravatar

Re: [groovy-user] Groovy 3

Am 27.06.2012 00:59, schrieb Bob Brown:
[...]
> println a??.b.c.d.e.f
>
> as a useful shortcut syntax.
>
> The compiler would generate something like:
>
> def tmp = a
> tmp = tmp ? tmp.a : null
> tmp = tmp ? tmp.b : null
> tmp = tmp ? tmp.c : null
> tmp = tmp ? tmp.d : null
> tmp = tmp ? tmp.e : null
> if (tmp) tmp =tmp.f
>
> Can't find anything to support my lousy memory, though...

As a syntax change, this is beyond GEP-11

bye blackdrag

--

-- 
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org

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

    http://xircles.codehaus.org/manage_email

Wujek Srujek | 27 Jun 2012 07:35
Picon

Re: [groovy-user] Groovy 3



On Wed, Jun 27, 2012 at 12:50 AM, Bob Brown <bob-KiwF19kzwtgVDcw6SFq9D4dd74u8MsAO@public.gmane.org> wrote:
My bugbears:

1. I'd like to see a version of Ruby's case statement:

def manufacturer = match(car) {
 when "Focus",     "Ford"
 when "Navigator", "Lincoln"
 when "Camry",     "Toyota"
 when "Civic",     "Honda"
 when "Patriot",   "Jeep"
 when "Jetta",     "VW"
 when "Ceyene",    "Porsche"
 when "Outback",   "Subaru"
 when "520i",      "BMW"
 when "Tundra",    "Nissan"
 otherwise         "Unknown"
}

What do you need here that you can't do with Groovy switch?

wujek
Bob Brown | 27 Jun 2012 08:03
Picon
Favicon

RE: [groovy-user] Groovy 3

This is the discussion I had before...

One CAN do it all with a switch. It's more cumbersome but it can be done. 

Of course.

And I discussed this/how at the link I gave before...

Here's a tiny bit of 'real' code from a project:

  private textColor(s) {
    match(s)
      case CUSTOMER: return "#00FF00"; break;
      case SYSTEM: return "#FF0000"; break;
      case ADMIN: return "#0000FF"; break;
    }
  }

To me, the following expresses what I need much more cleanly:

  private textColor(s) {
    match (s) {
      when CUSTOMER,  "#00FF00"
      when SYSTEM, "#FF0000"
      when ADMIN, "#0000FF"
    }
  }

Now: a 'switch' isn't 'necessary' because we have an 'if' statement, and a
safe navigator operator isn't required because an 'if' will "do the job",
and a 'while' isn't needed if you have a 'for' loop, etc.

I think the point isn't necessity, but lack of ceremony/ease of use/fun call
it what you will.

I recall a previous colleague dismissing C because he could do it all in
BCPL ;-)

I am also thinking of a "South Park" episode: "simpsons already did it"
(http://en.wikipedia.org/wiki/Simpsons_Already_Did_It) in this case "ruby
already did it", although you may feel that this is not good enough reason.

Cheers,

BOB
> -----Original Message-----
> From: Wujek Srujek [mailto:wujek.srujek@...]
> Sent: Wednesday, 27 June 2012 3:35 PM
> To: user@...
> Subject: Re: [groovy-user] Groovy 3
> 
> 
> 
> On Wed, Jun 27, 2012 at 12:50 AM, Bob Brown <bob@...>
> wrote:
> 
> 
> 	My bugbears:
> 
> 	1. I'd like to see a version of Ruby's case statement:
> 
> 	def manufacturer = match(car) {
> 	 when "Focus",     "Ford"
> 	 when "Navigator", "Lincoln"
> 	 when "Camry",     "Toyota"
> 	 when "Civic",     "Honda"
> 	 when "Patriot",   "Jeep"
> 	 when "Jetta",     "VW"
> 	 when "Ceyene",    "Porsche"
> 	 when "Outback",   "Subaru"
> 	 when "520i",      "BMW"
> 	 when "Tundra",    "Nissan"
> 	 otherwise         "Unknown"
> 	}
> 
> 
> 
> What do you need here that you can't do with Groovy switch?
> 
> wujek

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

    http://xircles.codehaus.org/manage_email

Peter Niederwieser | 27 Jun 2012 15:32
Picon
Gravatar

[groovy-user] RE: Groovy 3


Bob Brown wrote
> 
> Here's a tiny bit of 'real' code from a project:
> 
>   private textColor(s) {
>     match(s)
>       case CUSTOMER: return "#00FF00"; break;
>       case SYSTEM: return "#FF0000"; break;
>       case ADMIN: return "#0000FF"; break;
>     }
>   }
> 

It's "switch", not "match". The "break"s are unnecessary, both in Groovy and
in Java. Adding a totally different switch syntax because it may read a bit
nicer (but departs from Java) is not a good way to evolve a language.

Cheers,
Peter

--
View this message in context: http://groovy.329449.n5.nabble.com/Groovy-3-tp5710334p5710386.html
Sent from the groovy - user mailing list archive at Nabble.com.

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

    http://xircles.codehaus.org/manage_email

Paul Wilson | 27 Jun 2012 15:37
Picon

Re: [groovy-user] RE: Groovy 3

Doesn't groovy allow something like this:

private textColor(s) {
     [CUSTOMER: '#00FF00',
      SYSTEM:      '#FF0000',
      ADMIN:         '#0000FF'].get(s)
}

anyway??

On 27 June 2012 14:32, Peter Niederwieser <pniederw@...> wrote:
>
>
> Bob Brown wrote
> >
> > Here's a tiny bit of 'real' code from a project:
> >
> >   private textColor(s) {
> >     match(s)
> >       case CUSTOMER: return "#00FF00"; break;
> >       case SYSTEM: return "#FF0000"; break;
> >       case ADMIN: return "#0000FF"; break;
> >     }
> >   }
> >
>
> It's "switch", not "match". The "break"s are unnecessary, both in Groovy and
> in Java. Adding a totally different switch syntax because it may read a bit
> nicer (but departs from Java) is not a good way to evolve a language.
>
> Cheers,
> Peter
>
>
> --
> View this message in context: http://groovy.329449.n5.nabble.com/Groovy-3-tp5710334p5710386.html
> Sent from the groovy - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> 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

Steven Guitar | 27 Jun 2012 15:43
Picon
Gravatar

Re: [groovy-user] RE: Groovy 3

Yes, that however is map based.

On Jun 27, 2012, at 9:38 AM, Paul Wilson <paulalexwilson@...> wrote:

> Doesn't groovy allow something like this:
>
> private textColor(s) {
>      [CUSTOMER: '#00FF00',
>       SYSTEM:      '#FF0000',
>       ADMIN:         '#0000FF'].get(s)
> }
>
> anyway??
>
> On 27 June 2012 14:32, Peter Niederwieser <pniederw@...> wrote:
>>
>>
>> Bob Brown wrote
>>>
>>> Here's a tiny bit of 'real' code from a project:
>>>
>>>   private textColor(s) {
>>>     match(s)
>>>       case CUSTOMER: return "#00FF00"; break;
>>>       case SYSTEM: return "#FF0000"; break;
>>>       case ADMIN: return "#0000FF"; break;
>>>     }
>>>   }
>>>
>>
>> It's "switch", not "match". The "break"s are unnecessary, both in Groovy and
>> in Java. Adding a totally different switch syntax because it may read a bit
>> nicer (but departs from Java) is not a good way to evolve a language.
>>
>> Cheers,
>> Peter
>>
>>
>> --
>> View this message in context: http://groovy.329449.n5.nabble.com/Groovy-3-tp5710334p5710386.html
>> Sent from the groovy - user mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> 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

Jochen Theodorou | 27 Jun 2012 17:33
Picon
Gravatar

Re: [groovy-user] RE: Groovy 3

Am 27.06.2012 15:43, schrieb Steven Guitar:
> Yes, that however is map based.

sure, but is the problem of that?

bye blackdrag

--

-- 
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org

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

    http://xircles.codehaus.org/manage_email

Steven Guitar | 27 Jun 2012 17:41
Picon
Gravatar

Re: [groovy-user] RE: Groovy 3

No, not to me. Sorry if it sounded like that. I was just pointing out
how the code would be interpreted by the JVM or what have you.

Sent from my iPhone

On Jun 27, 2012, at 11:34 AM, Jochen Theodorou <blackdrag@...> wrote:

> Am 27.06.2012 15:43, schrieb Steven Guitar:
>> Yes, that however is map based.
>
> sure, but is the problem of that?
>
> bye blackdrag
>
> --
> Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
> blog: http://blackdragsview.blogspot.com/
> german groovy discussion newsgroup: de.comp.lang.misc
> For Groovy programming sources visit http://groovy-lang.org
>
>
>
>
> ---------------------------------------------------------------------
> 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

Wilson MacGyver | 27 Jun 2012 15:54
Picon

Re: [groovy-user] RE: Groovy 3

Couldn't agree more. Groovy is groovy, not ruby/language X. Adding different keywords so it look more like
language X isn't a good way forward in my opinion

On Jun 27, 2012, at 9:32 AM, Peter Niederwieser <pniederw@...> wrote:

> 
> Bob Brown wrote
>> 
>> Here's a tiny bit of 'real' code from a project:
>> 
>>  private textColor(s) {
>>    match(s)
>>      case CUSTOMER: return "#00FF00"; break;
>>      case SYSTEM: return "#FF0000"; break;
>>      case ADMIN: return "#0000FF"; break;
>>    }
>>  }
>> 
> 
> It's "switch", not "match". The "break"s are unnecessary, both in Groovy and
> in Java. Adding a totally different switch syntax because it may read a bit
> nicer (but departs from Java) is not a good way to evolve a language.
> 
> Cheers,
> Peter
> 
> 
> --
> View this message in context: http://groovy.329449.n5.nabble.com/Groovy-3-tp5710334p5710386.html
> Sent from the groovy - user mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> 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

Jochen Theodorou | 27 Jun 2012 08:46
Picon
Gravatar

Re: [groovy-user] Groovy 3

Am 27.06.2012 00:50, schrieb Bob Brown:
> My bugbears:
>
> 1. I'd like to see a version of Ruby's case statement:
>
> def manufacturer = match(car) {
>    when "Focus",     "Ford"
>    when "Navigator", "Lincoln"
>    when "Camry",     "Toyota"
>    when "Civic",     "Honda"
>    when "Patriot",   "Jeep"
>    when "Jetta",     "VW"
>    when "Ceyene",    "Porsche"
>    when "Outback",   "Subaru"
>    when "520i",      "BMW"
>    when "Tundra",    "Nissan"
>    otherwise         "Unknown"
> }
>
> This construct is incredibly useful (converting to/from database-y stuff,
> for example). I probably need it once a day (and I DO know about the various
> facilities provided in enums).

I normally use maps for this kind of logic.

> I remember having a nice discussion about this with Guillame Laforge and
> subsequently wrote this up (there's more):
> http://wordpress.transentia.com.au/wordpress/2009/03/11/inventing-a-new-stat
> ement-for-groovy-in-10-minutes/.
>
> I also recall having a discussion with Paul King about this....trying to
> create an AST transform, but we couldn't quite get there. It needs to be in
> the language.

yes? What was the problem? Probably that switch is a statement and thus 
cannot stay on the right side. But with command expressions the above 
seems to be possible

> 2. I'd like to:
>
> println "An error occurred on ${__LINE__} of ${__FILE__}"

ah... yes... actually that should not be too difficult for normal cases. 
The problem is what we give here for stuff that has no file, like 
scripts from strings and runtime created scripts. They can still have a 
line, but a file would be then... what?

> 3. I'd like a facility analogous to bash's xtrace option:
>
> bash -x command.sh
>
> These latter two hark back to the idea of "Groovy as scripting tool", rather
> than "Groovy as programming language" and are more pie-in-the sky and MUCH
> harder to do for Groovy than for bash, of course. But you guys DID ask ;-)

Really difficult is only this last one here. With an pure interpreter it 
is easy, it can just print out the text it is going to interpret. But in 
Groovy we work on the AST and compile bytecode from that. What a 
transform produces may not have anything to do with something you can 
understand in Groovy. What we would have to do in the end is to store 
somehow the "source" in the bytecode, not only multiplying the size, but 
also having a useless information for most cases.

If we now say it is enough to have this feature for not precompiled 
code, then a transform could do it actually.

bye blackdrag

--

-- 
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org

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

    http://xircles.codehaus.org/manage_email

Jochen Theodorou | 27 Jun 2012 08:30
Picon
Gravatar

Re: [groovy-user] Groovy 3

Am 26.06.2012 20:01, schrieb Wujek Srujek:
[...]
> Why do you think this would make overriding more difficult, and Java
> interop worse?

currently if you do

def foo(int a=1, long b=2)

we create the methods

foo(int,long)
foo(int)
foo()

there is a strict right to left rule for this and you cannot have 
foo(long) this way. We do it like this to avoid type problems since a 
method signatrue can appear only once.

With optional arguments like I think you described there would be only 
one method. So the optional nature is not available from Java directly. 
That's why less interop. Also if you then write in a subclass for 
example foo(long), does it override foo(int a=1, long b=2) in some cases 
or not? That's why more difficult... in this more difficult for the 
compiler and the human.

> I think that calling Java methods from Groovy just has to
> use positional parameters (I don't think I can succesfully use the Map
> workaround that exists now? the java method would need to take a Map,
> and I don't know if it would work anyways, just like POJO setProperty
> doesn't work).

Of course that works. But interoperability means in Groovy we have to 
include the Java world. That means we have to additionally look at the 
usage from Java as well as what happens if we subclass in Java and use 
from Groovy. and there is such a subclassing problem with only named 
arguments as well here... Assume:

class X {
   def foo(int a, int b){}
}
....
def x = getInstanceFromSomewhere()
x.foo(b=1,a=2)

and assume the getInstanceFromSomewhere() does not return an X, but an Y 
extends X, written in Java, thus without named parameters. That means 
this call x.foo above would work only if the returned Object is an X, as 
soon as it is an Y it will not work anymore.

[...]
> To sum up: I would like to be able to apply a category (maybe something
> new?) to a block of code, and I would like to be able to initialize it
> somehow myself with dependencies, not rely on static methods / state,
> and that I can use to add methodMissing to classes.
>
>
>         My use case was that the category would get some arguments that
>         I had
>         dependency-injected into the class that had the above code. It would
>         have made my design simpler in a few cases.
>
>
>     and how far should the change minimally reach for your use case?
>     only the block or beyond?
>
>
> The block. The code that is inside (which might be a call to
> GroovyScriptEngine recursively, as the scripts might call evaluate() and
> others) or deeply nested methods should see the changes. Mind that such
> use blocks might be called by multiple threads, so static state is not
> really an option (unless you mess around with ThreadLocals...).

categories currently are ThreadLocal changes, visible along the stack. 
This has been a problem in the past, because of the way we checked our 
callsites for validity. But now I know how to prevent this. So the only 
thing that is going to be slower is the method selection part and 
entering the block. Imho it should not really be a problem to use an 
instance here

bye blackdrag

--

-- 
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org

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

    http://xircles.codehaus.org/manage_email

Wujek Srujek | 27 Jun 2012 09:42
Picon

Re: [groovy-user] Groovy 3



On Wed, Jun 27, 2012 at 8:30 AM, Jochen Theodorou <blackdrag-BA+cFGlbTmA@public.gmane.org> wrote:
Am 26.06.2012 20:01, schrieb Wujek Srujek:
[...]

Why do you think this would make overriding more difficult, and Java
interop worse?

currently if you do

def foo(int a=1, long b=2)

we create the methods

foo(int,long)
foo(int)
foo()

there is a strict right to left rule for this and you cannot have foo(long) this way. We do it like this to avoid type problems since a method signatrue can appear only once.

With optional arguments like I think you described there would be only one method. So the optional nature is not available from Java directly. That's why less interop. Also if you then write in a subclass for example foo(long), does it override foo(int a=1, long b=2) in some cases or not? That's why more difficult... in this more difficult for the compiler and the human.


I think that calling Java methods from Groovy just has to
use positional parameters (I don't think I can succesfully use the Map
workaround that exists now? the java method would need to take a Map,
and I don't know if it would work anyways, just like POJO setProperty
doesn't work).

Of course that works.

Ok, I didn't know that you compile so many methods for all the possible combinations. All the better, imho. I was just talking about the case where in groovy you have:
def method(Map map) { ... }
and you precompile it and try to call it from Java:
method(1, 2)
or whatever. An explicit map would work, though.
 
But interoperability means in Groovy we have to include the Java world. That means we have to additionally look at the usage from Java as well as what happens if we subclass in Java and use from Groovy.

Yes! I don't want to loose the interop, my proposal was just to maybe trigger interested people (versed in compilers and groovy internals) to look into this. Because the Map workaround is really just it, a workaround. The problem is also that I have to check if the required are there in every method, iterating over the map, or just assume they are there and explode when not (this is actually the pythonic way of things, but python parameter passing is much better imho, but they don't have to worry about interop...). If the check were automatic, it would be one pita less for me. Not sure if this can be done.

and there is such a subclassing problem with only named arguments as well here... Assume:

class X {
 def foo(int a, int b){}
}
....
def x = getInstanceFromSomewhere()
x.foo(b=1,a=2)

and assume the getInstanceFromSomewhere() does not return an X, but an Y extends X, written in Java, thus without named parameters. That means this call x.foo above would work only if the returned Object is an X, as soon as it is an Y it will not work anymore.

You are right, of course. However, maybe it is worth looking what others are doing in this regard? They did make it work, but then again, maybe Java interop is not as great as in Groovy. 
I also think that I mixed and matched Map arguments with default arguments, and you treat those cases separately (which is correct ;d). My main pain is the catch-it-all Map.

[...]

To sum up: I would like to be able to apply a category (maybe something
new?) to a block of code, and I would like to be able to initialize it
somehow myself with dependencies, not rely on static methods / state,
and that I can use to add methodMissing to classes.


       My use case was that the category would get some arguments that
       I had
       dependency-injected into the class that had the above code. It would
       have made my design simpler in a few cases.


   and how far should the change minimally reach for your use case?
   only the block or beyond?


The block. The code that is inside (which might be a call to
GroovyScriptEngine recursively, as the scripts might call evaluate() and
others) or deeply nested methods should see the changes. Mind that such
use blocks might be called by multiple threads, so static state is not
really an option (unless you mess around with ThreadLocals...).

categories currently are ThreadLocal changes, visible along the stack. This has been a problem in the past, because of the way we checked our callsites for validity. But now I know how to prevent this. So the only thing that is going to be slower is the method selection part and entering the block. Imho it should not really be a problem to use an instance here

Great to hear!

wujek 
Tim Yates | 27 Jun 2012 10:21
Picon
Gravatar

Re: [groovy-user] Groovy 3

I put together a quick meta-programming version of the Ruby Match thing:



Obviously, inclusion into Groovy would mean you get proper parse errors when you've (for example) used a comma in the list variant at the bottom

On 27 June 2012 08:42, Wujek Srujek <wujek.srujek-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:


On Wed, Jun 27, 2012 at 8:30 AM, Jochen Theodorou <blackdrag-BA+cFGlbTmA@public.gmane.org> wrote:
Am 26.06.2012 20:01, schrieb Wujek Srujek:
[...]

Why do you think this would make overriding more difficult, and Java
interop worse?

currently if you do

def foo(int a=1, long b=2)

we create the methods

foo(int,long)
foo(int)
foo()

there is a strict right to left rule for this and you cannot have foo(long) this way. We do it like this to avoid type problems since a method signatrue can appear only once.

With optional arguments like I think you described there would be only one method. So the optional nature is not available from Java directly. That's why less interop. Also if you then write in a subclass for example foo(long), does it override foo(int a=1, long b=2) in some cases or not? That's why more difficult... in this more difficult for the compiler and the human.


I think that calling Java methods from Groovy just has to
use positional parameters (I don't think I can succesfully use the Map
workaround that exists now? the java method would need to take a Map,
and I don't know if it would work anyways, just like POJO setProperty
doesn't work).

Of course that works.

Ok, I didn't know that you compile so many methods for all the possible combinations. All the better, imho. I was just talking about the case where in groovy you have:
def method(Map map) { ... }
and you precompile it and try to call it from Java:
method(1, 2)
or whatever. An explicit map would work, though.
 
But interoperability means in Groovy we have to include the Java world. That means we have to additionally look at the usage from Java as well as what happens if we subclass in Java and use from Groovy.

Yes! I don't want to loose the interop, my proposal was just to maybe trigger interested people (versed in compilers and groovy internals) to look into this. Because the Map workaround is really just it, a workaround. The problem is also that I have to check if the required are there in every method, iterating over the map, or just assume they are there and explode when not (this is actually the pythonic way of things, but python parameter passing is much better imho, but they don't have to worry about interop...). If the check were automatic, it would be one pita less for me. Not sure if this can be done.

and there is such a subclassing problem with only named arguments as well here... Assume:

class X {
 def foo(int a, int b){}
}
....
def x = getInstanceFromSomewhere()
x.foo(b=1,a=2)

and assume the getInstanceFromSomewhere() does not return an X, but an Y extends X, written in Java, thus without named parameters. That means this call x.foo above would work only if the returned Object is an X, as soon as it is an Y it will not work anymore.

You are right, of course. However, maybe it is worth looking what others are doing in this regard? They did make it work, but then again, maybe Java interop is not as great as in Groovy. 
I also think that I mixed and matched Map arguments with default arguments, and you treat those cases separately (which is correct ;d). My main pain is the catch-it-all Map.

[...]

To sum up: I would like to be able to apply a category (maybe something
new?) to a block of code, and I would like to be able to initialize it
somehow myself with dependencies, not rely on static methods / state,
and that I can use to add methodMissing to classes.


       My use case was that the category would get some arguments that
       I had
       dependency-injected into the class that had the above code. It would
       have made my design simpler in a few cases.


   and how far should the change minimally reach for your use case?
   only the block or beyond?


The block. The code that is inside (which might be a call to
GroovyScriptEngine recursively, as the scripts might call evaluate() and
others) or deeply nested methods should see the changes. Mind that such
use blocks might be called by multiple threads, so static state is not
really an option (unless you mess around with ThreadLocals...).

categories currently are ThreadLocal changes, visible along the stack. This has been a problem in the past, because of the way we checked our callsites for validity. But now I know how to prevent this. So the only thing that is going to be slower is the method selection part and entering the block. Imho it should not really be a problem to use an instance here

Great to hear!

wujek 

Bob Brown | 27 Jun 2012 12:25
Picon
Favicon

RE: [groovy-user] Groovy 3

Thanks.

I know that there are a few ways of doing this...I was hoping that Groovy 3
would be a good time/place to bring it into the language proper.

BOB

> -----Original Message-----
> From: Tim Yates [mailto:tim.yates@...]
> Sent: Wednesday, 27 June 2012 6:22 PM
> To: user@...
> Subject: Re: [groovy-user] Groovy 3
> 
> I put together a quick meta-programming version of the Ruby Match thing:
> 
> https://gist.github.com/b00be3058d86ccaa3612
> 
> Obviously, inclusion into Groovy would mean you get proper parse errors
> when you've (for example) used a comma in the list variant at the bottom
> 
> 
> On 27 June 2012 08:42, Wujek Srujek <wujek.srujek@...> wrote:
> 
> 
> 
> 
> 	On Wed, Jun 27, 2012 at 8:30 AM, Jochen Theodorou
> <blackdrag@...> wrote:
> 
> 
> 		Am 26.06.2012 20 <tel:26.06.2012%2020> :01, schrieb Wujek
> Srujek:
> 		[...]
> 
> 
> 			Why do you think this would make overriding more
> difficult, and Java
> 			interop worse?
> 
> 
> 
> 		currently if you do
> 
> 		def foo(int a=1, long b=2)
> 
> 		we create the methods
> 
> 		foo(int,long)
> 		foo(int)
> 		foo()
> 
> 		there is a strict right to left rule for this and you cannot
have
> foo(long) this way. We do it like this to avoid type problems since a
method
> signatrue can appear only once.
> 
> 		With optional arguments like I think you described there
> would be only one method. So the optional nature is not available from
Java
> directly. That's why less interop. Also if you then write in a subclass
for
> example foo(long), does it override foo(int a=1, long b=2) in some cases
or
> not? That's why more difficult... in this more difficult for the compiler
and the
> human.
> 
> 
> 
> 			I think that calling Java methods from Groovy just
has
> to
> 			use positional parameters (I don't think I can
> succesfully use the Map
> 			workaround that exists now? the java method would
> need to take a Map,
> 			and I don't know if it would work anyways, just like
> POJO setProperty
> 			doesn't work).
> 
> 
> 
> 		Of course that works.
> 
> 
> 	Ok, I didn't know that you compile so many methods for all the
> possible combinations. All the better, imho. I was just talking about the
case
> where in groovy you have:
> 	def method(Map map) { ... }
> 	and you precompile it and try to call it from Java:
> 	method(1, 2)
> 	or whatever. An explicit map would work, though.
> 
> 
> 		But interoperability means in Groovy we have to include the
> Java world. That means we have to additionally look at the usage from Java
> as well as what happens if we subclass in Java and use from Groovy.
> 
> 
> 	Yes! I don't want to loose the interop, my proposal was just to
maybe
> trigger interested people (versed in compilers and groovy internals) to
look
> into this. Because the Map workaround is really just it, a workaround. The
> problem is also that I have to check if the required are there in every
> method, iterating over the map, or just assume they are there and explode
> when not (this is actually the pythonic way of things, but python
parameter
> passing is much better imho, but they don't have to worry about
interop...).
> If the check were automatic, it would be one pita less for me. Not sure if
this
> can be done.
> 
> 
> 		and there is such a subclassing problem with only named
> arguments as well here... Assume:
> 
> 		class X {
> 		 def foo(int a, int b){}
> 		}
> 		....
> 		def x = getInstanceFromSomewhere()
> 		x.foo(b=1,a=2)
> 
> 		and assume the getInstanceFromSomewhere() does not
> return an X, but an Y extends X, written in Java, thus without named
> parameters. That means this call x.foo above would work only if the
returned
> Object is an X, as soon as it is an Y it will not work anymore.
> 
> 
> 
> 	You are right, of course. However, maybe it is worth looking what
> others are doing in this regard? They did make it work, but then again,
maybe
> Java interop is not as great as in Groovy.
> 	I also think that I mixed and matched Map arguments with default
> arguments, and you treat those cases separately (which is correct ;d). My
> main pain is the catch-it-all Map.
> 
> 
> 		[...]
> 
> 
> 			To sum up: I would like to be able to apply a
category
> (maybe something
> 			new?) to a block of code, and I would like to be
able
> to initialize it
> 			somehow myself with dependencies, not rely on
> static methods / state,
> 			and that I can use to add methodMissing to classes.
> 
> 
> 			       My use case was that the category would get
> some arguments that
> 			       I had
> 			       dependency-injected into the class that had
the
> above code. It would
> 			       have made my design simpler in a few cases.
> 
> 
> 			   and how far should the change minimally reach for
> your use case?
> 			   only the block or beyond?
> 
> 
> 			The block. The code that is inside (which might be a
> call to
> 			GroovyScriptEngine recursively, as the scripts might
> call evaluate() and
> 			others) or deeply nested methods should see the
> changes. Mind that such
> 			use blocks might be called by multiple threads, so
> static state is not
> 			really an option (unless you mess around with
> ThreadLocals...).
> 
> 
> 
> 		categories currently are ThreadLocal changes, visible along
> the stack. This has been a problem in the past, because of the way we
> checked our callsites for validity. But now I know how to prevent this. So
the
> only thing that is going to be slower is the method selection part and
entering
> the block. Imho it should not really be a problem to use an instance here
> 
> 
> 	Great to hear!
> 
> 
> 	wujek
> 

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

    http://xircles.codehaus.org/manage_email

Jochen Theodorou | 27 Jun 2012 10:32
Picon
Gravatar

Re: [groovy-user] Groovy 3

Am 27.06.2012 09:42, schrieb Wujek Srujek:
[...]
> The problem is also that I have to check if the required are
> there in every method, iterating over the map, or just assume they are
> there and explode when not (this is actually the pythonic way of things,
> but python parameter passing is much better imho, but they don't have to
> worry about interop...). If the check were automatic, it would be one
> pita less for me. Not sure if this can be done.

how about something like this:

 <at> MapParameters("a","b","c")
def foo(params) {
   println "$a+$b = $c"
}

the transform could add a block of code at the beginning of the method 
which will extract values for a,b,c from the map and declare local 
variables with these names, for you to use later on. Then you have an 
automated check. Such a transform should not be difficult for methods.

>     and there is such a subclassing problem with only named arguments as
>     well here... Assume:
>
>     class X {
>       def foo(int a, int b){}
>     }
>     ....
>     def x = getInstanceFromSomewhere()
>     x.foo(b=1,a=2)
>
>     and assume the getInstanceFromSomewhere() does not return an X, but
>     an Y extends X, written in Java, thus without named parameters. That
>     means this call x.foo above would work only if the returned Object
>     is an X, as soon as it is an Y it will not work anymore.
>
>
> You are right, of course. However, maybe it is worth looking what others
> are doing in this regard? They did make it work, but then again, maybe
> Java interop is not as great as in Groovy.
> I also think that I mixed and matched Map arguments with default
> arguments, and you treat those cases separately (which is correct ;d).
> My main pain is the catch-it-all Map.

With real named parameters you could do a different style of optional 
parameters than today. That's what I described and I thought you did mean.

[...]
>         To sum up: I would like to be able to apply a category (maybe
>         something
>         new?) to a block of code, and I would like to be able to
>         initialize it
>         somehow myself with dependencies, not rely on static methods /
>         state,
>         and that I can use to add methodMissing to classes.

I added that to the GEP page

bye blackdrag

--

-- 
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org

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

    http://xircles.codehaus.org/manage_email

Mohamed Seifeddine | 16 Jul 2012 10:48
Picon

Re: [groovy-user] Groovy 3

Jochen, 

On Wed, Jun 27, 2012 at 8:30 AM, Jochen Theodorou <blackdrag-BA+cFGlbTmA@public.gmane.org> wrote:
Am 26.06.2012 20:01, schrieb Wujek Srujek:
[...]

Why do you think this would make overriding more difficult, and Java
interop worse?

currently if you do

def foo(int a=1, long b=2)

we create the methods

foo(int,long)
foo(int)
foo()



I remember once requesting a another feature for this type of usecase. 

Say we a method 

foo(int a=1, long b=2, double c=false) 

To avoid the order issue you are describing, you should be able to call this as: 

foo(default, 3, true)

foo()

foo(default, default, false)

foo(2) // results in foo(2, default, default)

This would allow you to have default values and a choise to override any other parameter. 
If you like to call foo(long) you could still do it as foo(default, 3) or foo(default, 3, default)

If there is no default value for the parameter, then default would result in a null being passed for object types. What happens to primitives I am not sure, but I am sure there is a choice that can me made surrounding this.

// Mohamed 


there is a strict right to left rule for this and you cannot have foo(long) this way. We do it like this to avoid type problems since a method signatrue can appear only once.

With optional arguments like I think you described there would be only one method. So the optional nature is not available from Java directly. That's why less interop. Also if you then write in a subclass for example foo(long), does it override foo(int a=1, long b=2) in some cases or not? That's why more difficult... in this more difficult for the compiler and the human.


I think that calling Java methods from Groovy just has to
use positional parameters (I don't think I can succesfully use the Map
workaround that exists now? the java method would need to take a Map,
and I don't know if it would work anyways, just like POJO setProperty
doesn't work).

Of course that works. But interoperability means in Groovy we have to include the Java world. That means we have to additionally look at the usage from Java as well as what happens if we subclass in Java and use from Groovy. and there is such a subclassing problem with only named arguments as well here... Assume:

class X {
  def foo(int a, int b){}
}
....
def x = getInstanceFromSomewhere()
x.foo(b=1,a=2)

and assume the getInstanceFromSomewhere() does not return an X, but an Y extends X, written in Java, thus without named parameters. That means this call x.foo above would work only if the returned Object is an X, as soon as it is an Y it will not work anymore.

[...]

To sum up: I would like to be able to apply a category (maybe something
new?) to a block of code, and I would like to be able to initialize it
somehow myself with dependencies, not rely on static methods / state,
and that I can use to add methodMissing to classes.


        My use case was that the category would get some arguments that
        I had
        dependency-injected into the class that had the above code. It would
        have made my design simpler in a few cases.


    and how far should the change minimally reach for your use case?
    only the block or beyond?


The block. The code that is inside (which might be a call to
GroovyScriptEngine recursively, as the scripts might call evaluate() and
others) or deeply nested methods should see the changes. Mind that such
use blocks might be called by multiple threads, so static state is not
really an option (unless you mess around with ThreadLocals...).

categories currently are ThreadLocal changes, visible along the stack. This has been a problem in the past, because of the way we checked our callsites for validity. But now I know how to prevent this. So the only thing that is going to be slower is the method selection part and entering the block. Imho it should not really be a problem to use an instance here


bye blackdrag

--
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org




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

   http://xircles.codehaus.org/manage_email



Jochen Theodorou | 16 Jul 2012 14:31
Picon
Gravatar

Re: [groovy-user] Groovy 3

Am 16.07.2012 10:48, schrieb Mohamed Seifeddine:
[...]
> I remember once requesting a another feature for this type of usecase.
>
> Say we a method
>
> foo(int a=1, long b=2, double c=false)
>
> To avoid the order issue you are describing, you should be able to call
> this as:
>
> foo(*default*, 3, true)
>
> foo()
>
> foo(*default*, *default*, false)
>
> foo(2) // results in foo(2, *default, default*)
>
> This would allow you to have default values and a choise to override any
> other parameter.
> If you like to call foo(long) you could still do it as foo(*default*, 3)
> or foo(*default, *3, *default)*
> *
> *
> If there is no default value for the parameter, then default would
> result in a *null *being passed for object types. What happens to
> primitives I am not sure, but I am sure there is a choice that can me
> made surrounding this.

If I remember my days in GW-Basic right, then there you could do things 
like this:

foo(,,true)

It doesn't combine so well with command expressions, but anyway.. The 
grammar change for this might be quite small, so it might be possible to 
add. Would you dare to make a GEP for this?

bye blackdrag

--

-- 
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org

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

    http://xircles.codehaus.org/manage_email

Jochen Theodorou | 26 Jun 2012 18:51
Picon
Gravatar

Re: [groovy-user] Groovy 3

Am 26.06.2012 14:56, schrieb Gavin Grover:
> Jochen,
>
> will VMWare assign the budget for you to make semantic changes to
> Groovy and upgrade the MOP? The project management don't seem to want
> to change anything

The project management is mainly Guillaume an myself. And we both want a 
new MOP a long time now. Changing by now established terminology is of a 
different beast then changing the semantics of the language a little 
here and there. And even if the new MOP will not be an upgrade, but a 
major changing break, most of the semantics in Groovy will still stay 
the same.

Anyway... to answer your question... Vmware has no problem so far in 
letting me do that new MOP and paying me for it ;)

bye Jochen

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

    http://xircles.codehaus.org/manage_email

Wujek Srujek | 26 Jun 2012 16:02
Picon

Re: [groovy-user] Groovy 3

There was something about methodMissing (or maybe it was getProperty et.al.?) not being able to be defined with a closure assignment to a metaClass.
Then, I had this case that my Java class had get/setProperty methods, but they were not discovered by Groovy, and so I had to set get/setProperty closures to the metaClass, which just called the Java methods.



On Tue, Jun 26, 2012 at 1:17 PM, Jochen Theodorou <blackdrag-BA+cFGlbTmA@public.gmane.org> wrote:
Hi all,

soon Groovy 2 will be released and I will start on working for Groovy 3, which is supposed to get released next year. Groovy 3 will contain a new MOP and some semantic changes. I thought I start a GEP (GEP-11) for this to make it more easy for people to contribute. I only just started the with some things I want not to have anymore in Groovy3. I will soon try to describe the new MOP. But most probably that will be in constant flux, since I will have to see if things work out right or not while I implement it.

So anyone who wants something absolutely in Groovy3 regarding semantics or the new MOP.. it would be a good time to speak now... for example in this thread. I will collect the ideas on the wiki page of the GEP and possibly make them part of that "design document".

Those who want some syntactic changes, sorry, they will not be part of that GEP.

<at> see http://docs.codehaus.org/display/GroovyJSR/GEP+11+-+Groovy+3+semantics+and+new+MOP

bye blackdrag

--
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org



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

  http://xircles.codehaus.org/manage_email



Jochen Theodorou | 27 Jun 2012 08:06
Picon
Gravatar

Re: [groovy-user] Groovy 3

Am 26.06.2012 16:02, schrieb Wujek Srujek:
> There was something about methodMissing (or maybe it was getProperty
> et.al.?) not being able to be defined with a closure assignment to a
> metaClass.

This is going to be a standard case with the new MOP, so this will 
ensured to work ;)

> Then, I had this case that my Java class had get/setProperty methods,
> but they were not discovered by Groovy, and so I had to set
> get/setProperty closures to the metaClass, which just called the Java
> methods.

yes, well, this is due to them being called directly through Java. I 
mean to change that (along with having them not there anymore by 
default), so it should then work as well

bye blackdrag

--

-- 
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org

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

    http://xircles.codehaus.org/manage_email

Skeptic . | 26 Jun 2012 19:16
Picon
Favicon

RE: [groovy-user] Groovy 3


I know it probably won't change with Groovy 3, but I hate to have to do :

assert map != null

instead of 

assert map 

because an empty map (or any other collection or boolean references) will fail the latter.

BTW, if there is a better alternative, let me know !

> Date: Tue, 26 Jun 2012 13:17:03 +0200
> From: blackdrag-BA+cFGlbTmA@public.gmane.org
> To: user-i9PBDF1N6cxnkHa44VUL00B+6BGkLq7r@public.gmane.org
> Subject: [groovy-user] Groovy 3
>
> Hi all,
>
> soon Groovy 2 will be released and I will start on working for Groovy 3,
> which is supposed to get released next year. Groovy 3 will contain a new
> MOP and some semantic changes. I thought I start a GEP (GEP-11) for this
> to make it more easy for people to contribute. I only just started the
> with some things I want not to have anymore in Groovy3. I will soon try
> to describe the new MOP. But most probably that will be in constant
> flux, since I will have to see if things work out right or not while I
> implement it.
>
> So anyone who wants something absolutely in Groovy3 regarding semantics
> or the new MOP.. it would be a good time to speak now... for example in
> this thread. I will collect the ideas on the wiki page of the GEP and
> possibly make them part of that "design document".
>
> Those who want some syntactic changes, sorry, they will not be part of
> that GEP.
>
> <at> see
> http://docs.codehaus.org/display/GroovyJSR/GEP+11+-+Groovy+3+semantics+and+new+MOP
>
> bye blackdrag
>
> --
> Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
> blog: http://blackdragsview.blogspot.com/
> german groovy discussion newsgroup: de.comp.lang.misc
> For Groovy programming sources visit http://groovy-lang.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
Gavin Grover | 27 Jun 2012 01:57
Picon
Favicon

Re: [groovy-user] Groovy 3

Jochen,

Part of the roadmapped semantic changes in Groovy 3 is the Java 8 closure retrofit. The Java 8 closures will
add many methods to the java standard libraries, see http://cr.openjdk.java.net/~briangoetz/lambda/collections-overview.html

Their methods duplicate many Groovy methods in the GDK, though their names are different, e.g. forEach,
filter, into, map, flatMap, pipeline, sorted, groupByMulti, reduce, anyMatch.

Will this mean Groovy 3 will deprecate most of the core GDK methods in favor of the Java 8 new closure methods?

Gavin Grover
blog: http://groovy.codeplex.com/wikipage?title=Blog02
email: gvgrover@...

----- Original Message -----

> From: Jochen Theodorou <blackdrag@...>
> To: user@...
> Cc: 
> Sent: Tuesday, June 26, 2012 7:17 PM
> Subject: [groovy-user] Groovy 3
> 
> Hi all,
> 
> soon Groovy 2 will be released and I will start on working for Groovy 3, which 
> is supposed to get released next year. Groovy 3 will contain a new MOP and some 
> semantic changes. I thought I start a GEP (GEP-11) for this to make it more easy 
> for people to contribute. I only just started the with some things I want not to 
> have anymore in Groovy3. I will soon try to describe the new MOP. But most 
> probably that will be in constant flux, since I will have to see if things work 
> out right or not while I implement it.
> 
> So anyone who wants something absolutely in Groovy3 regarding semantics or the 
> new MOP.. it would be a good time to speak now... for example in this thread. I 
> will collect the ideas on the wiki page of the GEP and possibly make them part 
> of that "design document".
> 
> Those who want some syntactic changes, sorry, they will not be part of that GEP.
> 
>  <at> see 
> http://docs.codehaus.org/display/GroovyJSR/GEP+11+-+Groovy+3+semantics+and+new+MOP
> 
> bye blackdrag
> 
> -- Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
> blog: http://blackdragsview.blogspot.com/
> german groovy discussion newsgroup: de.comp.lang.misc
> For Groovy programming sources visit http://groovy-lang.org
> 
> 
> 
> ---------------------------------------------------------------------
> 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

Jochen Theodorou | 27 Jun 2012 08:58
Picon
Gravatar

Re: [groovy-user] Groovy 3

Am 27.06.2012 01:57, schrieb Gavin Grover:
> Jochen,
>
> Part of the roadmapped semantic changes in Groovy 3 is the Java 8
> closure retrofit. The Java 8 closures will add many methods to the
> java standard libraries, see
> http://cr.openjdk.java.net/~briangoetz/lambda/collections-overview.html
>
>  Their methods duplicate many Groovy methods in the GDK, though their
> names are different, e.g. forEach, filter, into, map, flatMap,
> pipeline, sorted, groupByMulti, reduce, anyMatch.
>
> Will this mean Groovy 3 will deprecate most of the core GDK methods
> in favor of the Java 8 new closure methods?

Java8 is a problem for us, indeed. One problem being that the page you 
mention is a proposed API, not an approved one. That means, in the end 
it may look totally different. We may support both and then migrate in 
later versions if that is possible.

Would Java8 complete according to the plan here 
http://openjdk.java.net/projects/jdk8/ then well, I ma not sure. 
September is surely to late for adjustments of Groovy3, M6 is the latest 
we can react to, even if it would cause delays. We have to say what they 
come up with in the end. The earlier this API is "fixed" the more time 
we have to discuss the future path.

bye blackdrag

--

-- 
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org

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

    http://xircles.codehaus.org/manage_email

Cédric Champeau | 27 Jun 2012 11:07
Picon
Gravatar

Re: [groovy-user] Groovy 3

Sure, but this is also forgetting that Lambdas in Java 8 and Closures in 
Groovy are two very different beasts. Lambdas in Java 8 must be assigned 
to interfaces and cannot be "manipulated" like the closures from Groovy. 
We must support both or we'll loose very useful features. We could align 
the method names, use a similar API but in the end, we will still 
support both. It's important to say :)

Le 27/06/2012 08:58, Jochen Theodorou a écrit :
> Am 27.06.2012 01:57, schrieb Gavin Grover:
>> Jochen,
>>
>> Part of the roadmapped semantic changes in Groovy 3 is the Java 8
>> closure retrofit. The Java 8 closures will add many methods to the
>> java standard libraries, see
>> http://cr.openjdk.java.net/~briangoetz/lambda/collections-overview.html
>>
>>  Their methods duplicate many Groovy methods in the GDK, though their
>> names are different, e.g. forEach, filter, into, map, flatMap,
>> pipeline, sorted, groupByMulti, reduce, anyMatch.
>>
>> Will this mean Groovy 3 will deprecate most of the core GDK methods
>> in favor of the Java 8 new closure methods?
>
> Java8 is a problem for us, indeed. One problem being that the page you 
> mention is a proposed API, not an approved one. That means, in the end 
> it may look totally different. We may support both and then migrate in 
> later versions if that is possible.
>
> Would Java8 complete according to the plan here 
> http://openjdk.java.net/projects/jdk8/ then well, I ma not sure. 
> September is surely to late for adjustments of Groovy3, M6 is the 
> latest we can react to, even if it would cause delays. We have to say 
> what they come up with in the end. The earlier this API is "fixed" the 
> more time we have to discuss the future path.
>
> bye blackdrag
>

--

-- 
Cédric Champeau
SpringSource - A Division Of VMware
http://www.springsource.com/
http://twitter.com/CedricChampeau

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

    http://xircles.codehaus.org/manage_email

Wujek Srujek | 27 Jun 2012 11:55
Picon

Re: [groovy-user] Groovy 3

What I love in different languages / libraries and would like to have:

1. Python Generators (the 'yield' keyword), .NET / C# has it with the name 'Iterators' (and what Java calls iterators, is an Enumerator):
(python)
def gen():
  i = 1
  while True:
    yield i
    i += 1

for i in gen(): print i # that loops forever

I can't stress how useful that is to create streaming, read only data sources in just a few lines. Of course, you can do it in Java, with Iterators, Groovy alleviates the need to create an Iterable for it (as DGM adds iterator() to Iterator), and I can do it with closures coercion but it still is verbose, and I have to implement the 'remove()' method, which I don't care about - we are read only. Would love it to be automatic.

2. There are also list comprehensions ('squares = [x**2 for x in range(1, 11)]') which create lists in memory, and generator expressions ('(x*y for x in xrange(1, 11) for y in xrange(1, 11))') that create generators (point #1). The xrange function retuns a kind of a generator itself, so shouldbe a really memory-efficient implementation of the multiplication table ;d (Python 3 doesn't have both functions, range behaves like xrange in python 2.x.)
One can attach conditions to filter our certain elements, like:
[x**2 for x in range(10) if x % 2]
similarly for generators:
for i in (x*y for x in xrange(1, 4) for y in xrange(1, 4) if x % 2 if y % 2): print i
(But this slowly gets not very readable when not formatted correctly.)

3. In Groovy, methods like findAll, collect, flatten and others create lists in memory that have all elements and then returns it. There are numerous cases when you don't want that, you want to 'stream' the data, like in our case, we have an object, that has relationships to other objects, and there can be millions, and while we generate a report (with a Groovy DSL), we don't want all of them at once most of the time, as we output one by one (after filtering, processing and so on). If we do want all of them at once, we just have to wrap them in a list or sth. In Python, at some point, functions like map or enumerate have been changed to return generators, and if one wants to have all in memory and have random access via indexing, you do 'list(someMethodThatReturnsStreamingCollection())'.
Guava has 'live views'.

I think this last one would also benefit GPath, right? (I don't use it much, so maybe I am mistaken.)

wujek


On Wed, Jun 27, 2012 at 11:07 AM, Cédric Champeau <cedric.champeau-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
Sure, but this is also forgetting that Lambdas in Java 8 and Closures in Groovy are two very different beasts. Lambdas in Java 8 must be assigned to interfaces and cannot be "manipulated" like the closures from Groovy. We must support both or we'll loose very useful features. We could align the method names, use a similar API but in the end, we will still support both. It's important to say :)

Le 27/06/2012 08:58, Jochen Theodorou a écrit :

Am 27.06.2012 01:57, schrieb Gavin Grover:
Jochen,

Part of the roadmapped semantic changes in Groovy 3 is the Java 8
closure retrofit. The Java 8 closures will add many methods to the
java standard libraries, see
http://cr.openjdk.java.net/~briangoetz/lambda/collections-overview.html

 Their methods duplicate many Groovy methods in the GDK, though their
names are different, e.g. forEach, filter, into, map, flatMap,
pipeline, sorted, groupByMulti, reduce, anyMatch.

Will this mean Groovy 3 will deprecate most of the core GDK methods
in favor of the Java 8 new closure methods?

Java8 is a problem for us, indeed. One problem being that the page you mention is a proposed API, not an approved one. That means, in the end it may look totally different. We may support both and then migrate in later versions if that is possible.

Would Java8 complete according to the plan here http://openjdk.java.net/projects/jdk8/ then well, I ma not sure. September is surely to late for adjustments of Groovy3, M6 is the latest we can react to, even if it would cause delays. We have to say what they come up with in the end. The earlier this API is "fixed" the more time we have to discuss the future path.

bye blackdrag



--
Cédric Champeau
SpringSource - A Division Of VMware
http://www.springsource.com/
http://twitter.com/CedricChampeau



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

  http://xircles.codehaus.org/manage_email



Cédric Champeau | 27 Jun 2012 12:01
Picon
Gravatar

Re: [groovy-user] Groovy 3


3. In Groovy, methods like findAll, collect, flatten and others create lists in memory that have all elements and then returns it. There are numerous cases when you don't want that, you want to 'stream' the data, like in our case, we have an object, that has relationships to other objects, and there can be millions, and while we generate a report (with a Groovy DSL), we don't want all of them at once most of the time, as we output one by one (after filtering, processing and so on). If we do want all of them at once, we just have to wrap them in a list or sth. In Python, at some point, functions like map or enumerate have been changed to return generators, and if one wants to have all in memory and have random access via indexing, you do 'list(someMethodThatReturnsStreamingCollection())'.
Guava has 'live views'.

I think this last one would also benefit GPath, right? (I don't use it much, so maybe I am mistaken.)

Well, at the last Groovy DevCon, we discussed that point and we (more or less) agreed that we should wait for what Java 8 APIs will look like, because basically, they follow the "lazy" idea. Meanwhile, the extension module mechanism would allow for example Tim Yates to propose lazy evaluation and generators as an experimental feature before we integrate it :)
wujek


On Wed, Jun 27, 2012 at 11:07 AM, Cédric Champeau <cedric.champeau-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
Sure, but this is also forgetting that Lambdas in Java 8 and Closures in Groovy are two very different beasts. Lambdas in Java 8 must be assigned to interfaces and cannot be "manipulated" like the closures from Groovy. We must support both or we'll loose very useful features. We could align the method names, use a similar API but in the end, we will still support both. It's important to say :)

Le 27/06/2012 08:58, Jochen Theodorou a écrit :

Am 27.06.2012 01:57, schrieb Gavin Grover:
Jochen,

Part of the roadmapped semantic changes in Groovy 3 is the Java 8
closure retrofit. The Java 8 closures will add many methods to the
java standard libraries, see
http://cr.openjdk.java.net/~briangoetz/lambda/collections-overview.html

 Their methods duplicate many Groovy methods in the GDK, though their
names are different, e.g. forEach, filter, into, map, flatMap,
pipeline, sorted, groupByMulti, reduce, anyMatch.

Will this mean Groovy 3 will deprecate most of the core GDK methods
in favor of the Java 8 new closure methods?

Java8 is a problem for us, indeed. One problem being that the page you mention is a proposed API, not an approved one. That means, in the end it may look totally different. We may support both and then migrate in later versions if that is possible.

Would Java8 complete according to the plan here http://openjdk.java.net/projects/jdk8/ then well, I ma not sure. September is surely to late for adjustments of Groovy3, M6 is the latest we can react to, even if it would cause delays. We have to say what they come up with in the end. The earlier this API is "fixed" the more time we have to discuss the future path.

bye blackdrag



--
Cédric Champeau
SpringSource - A Division Of VMware
http://www.springsource.com/
http://twitter.com/CedricChampeau



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

  http://xircles.codehaus.org/manage_email





-- Cédric Champeau SpringSource - A Division Of VMware http://www.springsource.com/ http://twitter.com/CedricChampeau
Tim Yates | 27 Jun 2012 12:05
Picon
Gravatar

Re: [groovy-user] Groovy 3

The generator example is here btw:

http://timyates.github.com/groovy-stream/

On 27 June 2012 11:01, Cédric Champeau <cedric.champeau-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

3. In Groovy, methods like findAll, collect, flatten and others create lists in memory that have all elements and then returns it. There are numerous cases when you don't want that, you want to 'stream' the data, like in our case, we have an object, that has relationships to other objects, and there can be millions, and while we generate a report (with a Groovy DSL), we don't want all of them at once most of the time, as we output one by one (after filtering, processing and so on). If we do want all of them at once, we just have to wrap them in a list or sth. In Python, at some point, functions like map or enumerate have been changed to return generators, and if one wants to have all in memory and have random access via indexing, you do 'list(someMethodThatReturnsStreamingCollection())'.
Guava has 'live views'.

I think this last one would also benefit GPath, right? (I don't use it much, so maybe I am mistaken.)

Well, at the last Groovy DevCon, we discussed that point and we (more or less) agreed that we should wait for what Java 8 APIs will look like, because basically, they follow the "lazy" idea. Meanwhile, the extension module mechanism would allow for example Tim Yates to propose lazy evaluation and generators as an experimental feature before we integrate it :)

wujek


On Wed, Jun 27, 2012 at 11:07 AM, Cédric Champeau <cedric.champeau-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
Sure, but this is also forgetting that Lambdas in Java 8 and Closures in Groovy are two very different beasts. Lambdas in Java 8 must be assigned to interfaces and cannot be "manipulated" like the closures from Groovy. We must support both or we'll loose very useful features. We could align the method names, use a similar API but in the end, we will still support both. It's important to say :)

Le 27/06/2012 08:58, Jochen Theodorou a écrit :

Am 27.06.2012 01:57, schrieb Gavin Grover:
Jochen,

Part of the roadmapped semantic changes in Groovy 3 is the Java 8
closure retrofit. The Java 8 closures will add many methods to the
java standard libraries, see
http://cr.openjdk.java.net/~briangoetz/lambda/collections-overview.html

 Their methods duplicate many Groovy methods in the GDK, though their
names are different, e.g. forEach, filter, into, map, flatMap,
pipeline, sorted, groupByMulti, reduce, anyMatch.

Will this mean Groovy 3 will deprecate most of the core GDK methods
in favor of the Java 8 new closure methods?

Java8 is a problem for us, indeed. One problem being that the page you mention is a proposed API, not an approved one. That means, in the end it may look totally different. We may support both and then migrate in later versions if that is possible.

Would Java8 complete according to the plan here http://openjdk.java.net/projects/jdk8/ then well, I ma not sure. September is surely to late for adjustments of Groovy3, M6 is the latest we can react to, even if it would cause delays. We have to say what they come up with in the end. The earlier this API is "fixed" the more time we have to discuss the future path.

bye blackdrag



--
Cédric Champeau
SpringSource - A Division Of VMware
http://www.springsource.com/
http://twitter.com/CedricChampeau



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

  http://xircles.codehaus.org/manage_email





-- Cédric Champeau SpringSource - A Division Of VMware http://www.springsource.com/ http://twitter.com/CedricChampeau

Jochen Theodorou | 27 Jun 2012 12:16
Picon
Gravatar

Re: [groovy-user] Groovy 3

Am 27.06.2012 11:55, schrieb Wujek Srujek:
> What I love in different languages / libraries and would like to have:
>
> 1. Python Generators (the 'yield' keyword), .NET / C# has it with the
> name 'Iterators' (and what Java calls iterators, is an Enumerator):
> (python)
> def gen():
>    i = 1
>    while True:
>      yield i
>      i += 1
>
> for i in gen(): print i # that loops forever
>
> I can't stress how useful that is to create streaming, read only data
> sources in just a few lines. Of course, you can do it in Java, with
> Iterators, Groovy alleviates the need to create an Iterable for it (as
> DGM adds iterator() to Iterator), and I can do it with closures coercion
> but it still is verbose, and I have to implement the 'remove()' method,
> which I don't care about - we are read only. Would love it to be automatic.

to really support that we would need real continuations. And I think 
they are not reasonably doable on the JVM without JVM support. 
Continuation passing style could be used to get this done in Groovy with 
only the help of a little wrapper. Would that be sufficient?

On generators and lazy lists Cedric and Tim already answered.

Anyway... I don't consider those semantic changes... well real 
continuations I would, but I don't see a good way to implement them

bye blackdrag

--

-- 
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org

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

    http://xircles.codehaus.org/manage_email

Russel Winder | 2 Jul 2012 19:19
Picon
Gravatar

Re: [groovy-user] Groovy 3

On Wed, 2012-06-27 at 11:55 +0200, Wujek Srujek wrote:
> What I love in different languages / libraries and would like to have:
> 
> 1. Python Generators (the 'yield' keyword), .NET / C# has it with the name
> 'Iterators' (and what Java calls iterators, is an Enumerator):
> (python)
> def gen():
>   i = 1
>   while True:
>     yield i
>     i += 1

Information for people not au fait with Python:  The above is a
generator not a function, so the result of a call to it (generators are
callable just as a function is) is an iterable. 

> for i in gen(): print i # that loops forever

For in Python executes next on an iterable until a StopIteration
exception is raised.

> I can't stress how useful that is to create streaming, read only data
> sources in just a few lines. Of course, you can do it in Java, with
> Iterators, Groovy alleviates the need to create an Iterable for it (as DGM
> adds iterator() to Iterator), and I can do it with closures coercion but it
> still is verbose, and I have to implement the 'remove()' method, which I
> don't care about - we are read only. Would love it to be automatic.

The point here is that generators create iterables which provide streams
of values, i.e. lazy evaluated infinite sequences. This is very cool.

> 2. There are also list comprehensions ('squares = [x**2 for x in range(1,
> 11)]') which create lists in memory, and generator expressions ('(x*y for x
> in xrange(1, 11) for y in xrange(1, 11))') that create generators (point
> #1). The xrange function retuns a kind of a generator itself, so shouldbe a
> really memory-efficient implementation of the multiplication table ;d
> (Python 3 doesn't have both functions, range behaves like xrange in python
> 2.x.)
> One can attach conditions to filter our certain elements, like:
> [x**2 for x in range(10) if x % 2]
> similarly for generators:
> for i in (x*y for x in xrange(1, 4) for y in xrange(1, 4) if x % 2 if y %
> 2): print i
> (But this slowly gets not very readable when not formatted correctly.)

Moreover you can have dictionary (aka map) comprehensions and set
comprehensions. Furthermore the comprehensions are generally faster than
using construction by for/while statement since all the activity happens
in the PVM level rather than via Python objects.

Python 3 has gone to great lengths to ensure that at all stages of
functional programming with map, reduce, filter, etc. it is iterables
that are being passed not actual data structures. cf. The Java project
LazyList

> 3. In Groovy, methods like findAll, collect, flatten and others create
> lists in memory that have all elements and then returns it. There are
> numerous cases when you don't want that, you want to 'stream' the data,
> like in our case, we have an object, that has relationships to other
> objects, and there can be millions, and while we generate a report (with a
> Groovy DSL), we don't want all of them at once most of the time, as we
> output one by one (after filtering, processing and so on). If we do want
> all of them at once, we just have to wrap them in a list or sth. In Python,
> at some point, functions like map or enumerate have been changed to return
> generators, and if one wants to have all in memory and have random access
> via indexing, you do 'list(someMethodThatReturnsStreamingCollection())'.
> Guava has 'live views'.

cf. TotallyLazy  http://code.google.com/p/totallylazy/

--

-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder <at> ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel@...
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

Christopher Taranto | 2 Jul 2012 20:39

Re: [groovy-user] Groovy 3

Hi Jochen,

Coming from the Perl realm where Moose and Class::MOP have provided some excellent OO syntax - I would say please look at what Perl has been doing.  Lots of lessons have been learned and are freely available.

http://search.cpan.org/search?query=Moose
http://search.cpan.org/search?query=Class%3A%3AMOP

From the documentation:

my $point = Point->new(x => 1, y => 5);
$point->clear;

package Point; use Moose; has 'x' => (is => 'rw', isa => 'Int'); has 'y' => (is => 'rw', isa => 'Int'); sub clear { my $self = shift; $self->x(0); $self->y(0); } package Point3D; use Moose; extends 'Point'; has 'z' => (is => 'rw', isa => 'Int'); after 'clear' => sub { my $self = shift; $self->z(0); };
On Tue, Jun 26, 2012 at 4:17 AM, Jochen Theodorou <blackdrag-BA+cFGlbTmA@public.gmane.org> wrote:
Hi all,

soon Groovy 2 will be released and I will start on working for Groovy 3, which is supposed to get released next year. Groovy 3 will contain a new MOP and some semantic changes. I thought I start a GEP (GEP-11) for this to make it more easy for people to contribute. I only just started the with some things I want not to have anymore in Groovy3. I will soon try to describe the new MOP. But most probably that will be in constant flux, since I will have to see if things work out right or not while I implement it.

So anyone who wants something absolutely in Groovy3 regarding semantics or the new MOP.. it would be a good time to speak now... for example in this thread. I will collect the ideas on the wiki page of the GEP and possibly make them part of that "design document".

Those who want some syntactic changes, sorry, they will not be part of that GEP.

<at> see http://docs.codehaus.org/display/GroovyJSR/GEP+11+-+Groovy+3+semantics+and+new+MOP

bye blackdrag

--
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org



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

   http://xircles.codehaus.org/manage_email



daniel_sun | 5 Jul 2012 13:02
Picon
Favicon

[groovy-user] Re: Groovy 3

Hi Jochen,

    How about improving the each function? When each function returns true,
the iteration will continue, and when returns false, the iteration will
break.

--------------------------------
[1, 2, 3].each {
    if (it == 2) {
        return true; *// means continue*
    }

    println it
}

yields
1
3

--------------------

[1, 2, 3].each {
    if (it == 2) {
        return false; *// means break*
    }

    println it
}

yields
1

--
View this message in context: http://groovy.329449.n5.nabble.com/Groovy-3-tp5710334p5710518.html
Sent from the groovy - user mailing list archive at Nabble.com.

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

    http://xircles.codehaus.org/manage_email

Guillaume Laforge | 5 Jul 2012 13:07
Gravatar

Re: [groovy-user] Re: Groovy 3

It would break existing code.

[1, 2, 3].each { println it } would stop after the first iteration!
Because println it is a statement, which (in a way) returns null which is evaluated to false.

On Thu, Jul 5, 2012 at 1:02 PM, daniel_sun <realbluesun-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:
Hi Jochen,

    How about improving the each function? When each function returns true,
the iteration will continue, and when returns false, the iteration will
break.

--------------------------------
[1, 2, 3].each {
    if (it == 2) {
        return true; *// means continue*
    }

    println it
}

yields
1
3

--------------------

[1, 2, 3].each {
    if (it == 2) {
        return false; *// means break*
    }

    println it
}

yields
1



--
View this message in context: http://groovy.329449.n5.nabble.com/Groovy-3-tp5710334p5710518.html
Sent from the groovy - user mailing list archive at Nabble.com.

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

    http://xircles.codehaus.org/manage_email





--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one
Paul Holt | 6 Jul 2012 01:16
Picon
Gravatar

Re: [groovy-user] Re: Groovy 3

The only way to break out of an 'each' right now is via throwables, because the inner loop is a Closure. Return just returns from the current run of the Closure.

Can we look forward to seeing a different way to escape from a loop defined by a closure? Maybe a new keyword... Have any keywords been defined but not used?

On Jul 5, 2012 9:08 PM, "Guillaume Laforge" <glaforge-yCVjj/EcxBJg9hUCZPvPmw@public.gmane.org> wrote:
It would break existing code.
[1, 2, 3].each { println it } would stop after the first iteration!
Because println it is a statement, which (in a way) returns null which is evaluated to false.

On Thu, Jul 5, 2012 at 1:02 PM, daniel_sun <realbluesun-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:
Hi Jochen,

    How about improving the each function? When each function returns true,
the iteration will continue, and when returns false, the iteration will
break.

--------------------------------
[1, 2, 3].each {
    if (it == 2) {
        return true; *// means continue*
    }

    println it
}

yields
1
3

--------------------

[1, 2, 3].each {
    if (it == 2) {
        return false; *// means break*
    }

    println it
}

yields
1



--
View this message in context: http://groovy.329449.n5.nabble.com/Groovy-3-tp5710334p5710518.html
Sent from the groovy - user mailing list archive at Nabble.com.

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

    http://xircles.codehaus.org/manage_email





--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one
Wujek Srujek | 6 Jul 2012 07:48
Picon

Re: [groovy-user] Re: Groovy 3

How reusing break?

On Fri, Jul 6, 2012 at 1:16 AM, Paul Holt <pcholt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

The only way to break out of an 'each' right now is via throwables, because the inner loop is a Closure. Return just returns from the current run of the Closure.

Can we look forward to seeing a different way to escape from a loop defined by a closure? Maybe a new keyword... Have any keywords been defined but not used?

On Jul 5, 2012 9:08 PM, "Guillaume Laforge" <glaforge-yCVjj/EcxBJg9hUCZPvPmw@public.gmane.org> wrote:
It would break existing code.
[1, 2, 3].each { println it } would stop after the first iteration!
Because println it is a statement, which (in a way) returns null which is evaluated to false.

On Thu, Jul 5, 2012 at 1:02 PM, daniel_sun <realbluesun-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:
Hi Jochen,

    How about improving the each function? When each function returns true,
the iteration will continue, and when returns false, the iteration will
break.

--------------------------------
[1, 2, 3].each {
    if (it == 2) {
        return true; *// means continue*
    }

    println it
}

yields
1
3

--------------------

[1, 2, 3].each {
    if (it == 2) {
        return false; *// means break*
    }

    println it
}

yields
1



--
View this message in context: http://groovy.329449.n5.nabble.com/Groovy-3-tp5710334p5710518.html
Sent from the groovy - user mailing list archive at Nabble.com.

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

    http://xircles.codehaus.org/manage_email





--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one

Paul Holt | 6 Jul 2012 08:17
Picon
Gravatar

Re: [groovy-user] Re: Groovy 3

What does break do right now if there is no enclosing loop?

On Jul 6, 2012 3:50 PM, "Wujek Srujek" <wujek.srujek-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
How reusing break?

On Fri, Jul 6, 2012 at 1:16 AM, Paul Holt <pcholt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

The only way to break out of an 'each' right now is via throwables, because the inner loop is a Closure. Return just returns from the current run of the Closure.

Can we look forward to seeing a different way to escape from a loop defined by a closure? Maybe a new keyword... Have any keywords been defined but not used?

On Jul 5, 2012 9:08 PM, "Guillaume Laforge" <glaforge-yCVjj/EcxBJg9hUCZPvPmw@public.gmane.org> wrote:
It would break existing code.
[1, 2, 3].each { println it } would stop after the first iteration!
Because println it is a statement, which (in a way) returns null which is evaluated to false.

On Thu, Jul 5, 2012 at 1:02 PM, daniel_sun <realbluesun-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:
Hi Jochen,

    How about improving the each function? When each function returns true,
the iteration will continue, and when returns false, the iteration will
break.

--------------------------------
[1, 2, 3].each {
    if (it == 2) {
        return true; *// means continue*
    }

    println it
}

yields
1
3

--------------------

[1, 2, 3].each {
    if (it == 2) {
        return false; *// means break*
    }

    println it
}

yields
1



--
View this message in context: http://groovy.329449.n5.nabble.com/Groovy-3-tp5710334p5710518.html
Sent from the groovy - user mailing list archive at Nabble.com.

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

    http://xircles.codehaus.org/manage_email





--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one

Guillaume Laforge | 6 Jul 2012 09:27
Gravatar

Re: [groovy-user] Re: Groovy 3

Well, reusing break, continue, etc, are some obvious choices, of course, but if you look back in the archives of the mailing-lists, you'll find plenty of discussions on this topic, about local and non-local returns, breaking out of each loops, etc.

The problem is not trivial, and we've never really found a good approach there.

On Fri, Jul 6, 2012 at 8:17 AM, Paul Holt <pcholt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

What does break do right now if there is no enclosing loop?

On Jul 6, 2012 3:50 PM, "Wujek Srujek" <wujek.srujek-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
How reusing break?

On Fri, Jul 6, 2012 at 1:16 AM, Paul Holt <pcholt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

The only way to break out of an 'each' right now is via throwables, because the inner loop is a Closure. Return just returns from the current run of the Closure.

Can we look forward to seeing a different way to escape from a loop defined by a closure? Maybe a new keyword... Have any keywords been defined but not used?

On Jul 5, 2012 9:08 PM, "Guillaume Laforge" <glaforge-yCVjj/EcxBJg9hUCZPvPmw@public.gmane.org> wrote:
It would break existing code.
[1, 2, 3].each { println it } would stop after the first iteration!
Because println it is a statement, which (in a way) returns null which is evaluated to false.

On Thu, Jul 5, 2012 at 1:02 PM, daniel_sun <realbluesun-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:
Hi Jochen,

    How about improving the each function? When each function returns true,
the iteration will continue, and when returns false, the iteration will
break.

--------------------------------
[1, 2, 3].each {
    if (it == 2) {
        return true; *// means continue*
    }

    println it
}

yields
1
3

--------------------

[1, 2, 3].each {
    if (it == 2) {
        return false; *// means break*
    }

    println it
}

yields
1



--
View this message in context: http://groovy.329449.n5.nabble.com/Groovy-3-tp5710334p5710518.html
Sent from the groovy - user mailing list archive at Nabble.com.

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

    http://xircles.codehaus.org/manage_email





--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one




--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one
Cédric Champeau | 6 Jul 2012 09:34
Picon
Gravatar

Re: [groovy-user] Re: Groovy 3

Also, there's the Closure.directive field that could be used by some algorithms, however, even the Groovy core doesn't really make use of it...

Le 06/07/2012 09:27, Guillaume Laforge a écrit :
Well, reusing break, continue, etc, are some obvious choices, of course, but if you look back in the archives of the mailing-lists, you'll find plenty of discussions on this topic, about local and non-local returns, breaking out of each loops, etc.
The problem is not trivial, and we've never really found a good approach there.

On Fri, Jul 6, 2012 at 8:17 AM, Paul Holt <pcholt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

What does break do right now if there is no enclosing loop?

On Jul 6, 2012 3:50 PM, "Wujek Srujek" <wujek.srujek-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
How reusing break?

On Fri, Jul 6, 2012 at 1:16 AM, Paul Holt <pcholt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

The only way to break out of an 'each' right now is via throwables, because the inner loop is a Closure. Return just returns from the current run of the Closure.

Can we look forward to seeing a different way to escape from a loop defined by a closure? Maybe a new keyword... Have any keywords been defined but not used?

On Jul 5, 2012 9:08 PM, "Guillaume Laforge" <glaforge-yCVjj/EcxBJg9hUCZPvPmw@public.gmane.org> wrote:
It would break existing code.
[1, 2, 3].each { println it } would stop after the first iteration!
Because println it is a statement, which (in a way) returns null which is evaluated to false.

On Thu, Jul 5, 2012 at 1:02 PM, daniel_sun <realbluesun-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:
Hi Jochen,

    How about improving the each function? When each function returns true,
the iteration will continue, and when returns false, the iteration will
break.

--------------------------------
[1, 2, 3].each {
    if (it == 2) {
        return true; *// means continue*
    }

    println it
}

yields
1
3

--------------------

[1, 2, 3].each {
    if (it == 2) {
        return false; *// means break*
    }

    println it
}

yields
1



--
View this message in context: http://groovy.329449.n5.nabble.com/Groovy-3-tp5710334p5710518.html
Sent from the groovy - user mailing list archive at Nabble.com.

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

    http://xircles.codehaus.org/manage_email





--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one




--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one


-- Cédric Champeau SpringSource - A Division Of VMware http://www.springsource.com/ http://twitter.com/CedricChampeau
Guillaume Laforge | 6 Jul 2012 09:40
Gravatar

Re: [groovy-user] Re: Groovy 3

Yes, with Closure.DONE.



On Fri, Jul 6, 2012 at 9:34 AM, Cédric Champeau <cedric.champeau-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
Also, there's the Closure.directive field that could be used by some algorithms, however, even the Groovy core doesn't really make use of it...

Le 06/07/2012 09:27, Guillaume Laforge a écrit :
Well, reusing break, continue, etc, are some obvious choices, of course, but if you look back in the archives of the mailing-lists, you'll find plenty of discussions on this topic, about local and non-local returns, breaking out of each loops, etc.
The problem is not trivial, and we've never really found a good approach there.

On Fri, Jul 6, 2012 at 8:17 AM, Paul Holt <pcholt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

What does break do right now if there is no enclosing loop?

On Jul 6, 2012 3:50 PM, "Wujek Srujek" <wujek.srujek-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
How reusing break?

On Fri, Jul 6, 2012 at 1:16 AM, Paul Holt <pcholt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

The only way to break out of an 'each' right now is via throwables, because the inner loop is a Closure. Return just returns from the current run of the Closure.

Can we look forward to seeing a different way to escape from a loop defined by a closure? Maybe a new keyword... Have any keywords been defined but not used?

On Jul 5, 2012 9:08 PM, "Guillaume Laforge" <glaforge-yCVjj/EcxBJg9hUCZPvPmw@public.gmane.org> wrote:
It would break existing code.
[1, 2, 3].each { println it } would stop after the first iteration!
Because println it is a statement, which (in a way) returns null which is evaluated to false.

On Thu, Jul 5, 2012 at 1:02 PM, daniel_sun <realbluesun <at> hotmail.com> wrote:
Hi Jochen,

    How about improving the each function? When each function returns true,
the iteration will continue, and when returns false, the iteration will
break.

--------------------------------
[1, 2, 3].each {
    if (it == 2) {
        return true; *// means continue*
    }

    println it
}

yields
1
3

--------------------

[1, 2, 3].each {
    if (it == 2) {
        return false; *// means break*
    }

    println it
}

yields
1



--
View this message in context: http://groovy.329449.n5.nabble.com/Groovy-3-tp5710334p5710518.html
Sent from the groovy - user mailing list archive at Nabble.com.

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

    http://xircles.codehaus.org/manage_email





--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one




--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one


-- Cédric Champeau SpringSource - A Division Of VMware http://www.springsource.com/ http://twitter.com/CedricChampeau



--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one
Wujek Srujek | 6 Jul 2012 11:21
Picon

Re: [groovy-user] Re: Groovy 3

Ok, sorry, I didn't read the mailing list about the topic, it just seemed a good idea to just throw that in here and see what happens ;d



On Fri, Jul 6, 2012 at 9:40 AM, Guillaume Laforge <glaforge-yCVjj/EcxBJg9hUCZPvPmw@public.gmane.org> wrote:
Yes, with Closure.DONE.


On Fri, Jul 6, 2012 at 9:34 AM, Cédric Champeau <cedric.champeau-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
Also, there's the Closure.directive field that could be used by some algorithms, however, even the Groovy core doesn't really make use of it...

Le 06/07/2012 09:27, Guillaume Laforge a écrit :
Well, reusing break, continue, etc, are some obvious choices, of course, but if you look back in the archives of the mailing-lists, you'll find plenty of discussions on this topic, about local and non-local returns, breaking out of each loops, etc.
The problem is not trivial, and we've never really found a good approach there.

On Fri, Jul 6, 2012 at 8:17 AM, Paul Holt <pcholt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

What does break do right now if there is no enclosing loop?

On Jul 6, 2012 3:50 PM, "Wujek Srujek" <wujek.srujek-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
How reusing break?

On Fri, Jul 6, 2012 at 1:16 AM, Paul Holt <pcholt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

The only way to break out of an 'each' right now is via throwables, because the inner loop is a Closure. Return just returns from the current run of the Closure.

Can we look forward to seeing a different way to escape from a loop defined by a closure? Maybe a new keyword... Have any keywords been defined but not used?

On Jul 5, 2012 9:08 PM, "Guillaume Laforge" <glaforge-yCVjj/EcxBJg9hUCZPvPmw@public.gmane.org> wrote:
It would break existing code.
[1, 2, 3].each { println it } would stop after the first iteration!
Because println it is a statement, which (in a way) returns null which is evaluated to false.

On Thu, Jul 5, 2012 at 1:02 PM, daniel_sun <realbluesun <at> hotmail.com> wrote:
Hi Jochen,

    How about improving the each function? When each function returns true,
the iteration will continue, and when returns false, the iteration will
break.

--------------------------------
[1, 2, 3].each {
    if (it == 2) {
        return true; *// means continue*
    }

    println it
}

yields
1
3

--------------------

[1, 2, 3].each {
    if (it == 2) {
        return false; *// means break*
    }

    println it
}

yields
1



--
View this message in context: http://groovy.329449.n5.nabble.com/Groovy-3-tp5710334p5710518.html
Sent from the groovy - user mailing list archive at Nabble.com.

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

    http://xircles.codehaus.org/manage_email





--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one




--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one


-- Cédric Champeau SpringSource - A Division Of VMware http://www.springsource.com/ http://twitter.com/CedricChampeau



--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one

Tim Yates | 6 Jul 2012 11:41
Picon
Gravatar

Re: [groovy-user] Re: Groovy 3

A small thing, but I'd like the


  def (a,b,c) = [ 'a', 'b', 'c' ]

idiom to stretch to allowing a type rather than def, ie:

  String (a,b,c) = [ 'a', 'b', 'c' ]

Guillaume Laforge | 6 Jul 2012 11:49
Gravatar

Re: [groovy-user] Re: Groovy 3

On Fri, Jul 6, 2012 at 11:41 AM, Tim Yates <tim.yates-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
A small thing, but I'd like the

  def (a,b,c) = [ 'a', 'b', 'c' ]

idiom to stretch to allowing a type rather than def, ie:

  String (a,b,c) = [ 'a', 'b', 'c' ]

Well the actual syntax for that is:

def (String a, String b, String c) = ['a', 'b', 'c']

As you can specify different types for each variable.

--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one
Steven Cooke | 19 Sep 2012 21:10
Picon

Re: [groovy-user] Re: Groovy 3

I have found using different looping constructs helpful



e.g. 
 [1, 2, 3].while(p) {...}  // loop until p is false or end of list
 [1,2,3].until(p) {...} // loop until p is true or end of list
 [1,2,3].when(p) {...} // loop for each executing closure only if p is true
where p is some predicate


They are essentially just sugar over filter methods but can be guaranteed to not create an intermediate list which is essential for my use case as the collections I have are more stream-like than list-like

each should always iterate over each IMHO

On Thu, Jul 5, 2012 at 7:02 AM, daniel_sun <realbluesun-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:
Hi Jochen,

    How about improving the each function? When each function returns true,
the iteration will continue, and when returns false, the iteration will
break.

--------------------------------
[1, 2, 3].each {
    if (it == 2) {
        return true; *// means continue*
    }

    println it
}

yields
1
3

--------------------

[1, 2, 3].each {
    if (it == 2) {
        return false; *// means break*
    }

    println it
}

yields
1



--
View this message in context: http://groovy.329449.n5.nabble.com/Groovy-3-tp5710334p5710518.html
Sent from the groovy - user mailing list archive at Nabble.com.

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

    http://xircles.codehaus.org/manage_email



3rdFloorGolfer | 9 Jul 2012 14:01
Picon

[groovy-user] Re: Groovy 3

Hello Jochen,

Not sure this one would fall into MOP or semantic changes, but what about
enforcing "true" scoping in Groovy 3, i.e. private / package / protected /
public?

' <at> PackageScope' annotation is a 1st step, though I am not convinced it to be
the perfect answer to the concern. I know many consider current Groovy scope
management as a feature, which I can understand for testing/mocking purpose.
However, when dealing with designing frameworks or apis, it sounds more like
a limitation, imho.

I may have missed recent devs in Groovy, so discard the question if no
longer applicable. 
Thanks in advance for your feedback!

Regards.

--
View this message in context: http://groovy.329449.n5.nabble.com/Groovy-3-tp5710334p5710576.html
Sent from the groovy - user mailing list archive at Nabble.com.

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

    http://xircles.codehaus.org/manage_email

Jochen Theodorou | 9 Jul 2012 21:13
Picon
Gravatar

Re: [groovy-user] Re: Groovy 3

Am 09.07.2012 14:01, schrieb 3rdFloorGolfer:
> Hello Jochen,
>
> Not sure this one would fall into MOP or semantic changes, but what about
> enforcing "true" scoping in Groovy 3, i.e. private / package / protected /
> public?

yes... the problem is how to fiddle that in the MOP. I would normally 
say that there are like two different ways...

(1) Foo.metaClass.allowPrivateAccess = true
something along this and then everyone can access private members of Foo

(2) ... that is something we have to still think about how it would look 
like in code... but it would do more or less the following... every code 
written in this lexical scope (be it class, source unit, method, a block 
of code..) is allowed to access any private member.

Number 2 is actually what makes the most sense for mocking and testing, 
from my point of view, while the first option is more like the meta 
class DSL stuff we already have. I have not yet formalized option 2 
though...

bye blackdrag

--

-- 
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org

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

    http://xircles.codehaus.org/manage_email

Paul Bennett | 20 Jul 2012 14:48

Re: [groovy-user] Groovy 3

One thing I really miss from other dynamic languages (Ruby, Smalltalk) is polymorphic dispatch of class
methods i.e. static methods in Java/Groovy. It's really convenient to be able to define a static method on
a class, then override in sub-classes. I suspect that there are underlying issues in the Java VM that make
this difficult, inefficient or impossible, but I don't know enough to be sure.

Is it possible? I guess I would be happy to be able to add methods to the metaClass, and dispatch of that - or
maybe that's possible already?

Cheers,

Paul

On Jun 26, 2012, at 7:17 AM, Jochen Theodorou wrote:

> Hi all,
> 
> soon Groovy 2 will be released and I will start on working for Groovy 3, which is supposed to get released
next year. Groovy 3 will contain a new MOP and some semantic changes. I thought I start a GEP (GEP-11) for
this to make it more easy for people to contribute. I only just started the with some things I want not to have
anymore in Groovy3. I will soon try to describe the new MOP. But most probably that will be in constant flux,
since I will have to see if things work out right or not while I implement it.
> 
> So anyone who wants something absolutely in Groovy3 regarding semantics or the new MOP.. it would be a good
time to speak now... for example in this thread. I will collect the ideas on the wiki page of the GEP and
possibly make them part of that "design document".
> 
> Those who want some syntactic changes, sorry, they will not be part of that GEP.
> 
>  <at> see http://docs.codehaus.org/display/GroovyJSR/GEP+11+-+Groovy+3+semantics+and+new+MOP
> 
> bye blackdrag
> 
> -- 
> Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
> blog: http://blackdragsview.blogspot.com/
> german groovy discussion newsgroup: de.comp.lang.misc
> For Groovy programming sources visit http://groovy-lang.org
> 
> 
> 
> ---------------------------------------------------------------------
> 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

Jochen Theodorou | 20 Jul 2012 15:53
Picon
Gravatar

Re: [groovy-user] Groovy 3

Am 20.07.2012 14:48, schrieb Paul Bennett:
> One thing I really miss from other dynamic languages (Ruby,
> Smalltalk) is polymorphic dispatch of class methods i.e. static
> methods in Java/Groovy. It's really convenient to be able to define a
> static method on a class, then override in sub-classes. I suspect
> that there are underlying issues in the Java VM that make this
> difficult, inefficient or impossible, but I don't know enough to be
> sure.
>
> Is it possible? I guess I would be happy to be able to add methods to
> the metaClass, and dispatch of that - or maybe that's possible
> already?

you mean this I guess:

class A{
   static foo(){1}
   static bar(){foo()}
}
class B extends A{
   static foo(){2}
}
assert B.bar() == 2

The only way I can currently imagine on how to implement that is by 
compiling the static methods with a kind of "this", that will be given 
in automatically, simulating, what the JVM does for us automatically 
normally. This means differing method signatures (foo() will be for 
example foo(Class)) - though this can probably be prevented - and it 
means Java will not fit in there nicely. If A is written in Java, then B 
will still not show polymorphism for example.

But in theory it should be doable with a transform only.

bye blackdrag

--

-- 
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org

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

    http://xircles.codehaus.org/manage_email

Ondřej Čada | 24 Jul 2012 19:39
Picon

Re: [groovy-user] Groovy 3

Paul,

On Jul 20, 2012, at 2:48 PM, Paul Bennett wrote:

> One thing I really miss from other dynamic languages (Ruby, Smalltalk) is polymorphic dispatch of class
methods i.e. static methods in Java/Groovy. It's really convenient to be able to define a static method on
a class, then override in sub-classes. I suspect that there are underlying issues in the Java VM that make
this difficult, inefficient or impossible, but I don't know enough to be sure.
> 
> Is it possible? I guess I would be happy to be able to add methods to the metaClass, and dispatch of that - or
maybe that's possible already?

Some time ago I've played with the idea; alas I had to focus on other things and did not get back to that. Here's
a copy of what I found:

===
> [...]
>> I've considered to add the 'this' argument through an AST, and at
>> the  same moment create a stub method to be called from Java -- something like
>> 
>> // source code:
>> static def foo(arg1, ... argN) { ... }
>> // result of AST:
>> static def foo(Class this,arg1, ... argN) { ... }
>> static def foo(arg1, ... argN) { foo(null,arg1, ... argN) }
> 
> in Groovy source (not necessarily in the AST) you can use optional arguments:
> 
> static def foo(Class this=null, arg1,...argN) {...}
> 
> And for you this is surely ok. Just to take this into the language I am not sure it is a good idea.

Doing it myself, I at the moment can't see a solution to

(i) catching static method invocations globally

The API does not seem to support that -- foo.metaClass.static.invokeMethod=... works for one specific
class foo only.

(ii) using new dynamic 'this' automatically when calling methods

This one perhaps can be solved AST-level, but I am not quite sure at this moment.

> Where you can really have a problem is if foo is overloaded and foo takes Class as first argument one time and
one time not, but everything else is the same.. for example:
> 
> foo()
> foo(Class)

Right, that was exactly what I meant by

"Preferrably with some distinctive type instead of Class, so that there is never any danger of a clash with
normal pair of methods like "static def foo() { ... } static def foo(Class foo) { .... }"."

Or does not Java/Groovy allow to define my own type for Class, which would contain class all right, but
allowing to distinguish these two cases?

> [...]
>> To go a bit further, we need an AST. I've got alas no more time to play now, but it seems to me it should be
possible (and comparatively easy) to
>> 
>> - auto-add the extra Class argument to the static methods;
>> - annotate the methods so that the test above (whether to add the self argument or not) would not fail in
case there happen to be more methods with different signatures in the class;
>> - prepend automatically "self." (or "this." if fixed at runtime) when calling other methods;
>> - implement "super." as simply "<superclass>." -- i.e., if "super.foo()" was used in Bar, it would turn
to "Foo.foo()"; if it was used in Bar, it would turn to "Object.foo()".
>> 
>> I guess there are still dark corners and potential problems, but seems to me it _might_ lead to the desired
outcome. With some luck :)
> 
> a transform can do the replacements, when the class is compiled, no big thing.

I fear a bit the "prepend automatically "self."" part, since I am not sure how difficult it is to determine
whether it should be done or not -- compare e.g., the standard Category AST, which does something similar,
and fails with the implicit 'it'.
===

All the best,
---
Ondra Čada
OCSoftware:     ocs@...               http://www.ocs.cz
private         ondra@...             http://www.ocs.cz/oc

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

    http://xircles.codehaus.org/manage_email

Mohamed Seifeddine | 12 Sep 2012 11:54
Picon

Re: [groovy-user] Groovy 3

Hi, 


I just came to think about something that I think would be a nice addition to Groovy Strings.

Just came about the new Dollar Slashy String and also saw that the slashy string is now multiline. 

I tried them out hoping that my case would be covered, but no.

All multiline versions fail to take into account that you might not want to keep the white space between each line, when you need to format them properly or when you have the multiline declared in indented code.

if ( true ) {
     String s = """I would like not to have to escape \
                        my string when I am formatting the String to get rid \
                        of the whitespace and newline and what not"""
}

The purpose of introducing the multiline string back in the days as I understood it was so that we did not have to "concatinate " + "strings on " + "new lines " + "making things less readable" .
I am aware of the backslash as you can see above, but it would be nice to see a multiline string that behave like the + one without having to nest ugly slashes everywhere. 

Also the above prints: 
I would like not to have to escape                         my string when I am formatting the String to get rid                         of the whitespace and newline and what not

So even if the newlines are gone with the backslash at the end of the line, the whitespace are not.

This is not really a nice option either: 

if ( true ) {
   if ( true ) {
        String s = """I would like not to have to escape \
my string when I am formatting the String to get rid \
of the whitespace and newline and what not"""
   }
}

Suggestion: 

String s = \"""My name 
               is Mohamed and I like Groo
               vy"""\

Prints: 
My name is Mohamed and I like Groovy

The tricky part is when a valid space before breaking a line is. However if white space does exist before the end of the line, ( like after My name ) then include it. It might not be quite readable though for a developer, so perhaps forcing the escape of a space at the end or start of line might be a good idea. 

String s = \"""My name \
               is Mohamed and I like Groo
               vy or escape
               \ here"""\

My two cents.

// Mohamed



On Tue, Jul 24, 2012 at 7:39 PM, Ondřej Čada <ocs <at> ocs.cz> wrote:
Paul,

On Jul 20, 2012, at 2:48 PM, Paul Bennett wrote:

> One thing I really miss from other dynamic languages (Ruby, Smalltalk) is polymorphic dispatch of class methods i.e. static methods in Java/Groovy. It's really convenient to be able to define a static method on a class, then override in sub-classes. I suspect that there are underlying issues in the Java VM that make this difficult, inefficient or impossible, but I don't know enough to be sure.
>
> Is it possible? I guess I would be happy to be able to add methods to the metaClass, and dispatch of that - or maybe that's possible already?

Some time ago I've played with the idea; alas I had to focus on other things and did not get back to that. Here's a copy of what I found:

===
> [...]
>> I've considered to add the 'this' argument through an AST, and at
>> the  same moment create a stub method to be called from Java -- something like
>>
>> // source code:
>> static def foo(arg1, ... argN) { ... }
>> // result of AST:
>> static def foo(Class this,arg1, ... argN) { ... }
>> static def foo(arg1, ... argN) { foo(null,arg1, ... argN) }
>
> in Groovy source (not necessarily in the AST) you can use optional arguments:
>
> static def foo(Class this=null, arg1,...argN) {...}
>
> And for you this is surely ok. Just to take this into the language I am not sure it is a good idea.

Doing it myself, I at the moment can't see a solution to

(i) catching static method invocations globally

The API does not seem to support that -- foo.metaClass.static.invokeMethod=... works for one specific class foo only.

(ii) using new dynamic 'this' automatically when calling methods

This one perhaps can be solved AST-level, but I am not quite sure at this moment.

> Where you can really have a problem is if foo is overloaded and foo takes Class as first argument one time and one time not, but everything else is the same.. for example:
>
> foo()
> foo(Class)

Right, that was exactly what I meant by

"Preferrably with some distinctive type instead of Class, so that there is never any danger of a clash with normal pair of methods like "static def foo() { ... } static def foo(Class foo) { .... }"."

Or does not Java/Groovy allow to define my own type for Class, which would contain class all right, but allowing to distinguish these two cases?

> [...]
>> To go a bit further, we need an AST. I've got alas no more time to play now, but it seems to me it should be possible (and comparatively easy) to
>>
>> - auto-add the extra Class argument to the static methods;
>> - annotate the methods so that the test above (whether to add the self argument or not) would not fail in case there happen to be more methods with different signatures in the class;
>> - prepend automatically "self." (or "this." if fixed at runtime) when calling other methods;
>> - implement "super." as simply "<superclass>." -- i.e., if "super.foo()" was used in Bar, it would turn to "Foo.foo()"; if it was used in Bar, it would turn to "Object.foo()".
>>
>> I guess there are still dark corners and potential problems, but seems to me it _might_ lead to the desired outcome. With some luck :)
>
> a transform can do the replacements, when the class is compiled, no big thing.

I fear a bit the "prepend automatically "self."" part, since I am not sure how difficult it is to determine whether it should be done or not -- compare e.g., the standard Category AST, which does something similar, and fails with the implicit 'it'.
===

All the best,
---
Ondra Čada
OCSoftware:     ocs-CKS8FbnQINU@public.gmane.org               http://www.ocs.cz
private         ondra <at> ocs.cz             http://www.ocs.cz/oc




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

    http://xircles.codehaus.org/manage_email



Guillaume Laforge | 12 Sep 2012 11:58
Gravatar

Re: [groovy-user] Groovy 3

Have you had a look at the stripIndent() and stripMargin() methods that Groovy adds to String?


Guillaume

On Wed, Sep 12, 2012 at 11:54 AM, Mohamed Seifeddine <mseifeddo <at> gmail.com> wrote:
Hi, 

I just came to think about something that I think would be a nice addition to Groovy Strings.

Just came about the new Dollar Slashy String and also saw that the slashy string is now multiline. 

I tried them out hoping that my case would be covered, but no.

All multiline versions fail to take into account that you might not want to keep the white space between each line, when you need to format them properly or when you have the multiline declared in indented code.

if ( true ) {
     String s = """I would like not to have to escape \
                        my string when I am formatting the String to get rid \
                        of the whitespace and newline and what not"""
}

The purpose of introducing the multiline string back in the days as I understood it was so that we did not have to "concatinate " + "strings on " + "new lines " + "making things less readable" .
I am aware of the backslash as you can see above, but it would be nice to see a multiline string that behave like the + one without having to nest ugly slashes everywhere. 

Also the above prints: 
I would like not to have to escape                         my string when I am formatting the String to get rid                         of the whitespace and newline and what not

So even if the newlines are gone with the backslash at the end of the line, the whitespace are not.

This is not really a nice option either: 

if ( true ) {
   if ( true ) {
        String s = """I would like not to have to escape \
my string when I am formatting the String to get rid \
of the whitespace and newline and what not"""
   }
}

Suggestion: 

String s = \"""My name 
               is Mohamed and I like Groo
               vy"""\

Prints: 
My name is Mohamed and I like Groovy

The tricky part is when a valid space before breaking a line is. However if white space does exist before the end of the line, ( like after My name ) then include it. It might not be quite readable though for a developer, so perhaps forcing the escape of a space at the end or start of line might be a good idea. 

String s = \"""My name \
               is Mohamed and I like Groo
               vy or escape
               \ here"""\

My two cents.

// Mohamed



On Tue, Jul 24, 2012 at 7:39 PM, Ondřej Čada <ocs-CKS8FbnQINU@public.gmane.org> wrote:
Paul,

On Jul 20, 2012, at 2:48 PM, Paul Bennett wrote:

> One thing I really miss from other dynamic languages (Ruby, Smalltalk) is polymorphic dispatch of class methods i.e. static methods in Java/Groovy. It's really convenient to be able to define a static method on a class, then override in sub-classes. I suspect that there are underlying issues in the Java VM that make this difficult, inefficient or impossible, but I don't know enough to be sure.
>
> Is it possible? I guess I would be happy to be able to add methods to the metaClass, and dispatch of that - or maybe that's possible already?

Some time ago I've played with the idea; alas I had to focus on other things and did not get back to that. Here's a copy of what I found:

===
> [...]
>> I've considered to add the 'this' argument through an AST, and at
>> the  same moment create a stub method to be called from Java -- something like
>>
>> // source code:
>> static def foo(arg1, ... argN) { ... }
>> // result of AST:
>> static def foo(Class this,arg1, ... argN) { ... }
>> static def foo(arg1, ... argN) { foo(null,arg1, ... argN) }
>
> in Groovy source (not necessarily in the AST) you can use optional arguments:
>
> static def foo(Class this=null, arg1,...argN) {...}
>
> And for you this is surely ok. Just to take this into the language I am not sure it is a good idea.

Doing it myself, I at the moment can't see a solution to

(i) catching static method invocations globally

The API does not seem to support that -- foo.metaClass.static.invokeMethod=... works for one specific class foo only.

(ii) using new dynamic 'this' automatically when calling methods

This one perhaps can be solved AST-level, but I am not quite sure at this moment.

> Where you can really have a problem is if foo is overloaded and foo takes Class as first argument one time and one time not, but everything else is the same.. for example:
>
> foo()
> foo(Class)

Right, that was exactly what I meant by

"Preferrably with some distinctive type instead of Class, so that there is never any danger of a clash with normal pair of methods like "static def foo() { ... } static def foo(Class foo) { .... }"."

Or does not Java/Groovy allow to define my own type for Class, which would contain class all right, but allowing to distinguish these two cases?

> [...]
>> To go a bit further, we need an AST. I've got alas no more time to play now, but it seems to me it should be possible (and comparatively easy) to
>>
>> - auto-add the extra Class argument to the static methods;
>> - annotate the methods so that the test above (whether to add the self argument or not) would not fail in case there happen to be more methods with different signatures in the class;
>> - prepend automatically "self." (or "this." if fixed at runtime) when calling other methods;
>> - implement "super." as simply "<superclass>." -- i.e., if "super.foo()" was used in Bar, it would turn to "Foo.foo()"; if it was used in Bar, it would turn to "Object.foo()".
>>
>> I guess there are still dark corners and potential problems, but seems to me it _might_ lead to the desired outcome. With some luck :)
>
> a transform can do the replacements, when the class is compiled, no big thing.

I fear a bit the "prepend automatically "self."" part, since I am not sure how difficult it is to determine whether it should be done or not -- compare e.g., the standard Category AST, which does something similar, and fails with the implicit 'it'.
===

All the best,
---
Ondra Čada
OCSoftware:     ocs-CKS8FbnQINU@public.gmane.org               http://www.ocs.cz
private         ondra-CKS8FbnQINU@public.gmane.org             http://www.ocs.cz/oc




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

    http://xircles.codehaus.org/manage_email






--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one
Mohamed Seifeddine | 12 Sep 2012 12:04
Picon

Re: [groovy-user] Groovy 3

No, I wasn't aware. I just tried them, but they didn't work :(


if ( true ) {
     String s = """I would like not to have to escape \
                        my string when I am formatting the String to get rid \
                        of the whitespace and newline and what not"""
                        
                        println s.stripMargin().stripIndent()
}

Prints 
"I would like not to have to escape                         my string when I am formatting the String to get rid                         of the whitespace and newline and what not"

Also tried: 

if ( true ) {
     String s = """I would like not to have to escape
                        my string when I am formatting the String to get rid
                        of the whitespace and newline and what not"""
                        
                        println s.stripMargin().stripIndent()
}

and with the other order : 

println s.stripIndent().stripMargin()

What am I missing?

// Moe

On Wed, Sep 12, 2012 at 11:58 AM, Guillaume Laforge <glaforge <at> codehaus.org> wrote:
Have you had a look at the stripIndent() and stripMargin() methods that Groovy adds to String?

Guillaume


On Wed, Sep 12, 2012 at 11:54 AM, Mohamed Seifeddine <mseifeddo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
Hi, 

I just came to think about something that I think would be a nice addition to Groovy Strings.

Just came about the new Dollar Slashy String and also saw that the slashy string is now multiline. 

I tried them out hoping that my case would be covered, but no.

All multiline versions fail to take into account that you might not want to keep the white space between each line, when you need to format them properly or when you have the multiline declared in indented code.

if ( true ) {
     String s = """I would like not to have to escape \
                        my string when I am formatting the String to get rid \
                        of the whitespace and newline and what not"""
}

The purpose of introducing the multiline string back in the days as I understood it was so that we did not have to "concatinate " + "strings on " + "new lines " + "making things less readable" .
I am aware of the backslash as you can see above, but it would be nice to see a multiline string that behave like the + one without having to nest ugly slashes everywhere. 

Also the above prints: 
I would like not to have to escape                         my string when I am formatting the String to get rid                         of the whitespace and newline and what not

So even if the newlines are gone with the backslash at the end of the line, the whitespace are not.

This is not really a nice option either: 

if ( true ) {
   if ( true ) {
        String s = """I would like not to have to escape \
my string when I am formatting the String to get rid \
of the whitespace and newline and what not"""
   }
}

Suggestion: 

String s = \"""My name 
               is Mohamed and I like Groo
               vy"""\

Prints: 
My name is Mohamed and I like Groovy

The tricky part is when a valid space before breaking a line is. However if white space does exist before the end of the line, ( like after My name ) then include it. It might not be quite readable though for a developer, so perhaps forcing the escape of a space at the end or start of line might be a good idea. 

String s = \"""My name \
               is Mohamed and I like Groo
               vy or escape
               \ here"""\

My two cents.

// Mohamed



On Tue, Jul 24, 2012 at 7:39 PM, Ondřej Čada <ocs-CKS8FbnQINU@public.gmane.org> wrote:
Paul,

On Jul 20, 2012, at 2:48 PM, Paul Bennett wrote:

> One thing I really miss from other dynamic languages (Ruby, Smalltalk) is polymorphic dispatch of class methods i.e. static methods in Java/Groovy. It's really convenient to be able to define a static method on a class, then override in sub-classes. I suspect that there are underlying issues in the Java VM that make this difficult, inefficient or impossible, but I don't know enough to be sure.
>
> Is it possible? I guess I would be happy to be able to add methods to the metaClass, and dispatch of that - or maybe that's possible already?

Some time ago I've played with the idea; alas I had to focus on other things and did not get back to that. Here's a copy of what I found:

===
> [...]
>> I've considered to add the 'this' argument through an AST, and at
>> the  same moment create a stub method to be called from Java -- something like
>>
>> // source code:
>> static def foo(arg1, ... argN) { ... }
>> // result of AST:
>> static def foo(Class this,arg1, ... argN) { ... }
>> static def foo(arg1, ... argN) { foo(null,arg1, ... argN) }
>
> in Groovy source (not necessarily in the AST) you can use optional arguments:
>
> static def foo(Class this=null, arg1,...argN) {...}
>
> And for you this is surely ok. Just to take this into the language I am not sure it is a good idea.

Doing it myself, I at the moment can't see a solution to

(i) catching static method invocations globally

The API does not seem to support that -- foo.metaClass.static.invokeMethod=... works for one specific class foo only.

(ii) using new dynamic 'this' automatically when calling methods

This one perhaps can be solved AST-level, but I am not quite sure at this moment.

> Where you can really have a problem is if foo is overloaded and foo takes Class as first argument one time and one time not, but everything else is the same.. for example:
>
> foo()
> foo(Class)

Right, that was exactly what I meant by

"Preferrably with some distinctive type instead of Class, so that there is never any danger of a clash with normal pair of methods like "static def foo() { ... } static def foo(Class foo) { .... }"."

Or does not Java/Groovy allow to define my own type for Class, which would contain class all right, but allowing to distinguish these two cases?

> [...]
>> To go a bit further, we need an AST. I've got alas no more time to play now, but it seems to me it should be possible (and comparatively easy) to
>>
>> - auto-add the extra Class argument to the static methods;
>> - annotate the methods so that the test above (whether to add the self argument or not) would not fail in case there happen to be more methods with different signatures in the class;
>> - prepend automatically "self." (or "this." if fixed at runtime) when calling other methods;
>> - implement "super." as simply "<superclass>." -- i.e., if "super.foo()" was used in Bar, it would turn to "Foo.foo()"; if it was used in Bar, it would turn to "Object.foo()".
>>
>> I guess there are still dark corners and potential problems, but seems to me it _might_ lead to the desired outcome. With some luck :)
>
> a transform can do the replacements, when the class is compiled, no big thing.

I fear a bit the "prepend automatically "self."" part, since I am not sure how difficult it is to determine whether it should be done or not -- compare e.g., the standard Category AST, which does something similar, and fails with the implicit 'it'.
===

All the best,
---
Ondra Čada
OCSoftware:     ocs-CKS8FbnQINU@public.gmane.org               http://www.ocs.cz
private         ondra-CKS8FbnQINU@public.gmane.org             http://www.ocs.cz/oc




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

    http://xircles.codehaus.org/manage_email






--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one

Guillaume Laforge | 12 Sep 2012 12:09
Gravatar

Re: [groovy-user] Groovy 3

Just use one or the other.

But please be sure to have a look at the JavaDoc explaining (briefly) their usage:
http://groovy.codehaus.org/groovy-jdk/java/lang/String.html#stripIndent()
In your case, I believe what you probably want stripIndent().

Guillaume

On Wed, Sep 12, 2012 at 12:04 PM, Mohamed Seifeddine <mseifeddo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
No, I wasn't aware. I just tried them, but they didn't work :(

if ( true ) {
     String s = """I would like not to have to escape \
                        my string when I am formatting the String to get rid \
                        of the whitespace and newline and what not"""
                        
                        println s.stripMargin().stripIndent()
}

Prints 
"I would like not to have to escape                         my string when I am formatting the String to get rid                         of the whitespace and newline and what not"

Also tried: 

if ( true ) {
     String s = """I would like not to have to escape
                        my string when I am formatting the String to get rid
                        of the whitespace and newline and what not"""
                        
                        println s.stripMargin().stripIndent()
}

and with the other order : 

println s.stripIndent().stripMargin()

What am I missing?

// Moe

On Wed, Sep 12, 2012 at 11:58 AM, Guillaume Laforge <glaforge <at> codehaus.org> wrote:
Have you had a look at the stripIndent() and stripMargin() methods that Groovy adds to String?

Guillaume


On Wed, Sep 12, 2012 at 11:54 AM, Mohamed Seifeddine <mseifeddo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
Hi, 

I just came to think about something that I think would be a nice addition to Groovy Strings.

Just came about the new Dollar Slashy String and also saw that the slashy string is now multiline. 

I tried them out hoping that my case would be covered, but no.

All multiline versions fail to take into account that you might not want to keep the white space between each line, when you need to format them properly or when you have the multiline declared in indented code.

if ( true ) {
     String s = """I would like not to have to escape \
                        my string when I am formatting the String to get rid \
                        of the whitespace and newline and what not"""
}

The purpose of introducing the multiline string back in the days as I understood it was so that we did not have to "concatinate " + "strings on " + "new lines " + "making things less readable" .
I am aware of the backslash as you can see above, but it would be nice to see a multiline string that behave like the + one without having to nest ugly slashes everywhere. 

Also the above prints: 
I would like not to have to escape                         my string when I am formatting the String to get rid                         of the whitespace and newline and what not

So even if the newlines are gone with the backslash at the end of the line, the whitespace are not.

This is not really a nice option either: 

if ( true ) {
   if ( true ) {
        String s = """I would like not to have to escape \
my string when I am formatting the String to get rid \
of the whitespace and newline and what not"""
   }
}

Suggestion: 

String s = \"""My name 
               is Mohamed and I like Groo
               vy"""\

Prints: 
My name is Mohamed and I like Groovy

The tricky part is when a valid space before breaking a line is. However if white space does exist before the end of the line, ( like after My name ) then include it. It might not be quite readable though for a developer, so perhaps forcing the escape of a space at the end or start of line might be a good idea. 

String s = \"""My name \
               is Mohamed and I like Groo
               vy or escape
               \ here"""\

My two cents.

// Mohamed



On Tue, Jul 24, 2012 at 7:39 PM, Ondřej Čada <ocs-CKS8FbnQINU@public.gmane.org> wrote:
Paul,

On Jul 20, 2012, at 2:48 PM, Paul Bennett wrote:

> One thing I really miss from other dynamic languages (Ruby, Smalltalk) is polymorphic dispatch of class methods i.e. static methods in Java/Groovy. It's really convenient to be able to define a static method on a class, then override in sub-classes. I suspect that there are underlying issues in the Java VM that make this difficult, inefficient or impossible, but I don't know enough to be sure.
>
> Is it possible? I guess I would be happy to be able to add methods to the metaClass, and dispatch of that - or maybe that's possible already?

Some time ago I've played with the idea; alas I had to focus on other things and did not get back to that. Here's a copy of what I found:

===
> [...]
>> I've considered to add the 'this' argument through an AST, and at
>> the  same moment create a stub method to be called from Java -- something like
>>
>> // source code:
>> static def foo(arg1, ... argN) { ... }
>> // result of AST:
>> static def foo(Class this,arg1, ... argN) { ... }
>> static def foo(arg1, ... argN) { foo(null,arg1, ... argN) }
>
> in Groovy source (not necessarily in the AST) you can use optional arguments:
>
> static def foo(Class this=null, arg1,...argN) {...}
>
> And for you this is surely ok. Just to take this into the language I am not sure it is a good idea.

Doing it myself, I at the moment can't see a solution to

(i) catching static method invocations globally

The API does not seem to support that -- foo.metaClass.static.invokeMethod=... works for one specific class foo only.

(ii) using new dynamic 'this' automatically when calling methods

This one perhaps can be solved AST-level, but I am not quite sure at this moment.

> Where you can really have a problem is if foo is overloaded and foo takes Class as first argument one time and one time not, but everything else is the same.. for example:
>
> foo()
> foo(Class)

Right, that was exactly what I meant by

"Preferrably with some distinctive type instead of Class, so that there is never any danger of a clash with normal pair of methods like "static def foo() { ... } static def foo(Class foo) { .... }"."

Or does not Java/Groovy allow to define my own type for Class, which would contain class all right, but allowing to distinguish these two cases?

> [...]
>> To go a bit further, we need an AST. I've got alas no more time to play now, but it seems to me it should be possible (and comparatively easy) to
>>
>> - auto-add the extra Class argument to the static methods;
>> - annotate the methods so that the test above (whether to add the self argument or not) would not fail in case there happen to be more methods with different signatures in the class;
>> - prepend automatically "self." (or "this." if fixed at runtime) when calling other methods;
>> - implement "super." as simply "<superclass>." -- i.e., if "super.foo()" was used in Bar, it would turn to "Foo.foo()"; if it was used in Bar, it would turn to "Object.foo()".
>>
>> I guess there are still dark corners and potential problems, but seems to me it _might_ lead to the desired outcome. With some luck :)
>
> a transform can do the replacements, when the class is compiled, no big thing.

I fear a bit the "prepend automatically "self."" part, since I am not sure how difficult it is to determine whether it should be done or not -- compare e.g., the standard Category AST, which does something similar, and fails with the implicit 'it'.
===

All the best,
---
Ondra Čada
OCSoftware:     ocs-CKS8FbnQINU@public.gmane.org               http://www.ocs.cz
private         ondra-CKS8FbnQINU@public.gmane.org             http://www.ocs.cz/oc




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

    http://xircles.codehaus.org/manage_email






--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one




--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one
Mohamed Seifeddine | 12 Sep 2012 15:24
Picon

Re: [groovy-user] Groovy 3

I see, but this doesn't seem to be what I am asking for. 


if ( true ) {
     String s = """I would like not to have to escape
                   |my string when I am formatting the String to get rid
                   |of the whitespace and newline and what not"""
                        
                        println s.stripMargin()
}

Prints:
I would like not to have to escape
my string when I am formatting the String to get rid
of the whitespace and newline and what not


As you can see the newlines are still there. 

if ( true ) {
     String s = """I would like not to have to escape \
                   |my string when I am formatting the String to get rid \
                   |of the whitespace and newline and what not"""
                        
                        println s.stripMargin()
}

Prints
I would like not to have to escape                    |my string when I am formatting the String to get rid                    |of the whitespace and newline and what not

StripIndent is not very useful. 

This will ALMOST get what I am looking for ( You might have valid newlines in between ): 

if ( true ) {
     String s = """I would like not to have to escape 
                   |my string when I am formatting the String to get rid 
                   |of the whitespace and newline and what not"""
                        
     println s.stripMargin().replaceAll("\n", "")
}

Prints
I would like not to have to escape my string when I am formatting the String to get rid of the whitespace and newline and what not




On Wed, Sep 12, 2012 at 12:09 PM, Guillaume Laforge <glaforge-yCVjj/EcxBJg9hUCZPvPmw@public.gmane.org> wrote:
Just use one or the other.
But please be sure to have a look at the JavaDoc explaining (briefly) their usage:
http://groovy.codehaus.org/groovy-jdk/java/lang/String.html#stripIndent()
In your case, I believe what you probably want stripIndent().

Guillaume


On Wed, Sep 12, 2012 at 12:04 PM, Mohamed Seifeddine <mseifeddo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
No, I wasn't aware. I just tried them, but they didn't work :(

if ( true ) {
     String s = """I would like not to have to escape \
                        my string when I am formatting the String to get rid \
                        of the whitespace and newline and what not"""
                        
                        println s.stripMargin().stripIndent()
}

Prints 
"I would like not to have to escape                         my string when I am formatting the String to get rid                         of the whitespace and newline and what not"

Also tried: 

if ( true ) {
     String s = """I would like not to have to escape
                        my string when I am formatting the String to get rid
                        of the whitespace and newline and what not"""
                        
                        println s.stripMargin().stripIndent()
}

and with the other order : 

println s.stripIndent().stripMargin()

What am I missing?

// Moe

On Wed, Sep 12, 2012 at 11:58 AM, Guillaume Laforge <glaforge <at> codehaus.org> wrote:
Have you had a look at the stripIndent() and stripMargin() methods that Groovy adds to String?

Guillaume


On Wed, Sep 12, 2012 at 11:54 AM, Mohamed Seifeddine <mseifeddo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
Hi, 

I just came to think about something that I think would be a nice addition to Groovy Strings.

Just came about the new Dollar Slashy String and also saw that the slashy string is now multiline. 

I tried them out hoping that my case would be covered, but no.

All multiline versions fail to take into account that you might not want to keep the white space between each line, when you need to format them properly or when you have the multiline declared in indented code.

if ( true ) {
     String s = """I would like not to have to escape \
                        my string when I am formatting the String to get rid \
                        of the whitespace and newline and what not"""
}

The purpose of introducing the multiline string back in the days as I understood it was so that we did not have to "concatinate " + "strings on " + "new lines " + "making things less readable" .
I am aware of the backslash as you can see above, but it would be nice to see a multiline string that behave like the + one without having to nest ugly slashes everywhere. 

Also the above prints: 
I would like not to have to escape                         my string when I am formatting the String to get rid                         of the whitespace and newline and what not

So even if the newlines are gone with the backslash at the end of the line, the whitespace are not.

This is not really a nice option either: 

if ( true ) {
   if ( true ) {
        String s = """I would like not to have to escape \
my string when I am formatting the String to get rid \
of the whitespace and newline and what not"""
   }
}

Suggestion: 

String s = \"""My name 
               is Mohamed and I like Groo
               vy"""\

Prints: 
My name is Mohamed and I like Groovy

The tricky part is when a valid space before breaking a line is. However if white space does exist before the end of the line, ( like after My name ) then include it. It might not be quite readable though for a developer, so perhaps forcing the escape of a space at the end or start of line might be a good idea. 

String s = \"""My name \
               is Mohamed and I like Groo
               vy or escape
               \ here"""\

My two cents.

// Mohamed



On Tue, Jul 24, 2012 at 7:39 PM, Ondřej Čada <ocs-CKS8FbnQINU@public.gmane.org> wrote:
Paul,

On Jul 20, 2012, at 2:48 PM, Paul Bennett wrote:

> One thing I really miss from other dynamic languages (Ruby, Smalltalk) is polymorphic dispatch of class methods i.e. static methods in Java/Groovy. It's really convenient to be able to define a static method on a class, then override in sub-classes. I suspect that there are underlying issues in the Java VM that make this difficult, inefficient or impossible, but I don't know enough to be sure.
>
> Is it possible? I guess I would be happy to be able to add methods to the metaClass, and dispatch of that - or maybe that's possible already?

Some time ago I've played with the idea; alas I had to focus on other things and did not get back to that. Here's a copy of what I found:

===
> [...]
>> I've considered to add the 'this' argument through an AST, and at
>> the  same moment create a stub method to be called from Java -- something like
>>
>> // source code:
>> static def foo(arg1, ... argN) { ... }
>> // result of AST:
>> static def foo(Class this,arg1, ... argN) { ... }
>> static def foo(arg1, ... argN) { foo(null,arg1, ... argN) }
>
> in Groovy source (not necessarily in the AST) you can use optional arguments:
>
> static def foo(Class this=null, arg1,...argN) {...}
>
> And for you this is surely ok. Just to take this into the language I am not sure it is a good idea.

Doing it myself, I at the moment can't see a solution to

(i) catching static method invocations globally

The API does not seem to support that -- foo.metaClass.static.invokeMethod=... works for one specific class foo only.

(ii) using new dynamic 'this' automatically when calling methods

This one perhaps can be solved AST-level, but I am not quite sure at this moment.

> Where you can really have a problem is if foo is overloaded and foo takes Class as first argument one time and one time not, but everything else is the same.. for example:
>
> foo()
> foo(Class)

Right, that was exactly what I meant by

"Preferrably with some distinctive type instead of Class, so that there is never any danger of a clash with normal pair of methods like "static def foo() { ... } static def foo(Class foo) { .... }"."

Or does not Java/Groovy allow to define my own type for Class, which would contain class all right, but allowing to distinguish these two cases?

> [...]
>> To go a bit further, we need an AST. I've got alas no more time to play now, but it seems to me it should be possible (and comparatively easy) to
>>
>> - auto-add the extra Class argument to the static methods;
>> - annotate the methods so that the test above (whether to add the self argument or not) would not fail in case there happen to be more methods with different signatures in the class;
>> - prepend automatically "self." (or "this." if fixed at runtime) when calling other methods;
>> - implement "super." as simply "<superclass>." -- i.e., if "super.foo()" was used in Bar, it would turn to "Foo.foo()"; if it was used in Bar, it would turn to "Object.foo()".
>>
>> I guess there are still dark corners and potential problems, but seems to me it _might_ lead to the desired outcome. With some luck :)
>
> a transform can do the replacements, when the class is compiled, no big thing.

I fear a bit the "prepend automatically "self."" part, since I am not sure how difficult it is to determine whether it should be done or not -- compare e.g., the standard Category AST, which does something similar, and fails with the implicit 'it'.
===

All the best,
---
Ondra Čada
OCSoftware:     ocs-CKS8FbnQINU@public.gmane.org               http://www.ocs.cz
private         ondra-CKS8FbnQINU@public.gmane.org             http://www.ocs.cz/oc




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

    http://xircles.codehaus.org/manage_email






--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one




--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one

Tim Yates | 12 Sep 2012 15:37
Picon
Gravatar

Re: [groovy-user] Groovy 3

Does


s.stripMargin().tr( '\n', ' ' )

Get you where you want to be?

Tim

On 12 September 2012 14:24, Mohamed Seifeddine <mseifeddo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
I see, but this doesn't seem to be what I am asking for. 

if ( true ) {
     String s = """I would like not to have to escape
                   |my string when I am formatting the String to get rid
                   |of the whitespace and newline and what not"""
                        
                        println s.stripMargin()
}

Prints:
I would like not to have to escape
my string when I am formatting the String to get rid
of the whitespace and newline and what not


As you can see the newlines are still there. 

if ( true ) {
     String s = """I would like not to have to escape \
                   |my string when I am formatting the String to get rid \
                   |of the whitespace and newline and what not"""
                        
                        println s.stripMargin()
}

Prints
I would like not to have to escape                    |my string when I am formatting the String to get rid                    |of the whitespace and newline and what not

StripIndent is not very useful. 

This will ALMOST get what I am looking for ( You might have valid newlines in between ): 

if ( true ) {
     String s = """I would like not to have to escape 
                   |my string when I am formatting the String to get rid 
                   |of the whitespace and newline and what not"""
                        
     println s.stripMargin().replaceAll("\n", "")
}

Prints
I would like not to have to escape my string when I am formatting the String to get rid of the whitespace and newline and what not




On Wed, Sep 12, 2012 at 12:09 PM, Guillaume Laforge <glaforge-yCVjj/EcxBJg9hUCZPvPmw@public.gmane.org> wrote:
Just use one or the other.
But please be sure to have a look at the JavaDoc explaining (briefly) their usage:
http://groovy.codehaus.org/groovy-jdk/java/lang/String.html#stripIndent()
In your case, I believe what you probably want stripIndent().

Guillaume


On Wed, Sep 12, 2012 at 12:04 PM, Mohamed Seifeddine <mseifeddo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
No, I wasn't aware. I just tried them, but they didn't work :(

if ( true ) {
     String s = """I would like not to have to escape \
                        my string when I am formatting the String to get rid \
                        of the whitespace and newline and what not"""
                        
                        println s.stripMargin().stripIndent()
}

Prints 
"I would like not to have to escape                         my string when I am formatting the String to get rid                         of the whitespace and newline and what not"

Also tried: 

if ( true ) {
     String s = """I would like not to have to escape
                        my string when I am formatting the String to get rid
                        of the whitespace and newline and what not"""
                        
                        println s.stripMargin().stripIndent()
}

and with the other order : 

println s.stripIndent().stripMargin()

What am I missing?

// Moe

On Wed, Sep 12, 2012 at 11:58 AM, Guillaume Laforge <glaforge <at> codehaus.org> wrote:
Have you had a look at the stripIndent() and stripMargin() methods that Groovy adds to String?

Guillaume


On Wed, Sep 12, 2012 at 11:54 AM, Mohamed Seifeddine <mseifeddo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
Hi, 

I just came to think about something that I think would be a nice addition to Groovy Strings.

Just came about the new Dollar Slashy String and also saw that the slashy string is now multiline. 

I tried them out hoping that my case would be covered, but no.

All multiline versions fail to take into account that you might not want to keep the white space between each line, when you need to format them properly or when you have the multiline declared in indented code.

if ( true ) {
     String s = """I would like not to have to escape \
                        my string when I am formatting the String to get rid \
                        of the whitespace and newline and what not"""
}

The purpose of introducing the multiline string back in the days as I understood it was so that we did not have to "concatinate " + "strings on " + "new lines " + "making things less readable" .
I am aware of the backslash as you can see above, but it would be nice to see a multiline string that behave like the + one without having to nest ugly slashes everywhere. 

Also the above prints: 
I would like not to have to escape                         my string when I am formatting the String to get rid                         of the whitespace and newline and what not

So even if the newlines are gone with the backslash at the end of the line, the whitespace are not.

This is not really a nice option either: 

if ( true ) {
   if ( true ) {
        String s = """I would like not to have to escape \
my string when I am formatting the String to get rid \
of the whitespace and newline and what not"""
   }
}

Suggestion: 

String s = \"""My name 
               is Mohamed and I like Groo
               vy"""\

Prints: 
My name is Mohamed and I like Groovy

The tricky part is when a valid space before breaking a line is. However if white space does exist before the end of the line, ( like after My name ) then include it. It might not be quite readable though for a developer, so perhaps forcing the escape of a space at the end or start of line might be a good idea. 

String s = \"""My name \
               is Mohamed and I like Groo
               vy or escape
               \ here"""\

My two cents.

// Mohamed



On Tue, Jul 24, 2012 at 7:39 PM, Ondřej Čada <ocs-CKS8FbnQINU@public.gmane.org> wrote:
Paul,

On Jul 20, 2012, at 2:48 PM, Paul Bennett wrote:

> One thing I really miss from other dynamic languages (Ruby, Smalltalk) is polymorphic dispatch of class methods i.e. static methods in Java/Groovy. It's really convenient to be able to define a static method on a class, then override in sub-classes. I suspect that there are underlying issues in the Java VM that make this difficult, inefficient or impossible, but I don't know enough to be sure.
>
> Is it possible? I guess I would be happy to be able to add methods to the metaClass, and dispatch of that - or maybe that's possible already?

Some time ago I've played with the idea; alas I had to focus on other things and did not get back to that. Here's a copy of what I found:

===
> [...]
>> I've considered to add the 'this' argument through an AST, and at
>> the  same moment create a stub method to be called from Java -- something like
>>
>> // source code:
>> static def foo(arg1, ... argN) { ... }
>> // result of AST:
>> static def foo(Class this,arg1, ... argN) { ... }
>> static def foo(arg1, ... argN) { foo(null,arg1, ... argN) }
>
> in Groovy source (not necessarily in the AST) you can use optional arguments:
>
> static def foo(Class this=null, arg1,...argN) {...}
>
> And for you this is surely ok. Just to take this into the language I am not sure it is a good idea.

Doing it myself, I at the moment can't see a solution to

(i) catching static method invocations globally

The API does not seem to support that -- foo.metaClass.static.invokeMethod=... works for one specific class foo only.

(ii) using new dynamic 'this' automatically when calling methods

This one perhaps can be solved AST-level, but I am not quite sure at this moment.

> Where you can really have a problem is if foo is overloaded and foo takes Class as first argument one time and one time not, but everything else is the same.. for example:
>
> foo()
> foo(Class)

Right, that was exactly what I meant by

"Preferrably with some distinctive type instead of Class, so that there is never any danger of a clash with normal pair of methods like "static def foo() { ... } static def foo(Class foo) { .... }"."

Or does not Java/Groovy allow to define my own type for Class, which would contain class all right, but allowing to distinguish these two cases?

> [...]
>> To go a bit further, we need an AST. I've got alas no more time to play now, but it seems to me it should be possible (and comparatively easy) to
>>
>> - auto-add the extra Class argument to the static methods;
>> - annotate the methods so that the test above (whether to add the self argument or not) would not fail in case there happen to be more methods with different signatures in the class;
>> - prepend automatically "self." (or "this." if fixed at runtime) when calling other methods;
>> - implement "super." as simply "<superclass>." -- i.e., if "super.foo()" was used in Bar, it would turn to "Foo.foo()"; if it was used in Bar, it would turn to "Object.foo()".
>>
>> I guess there are still dark corners and potential problems, but seems to me it _might_ lead to the desired outcome. With some luck :)
>
> a transform can do the replacements, when the class is compiled, no big thing.

I fear a bit the "prepend automatically "self."" part, since I am not sure how difficult it is to determine whether it should be done or not -- compare e.g., the standard Category AST, which does something similar, and fails with the implicit 'it'.
===

All the best,
---
Ondra Čada
OCSoftware:     ocs-CKS8FbnQINU@public.gmane.org               http://www.ocs.cz
private         ondra-CKS8FbnQINU@public.gmane.org             http://www.ocs.cz/oc




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

    http://xircles.codehaus.org/manage_email






--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one




--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one


Guillaume Laforge | 12 Sep 2012 15:37
Gravatar

Re: [groovy-user] Groovy 3

For stripMargin(), you must also put the margin character on the first line too.
Then, yes replaceAll, or split('\n').join()

On Wed, Sep 12, 2012 at 3:24 PM, Mohamed Seifeddine <mseifeddo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
I see, but this doesn't seem to be what I am asking for. 

if ( true ) {
     String s = """I would like not to have to escape
                   |my string when I am formatting the String to get rid
                   |of the whitespace and newline and what not"""
                        
                        println s.stripMargin()
}

Prints:
I would like not to have to escape
my string when I am formatting the String to get rid
of the whitespace and newline and what not


As you can see the newlines are still there. 


 

if ( true ) {
     String s = """I would like not to have to escape \
                   |my string when I am formatting the String to get rid \
                   |of the whitespace and newline and what not"""
                        
                        println s.stripMargin()
}

Prints
I would like not to have to escape                    |my string when I am formatting the String to get rid                    |of the whitespace and newline and what not

StripIndent is not very useful. 

This will ALMOST get what I am looking for ( You might have valid newlines in between ): 

if ( true ) {
     String s = """I would like not to have to escape 
                   |my string when I am formatting the String to get rid 
                   |of the whitespace and newline and what not"""
                        
     println s.stripMargin().replaceAll("\n", "")
}

Prints
I would like not to have to escape my string when I am formatting the String to get rid of the whitespace and newline and what not




On Wed, Sep 12, 2012 at 12:09 PM, Guillaume Laforge <glaforge-yCVjj/EcxBJg9hUCZPvPmw@public.gmane.org> wrote:
Just use one or the other.
But please be sure to have a look at the JavaDoc explaining (briefly) their usage:
http://groovy.codehaus.org/groovy-jdk/java/lang/String.html#stripIndent()
In your case, I believe what you probably want stripIndent().

Guillaume


On Wed, Sep 12, 2012 at 12:04 PM, Mohamed Seifeddine <mseifeddo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
No, I wasn't aware. I just tried them, but they didn't work :(

if ( true ) {
     String s = """I would like not to have to escape \
                        my string when I am formatting the String to get rid \
                        of the whitespace and newline and what not"""
                        
                        println s.stripMargin().stripIndent()
}

Prints 
"I would like not to have to escape                         my string when I am formatting the String to get rid                         of the whitespace and newline and what not"

Also tried: 

if ( true ) {
     String s = """I would like not to have to escape
                        my string when I am formatting the String to get rid
                        of the whitespace and newline and what not"""
                        
                        println s.stripMargin().stripIndent()
}

and with the other order : 

println s.stripIndent().stripMargin()

What am I missing?

// Moe

On Wed, Sep 12, 2012 at 11:58 AM, Guillaume Laforge <glaforge <at> codehaus.org> wrote:
Have you had a look at the stripIndent() and stripMargin() methods that Groovy adds to String?

Guillaume


On Wed, Sep 12, 2012 at 11:54 AM, Mohamed Seifeddine <mseifeddo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
Hi, 

I just came to think about something that I think would be a nice addition to Groovy Strings.

Just came about the new Dollar Slashy String and also saw that the slashy string is now multiline. 

I tried them out hoping that my case would be covered, but no.

All multiline versions fail to take into account that you might not want to keep the white space between each line, when you need to format them properly or when you have the multiline declared in indented code.

if ( true ) {
     String s = """I would like not to have to escape \
                        my string when I am formatting the String to get rid \
                        of the whitespace and newline and what not"""
}

The purpose of introducing the multiline string back in the days as I understood it was so that we did not have to "concatinate " + "strings on " + "new lines " + "making things less readable" .
I am aware of the backslash as you can see above, but it would be nice to see a multiline string that behave like the + one without having to nest ugly slashes everywhere. 

Also the above prints: 
I would like not to have to escape                         my string when I am formatting the String to get rid                         of the whitespace and newline and what not

So even if the newlines are gone with the backslash at the end of the line, the whitespace are not.

This is not really a nice option either: 

if ( true ) {
   if ( true ) {
        String s = """I would like not to have to escape \
my string when I am formatting the String to get rid \
of the whitespace and newline and what not"""
   }
}

Suggestion: 

String s = \"""My name 
               is Mohamed and I like Groo
               vy"""\

Prints: 
My name is Mohamed and I like Groovy

The tricky part is when a valid space before breaking a line is. However if white space does exist before the end of the line, ( like after My name ) then include it. It might not be quite readable though for a developer, so perhaps forcing the escape of a space at the end or start of line might be a good idea. 

String s = \"""My name \
               is Mohamed and I like Groo
               vy or escape
               \ here"""\

My two cents.

// Mohamed



On Tue, Jul 24, 2012 at 7:39 PM, Ondřej Čada <ocs-CKS8FbnQINU@public.gmane.org> wrote:
Paul,

On Jul 20, 2012, at 2:48 PM, Paul Bennett wrote:

> One thing I really miss from other dynamic languages (Ruby, Smalltalk) is polymorphic dispatch of class methods i.e. static methods in Java/Groovy. It's really convenient to be able to define a static method on a class, then override in sub-classes. I suspect that there are underlying issues in the Java VM that make this difficult, inefficient or impossible, but I don't know enough to be sure.
>
> Is it possible? I guess I would be happy to be able to add methods to the metaClass, and dispatch of that - or maybe that's possible already?

Some time ago I've played with the idea; alas I had to focus on other things and did not get back to that. Here's a copy of what I found:

===
> [...]
>> I've considered to add the 'this' argument through an AST, and at
>> the  same moment create a stub method to be called from Java -- something like
>>
>> // source code:
>> static def foo(arg1, ... argN) { ... }
>> // result of AST:
>> static def foo(Class this,arg1, ... argN) { ... }
>> static def foo(arg1, ... argN) { foo(null,arg1, ... argN) }
>
> in Groovy source (not necessarily in the AST) you can use optional arguments:
>
> static def foo(Class this=null, arg1,...argN) {...}
>
> And for you this is surely ok. Just to take this into the language I am not sure it is a good idea.

Doing it myself, I at the moment can't see a solution to

(i) catching static method invocations globally

The API does not seem to support that -- foo.metaClass.static.invokeMethod=... works for one specific class foo only.

(ii) using new dynamic 'this' automatically when calling methods

This one perhaps can be solved AST-level, but I am not quite sure at this moment.

> Where you can really have a problem is if foo is overloaded and foo takes Class as first argument one time and one time not, but everything else is the same.. for example:
>
> foo()
> foo(Class)

Right, that was exactly what I meant by

"Preferrably with some distinctive type instead of Class, so that there is never any danger of a clash with normal pair of methods like "static def foo() { ... } static def foo(Class foo) { .... }"."

Or does not Java/Groovy allow to define my own type for Class, which would contain class all right, but allowing to distinguish these two cases?

> [...]
>> To go a bit further, we need an AST. I've got alas no more time to play now, but it seems to me it should be possible (and comparatively easy) to
>>
>> - auto-add the extra Class argument to the static methods;
>> - annotate the methods so that the test above (whether to add the self argument or not) would not fail in case there happen to be more methods with different signatures in the class;
>> - prepend automatically "self." (or "this." if fixed at runtime) when calling other methods;
>> - implement "super." as simply "<superclass>." -- i.e., if "super.foo()" was used in Bar, it would turn to "Foo.foo()"; if it was used in Bar, it would turn to "Object.foo()".
>>
>> I guess there are still dark corners and potential problems, but seems to me it _might_ lead to the desired outcome. With some luck :)
>
> a transform can do the replacements, when the class is compiled, no big thing.

I fear a bit the "prepend automatically "self."" part, since I am not sure how difficult it is to determine whether it should be done or not -- compare e.g., the standard Category AST, which does something similar, and fails with the implicit 'it'.
===

All the best,
---
Ondra Čada
OCSoftware:     ocs-CKS8FbnQINU@public.gmane.org               http://www.ocs.cz
private         ondra-CKS8FbnQINU@public.gmane.org             http://www.ocs.cz/oc




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

    http://xircles.codehaus.org/manage_email






--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one




--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one




--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one
Mohamed Seifeddine | 12 Sep 2012 16:23
Picon

Re: [groovy-user] Groovy 3

<at> Tim 


Not sure, but I am not trying to do this for something particular like a task. I am recommending a feature for Groovy 3 for a String that would automatically support this usecase, rather than each of us having some strange implementation of our own. .stripMargin().tr(..) ? 
I do not want to read a doc to understand what that does, and my co-workers shouldn't either ( nor my regex below :) ). 
I am sure alot of people now indent their multiline strings in an ugly fashion just to get this behaviour. I've even seen it in the Grails source.

Here is what I came up mimicing stripMargins default | :

// Works along the way as StripMargin does:

     String s = """I would like not to have to escape 
                   | my string when I am formatting the String to get rid
                   | of the whitespace and newline and what not"""
                        
     println s.replaceAll("(?m)\\s*\$\n[ ]*\\|", "")

Prints
I would like not to have to escape my string when I am formatting the String to get rid of the whitespace and newline and what not



// I would prefer this over the above because you do not need a token at the beginning of each line: 
// A space is by default added to the end of each line, unless line ends with | which might be useful if breaking in the middle of a word

     String s = """I would like not to have to escape
                   my string when I am formatting the String to get rid whi|
                   tespace and newline and what not"""
                        
     println s.replaceAll("(?m)\\|\$\n[ ]*", "").replaceAll("(?m)\\s*\$\n[ ]*", " ") // This can be done in one regex using grouping

Prints
I would like not to have to escape my string when I am formatting the String to get rid whitespace and newline and what not

I think the latter one is most pretty. Either a method in the Groovy JDK or a new String syntax for all existing multilines ? Something like 

|""" ... """| or  |''' ---'''| or |/ .../| and etc ... 

I think it would be neat :)

Cheers, Moe
Carlos Cortinhas | 19 Sep 2012 15:48
Picon

Re: [groovy-user] Groovy 3

Hello,
Well I think this is the best place to make two requests for features to 
include in Groovy 3, or even in the Groovy 2 branch. If this is not the 
correct thread to make this requests I apologize.
The requests:
1 - Is there any possibility to include a parameter in the Closure 
objects to save the return value of a Closure when they are explicitly 
declared?
2 - This second request would be to add another parameter to the Closure 
object that would save the code of the Closure in text/string format.

For example:
Closure<Integer> c = {
     println "foo"
     return 1
}
println c.getReturnType()
println c.getCodeToString()

Output:
class java.lang.Integer
Closure<Integer> c = {
     println "foo"
     return 1
}

This is only a request, currently I'm using this in my groovy projects 
but with a Global Transformation I made.
Both features would be interesting to include. Specially the ReturnType 
would be simple enough to implement (I think) and would be quite useful.

Regards,
Carlos Cortinhas

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

    http://xircles.codehaus.org/manage_email

Jochen Theodorou | 19 Sep 2012 16:48
Picon
Gravatar

Re: [groovy-user] Groovy 3

Am 19.09.2012 15:48, schrieb Carlos Cortinhas:
> 1 - Is there any possibility to include a parameter in the Closure
> objects to save the return value of a Closure when they are explicitly
> declared?

Assuming Closure<Integer> c; would be a valid way to define the return 
type... then it would be easy, yes. But it is not.

> 2 - This second request would be to add another parameter to the Closure
> object that would save the code of the Closure in text/string format.
>
> For example:
> Closure<Integer> c = {
>      println "foo"
>      return 1
> }
> println c.getReturnType()
> println c.getCodeToString()
>
> Output:
> class java.lang.Integer
> Closure<Integer> c = {
>      println "foo"
>      return 1
> }

I of course know of why someone may want this... but what exactly is 
your motivation for this? I just want to verify that it is really what 
you need ;)

bye blackdrag

--

-- 
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org

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

    http://xircles.codehaus.org/manage_email

Carlos Cortinhas | 19 Sep 2012 18:16
Picon

Re: [groovy-user] Groovy 3

Oh ok, I did not know that would not be the valid way to define the 
return type..

As for the second feature, it would be useful for example when you have 
a method that takes a closure as parameter, and you want to inspect that 
closure before deciding on executing it or not. This was a very abstract 
example.
To tell you the truth my supervisor asked me this, and I implemented it 
with the Global AST that I mentioned before. Why he wants this I can 
only imagine, I think it has something to do with debugging, which makes 
sense. And also with the purpose of initializing other closures in 
different classes just using the String with the code, but I'm not sure 
about this last part... Tomorrow I can verify and confirm this :)

Carlos

Em 19-09-2012 15:48, Jochen Theodorou escreveu:
> Am 19.09.2012 15:48, schrieb Carlos Cortinhas:
>> 1 - Is there any possibility to include a parameter in the Closure
>> objects to save the return value of a Closure when they are explicitly
>> declared?
>
> Assuming Closure<Integer> c; would be a valid way to define the return 
> type... then it would be easy, yes. But it is not.
>
>> 2 - This second request would be to add another parameter to the Closure
>> object that would save the code of the Closure in text/string format.
>>
>> For example:
>> Closure<Integer> c = {
>>      println "foo"
>>      return 1
>> }
>> println c.getReturnType()
>> println c.getCodeToString()
>>
>> Output:
>> class java.lang.Integer
>> Closure<Integer> c = {
>>      println "foo"
>>      return 1
>> }
>
> I of course know of why someone may want this... but what exactly is 
> your motivation for this? I just want to verify that it is really what 
> you need ;)
>
> bye blackdrag
>

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

    http://xircles.codehaus.org/manage_email

Jochen Theodorou | 19 Sep 2012 20:48
Picon
Gravatar

Re: [groovy-user] Groovy 3

Am 19.09.2012 18:16, schrieb Carlos Cortinhas:
> Oh ok, I did not know that would not be the valid way to define the
> return type..

well, with  <at> CompileStatic it might be, but I think that is not 
supporting this yet.

> As for the second feature, it would be useful for example when you have
> a method that takes a closure as parameter, and you want to inspect that
> closure before deciding on executing it or not. This was a very abstract
> example.
> To tell you the truth my supervisor asked me this, and I implemented it
> with the Global AST that I mentioned before. Why he wants this I can
> only imagine, I think it has something to do with debugging, which makes
> sense. And also with the purpose of initializing other closures in
> different classes just using the String with the code, but I'm not sure
> about this last part... Tomorrow I can verify and confirm this :)

having only the text of the block will not work in many cases. If for 
example a local variable is referenced we use static scoping, but all 
other variables are dynamic scoped. With only the text of the closure, 
everything would be dynamic scoped. We have/had (I don't know anymore) a 
method getClassNode or something like that on MetaClass, allowing you to 
get the AST for a class, including those blocks if the source is 
available on the classpath. Normally that is what you want if you want 
to do something semantically.

bye blackdrag

--

-- 
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org

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

    http://xircles.codehaus.org/manage_email

Cédric Champeau | 19 Sep 2012 20:52
Picon
Gravatar

Re: [groovy-user] Groovy 3

Le 19/09/2012 20:48, Jochen Theodorou a écrit :
Am 19.09.2012 18:16, schrieb Carlos Cortinhas:
Oh ok, I did not know that would not be the valid way to define the
return type..

well, with <at> CompileStatic it might be, but I think that is not supporting this yet.
Actually, using <at> TypeChecked (thus <at> CompileStatic) on a closure, you have a node metadata that gives you the inferred return type. For example :

def foo = { 1 }

In the ClosureExpression of the right hand side, you would have a node metadata (StaticTypesMarker.INFERRED_RETURN_TYPE) which says ClassHelper.int_TYPE ;)


-- Cédric Champeau SpringSource - A Division Of VMware http://www.springsource.com/ http://twitter.com/CedricChampeau
Carlos Cortinhas | 20 Sep 2012 11:13
Picon

Re: [groovy-user] Groovy 3

Em 19-09-2012 19:48, Jochen Theodorou escreveu:
>
> having only the text of the block will not work in many cases. If for 
> example a local variable is referenced we use static scoping, but all 
> other variables are dynamic scoped. With only the text of the closure, 
> everything would be dynamic scoped. We have/had (I don't know anymore) 
> a method getClassNode or something like that on MetaClass, allowing 
> you to get the AST for a class, including those blocks if the source 
> is available on the classpath. Normally that is what you want if you 
> want to do something semantically.
>
> bye blackdrag
>
Hmm, I think I understand.
About the method getClassNode on the metaClass is still there and it was 
the first approach I tried to retrieve information about what was inside 
the closure. But it returns a null value, unless I did something wrong.. 
I was calling the method this way: c.metaClass.getClassNode()

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

    http://xircles.codehaus.org/manage_email

Mohamed Seifeddine | 29 Sep 2012 21:01
Picon

Re: [groovy-user] Groovy 3

Carlos, it sounds like you are asking for something like this, statically typed Closures: 

Although the above is for the Java language, I am sure it can easily be turned into a Groovy closure.

// Mo



On Thu, Sep 20, 2012 at 11:13 AM, Carlos Cortinhas <ccort-oe7qfRrRQfcmha6Ds7sm0l6hYfS7NtTn@public.gmane.org> wrote:
Em 19-09-2012 19:48, Jochen Theodorou escreveu:


having only the text of the block will not work in many cases. If for example a local variable is referenced we use static scoping, but all other variables are dynamic scoped. With only the text of the closure, everything would be dynamic scoped. We have/had (I don't know anymore) a method getClassNode or something like that on MetaClass, allowing you to get the AST for a class, including those blocks if the source is available on the classpath. Normally that is what you want if you want to do something semantically.

bye blackdrag

Hmm, I think I understand.
About the method getClassNode on the metaClass is still there and it was the first approach I tried to retrieve information about what was inside the closure. But it returns a null value, unless I did something wrong.. I was calling the method this way: c.metaClass.getClassNode()


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

   http://xircles.codehaus.org/manage_email



Carlos Cortinhas | 8 Oct 2012 12:30
Picon

Re: [groovy-user] Groovy 3

Hello and I'm sorry to bring this up again, just one question.
Earlier Jochen said:

> Em 19-09-2012 15:48, Jochen Theodorou escreveu:
>> Assuming Closure<Integer> c; would be a valid way to define the
>> return type... then it would be easy, yes. But it is not.

And currently  <at> CompileStatic takes this as the return parameter of a
Closure. So the question is: is this going to be temporary just to work
with static compilation? And are you thinking on a new and valid way of
declaring the return type?

My question would be if this is going to stay in Groovy 3 as it is now,
but perhaps it's too soon to ask.
Carlos

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

    http://xircles.codehaus.org/manage_email

Jochen Theodorou | 8 Oct 2012 13:08
Picon
Gravatar

Re: [groovy-user] Groovy 3

Am 08.10.2012 12:30, schrieb Carlos Cortinhas:
> Hello and I'm sorry to bring this up again, just one question.
> Earlier Jochen said:
>
>> Em 19-09-2012 15:48, Jochen Theodorou escreveu:
>>> Assuming Closure<Integer> c; would be a valid way to define the
>>> return type... then it would be easy, yes. But it is not.
>
> And currently  <at> CompileStatic takes this as the return parameter of a
> Closure.

You are a bit wrong. It is no return parameter for the Closure, it is 
the type of the Closure and exists only during compilation. It is not 
really existing so to say

bye blackdrag
--

-- 
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org

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

    http://xircles.codehaus.org/manage_email

Mohamed Seifeddine | 30 Oct 2012 10:54
Picon

Re: [groovy-user] Groovy 3


Feature recommendation: 

Support for nested comments: 

/**
method1() { ... }

/*
mymethod() { .. }
*/

method2() { ... }

method3() { ... }
**/

The problem often is that you either have to use the // to comment on each line which is ugly, harder to read, and a bit harder to copy and paste, but if you use /* */ ... and you decide to comment a bigger chunk around it, you often have to uncomment the "nested" one to support this. In Java, XML, HTML and so on... nothing new.

What if groovy supported nested comments by forcing close comment section by the same as the one opened? /* ... */ , /** ... **/, /*** ... ***/ and so on.Having only /* ... ***/ would still close on the first one, unless there is an unclosed /*** so I don't think that will break the current way and backwards compatibility, otherwise you might need to introduce a new style comment with something other than a star *.

GSP's support a couple of ways to comment, which is handy, but has some limitation, what if we had a general way, rather than multiple DIFFERENT ways?

// Mo


On Mon, Oct 8, 2012 at 1:08 PM, Jochen Theodorou <blackdrag-BA+cFGlbTmA@public.gmane.org> wrote:
Am 08.10.2012 12:30, schrieb Carlos Cortinhas:

Hello and I'm sorry to bring this up again, just one question.
Earlier Jochen said:

Em 19-09-2012 15:48, Jochen Theodorou escreveu:
Assuming Closure<Integer> c; would be a valid way to define the
return type... then it would be easy, yes. But it is not.

And currently <at> CompileStatic takes this as the return parameter of a
Closure.

You are a bit wrong. It is no return parameter for the Closure, it is the type of the Closure and exists only during compilation. It is not really existing so to say


bye blackdrag
--
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org


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

   http://xircles.codehaus.org/manage_email



Jochen Theodorou | 12 Sep 2012 13:40
Picon
Gravatar

Re: [groovy-user] Groovy 3

Am 12.09.2012 11:54, schrieb Mohamed Seifeddine:
[...]
> The purpose of introducing the multiline string back in the days as I
> understood it was so that we did not have to "concatinate " + "strings
> on " + "new lines " + "making things less readable" .

That's wrong. The purpose of multiline strings back in the days was to 
replace the heredoc synax (http://en.wikipedia.org/wiki/Here_document). 
Heredoc's purpose is to be able to have continuous text blocks, 
including all whitespace and newlines.

bye blackdrag

--

-- 
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org

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

    http://xircles.codehaus.org/manage_email

UEHARA Junji | 3 Oct 2012 09:02
Picon
Gravatar

Re: [groovy-user] Groovy 3

Hello,

This is very small idea of groovy, and maybe syntax matter,
so I apologize if this is not correct topic for this thread.

My request is "safe navigation operator for array index reference".

For example:

  String[] array = null
  assert array?[10] == null   // ?[ .. ] is new syntax

This notation 'foo?[..]' is just syntax sugar of  'foo?.getAt(..)'.
So safe navigation is very convenient and simple that
I also want to use it on array or list.

Best regards,

2012/6/26 Jochen Theodorou <blackdrag@...>:
> Hi all,
>
> soon Groovy 2 will be released and I will start on working for Groovy 3,
> which is supposed to get released next year. Groovy 3 will contain a new MOP
> and some semantic changes. I thought I start a GEP (GEP-11) for this to make
> it more easy for people to contribute. I only just started the with some
> things I want not to have anymore in Groovy3. I will soon try to describe
> the new MOP. But most probably that will be in constant flux, since I will
> have to see if things work out right or not while I implement it.
>
> So anyone who wants something absolutely in Groovy3 regarding semantics or
> the new MOP.. it would be a good time to speak now... for example in this
> thread. I will collect the ideas on the wiki page of the GEP and possibly
> make them part of that "design document".
>
> Those who want some syntactic changes, sorry, they will not be part of that
> GEP.
>
>  <at> see
> http://docs.codehaus.org/display/GroovyJSR/GEP+11+-+Groovy+3+semantics+and+new+MOP
>
> bye blackdrag
>
> --
> Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
> blog: http://blackdragsview.blogspot.com/
> german groovy discussion newsgroup: de.comp.lang.misc
> For Groovy programming sources visit http://groovy-lang.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>

--

-- 
UEHARA Junji

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

    http://xircles.codehaus.org/manage_email

Scholz. Ulrich | 8 Oct 2012 15:06
Picon
Favicon

[groovy-user] Groovy and cltool4j: Unable to instantiate target class

Dear all,

 

I’d like to use Groovy to write own shell commands. To ease the command definition, I’d like to use cltool4j, “a simple framework intended to speed development of command-line tools in Java.“

 

Now, If I run the cltool4j example (on the website http://code.google.com/p/cltool4j/) as Java application, it works fine. But if I run it as Groovy script (with ending .groovy) I get

 

Unable to instantiate target class: sun.reflect.NativeMethodAccessorImpl.<init>()

 

Why that?  Thanks, Ulrich




...

     


SEEBURGER AG   Vorstand/Seeburger Executive Board:
Sitz der Gesellschaft/Registered Office:   Bernd Seeburger, Axel Haas, Michael Kleeberg
Edisonstr. 1  
D-75015 Bretten Vorsitzender des Aufsichtsrats/Chairperson of the Seeburger Supervisory Board:
Tel.: 07252 / 96 - 0 Dr. Franz Scherer
Fax: 07252 / 96 - 2222
Internet: http://www.seeburger.de Registergericht/Commercial Register:
e-mail: info-dFjtzhuVO4pM7kwft8N7nw@public.gmane.org HRB 240708 Mannheim


Dieses E-Mail ist nur für den Empfänger bestimmt, an den es gerichtet ist und kann vertrauliches bzw. unter das Berufsgeheimnis fallendes Material enthalten. Jegliche darin enthaltene Ansicht oder Meinungsäußerung ist die des Autors und stellt nicht notwendigerweise die Ansicht oder Meinung der SEEBURGER AG dar. Sind Sie nicht der Empfänger, so haben Sie diese E-Mail irrtümlich erhalten und jegliche Verwendung, Veröffentlichung, Weiterleitung, Abschrift oder jeglicher Druck dieser E-Mail ist strengstens untersagt. Weder die SEEBURGER AG noch der Absender ( Scholz. Ulrich ) übernehmen die Haftung für Viren; es obliegt Ihrer Verantwortung, die E-Mail und deren Anhänge auf Viren zu prüfen.

The present email addresses only the addressee which it targets and may contain confidential material that may be protected by the professional secret. The opinions reflected herein are not necessarily the one of the SEEBURGER AG. If you are not the addressee, you have accidentally got this email and are not enabled to use, publish, forward, copy or print it in any way. Neither SEEBURGER AG , nor the sender (Scholz. Ulrich) are liable for viruses, being your own responsibility to check this email and its attachments for this purpose.

Guillaume Laforge | 8 Oct 2012 15:16
Gravatar

Re: [groovy-user] Groovy and cltool4j: Unable to instantiate target class

Hi Ulrich,


Perhaps you give the version of Java, of Groovy, that you are using. Also the full stacktrace might be good.
And when you say you tried the example, this is the big example we see on the link you posted below?

Guillaume

On Mon, Oct 8, 2012 at 3:06 PM, Scholz. Ulrich <u.scholz-dFjtzhuVO4pM7kwft8N7nw@public.gmane.org> wrote:

Dear all,

 

I’d like to use Groovy to write own shell commands. To ease the command definition, I’d like to use cltool4j, “a simple framework intended to speed development of command-line tools in Java.“

 

Now, If I run the cltool4j example (on the website http://code.google.com/p/cltool4j/) as Java application, it works fine. But if I run it as Groovy script (with ending .groovy) I get

 

Unable to instantiate target class: sun.reflect.NativeMethodAccessorImpl.<init>()

 

Why that?  Thanks, Ulrich




...

     


SEEBURGER AG   Vorstand/Seeburger Executive Board:
Sitz der Gesellschaft/Registered Office:   Bernd Seeburger, Axel Haas, Michael Kleeberg
Edisonstr. 1  
D-75015 Bretten Vorsitzender des Aufsichtsrats/Chairperson of the Seeburger Supervisory Board:
Tel.: 07252 / 96 - 0 Dr. Franz Scherer
Fax: 07252 / 96 - 2222
Internet: http://www.seeburger.de Registergericht/Commercial Register:
e-mail: info-dFjtzhuVO4pM7kwft8N7nw@public.gmane.org HRB 240708 Mannheim


Dieses E-Mail ist nur für den Empfänger bestimmt, an den es gerichtet ist und kann vertrauliches bzw. unter das Berufsgeheimnis fallendes Material enthalten. Jegliche darin enthaltene Ansicht oder Meinungsäußerung ist die des Autors und stellt nicht notwendigerweise die Ansicht oder Meinung der SEEBURGER AG dar. Sind Sie nicht der Empfänger, so haben Sie diese E-Mail irrtümlich erhalten und jegliche Verwendung, Veröffentlichung, Weiterleitung, Abschrift oder jeglicher Druck dieser E-Mail ist strengstens untersagt. Weder die SEEBURGER AG noch der Absender ( Scholz. Ulrich ) übernehmen die Haftung für Viren; es obliegt Ihrer Verantwortung, die E-Mail und deren Anhänge auf Viren zu prüfen.

The present email addresses only the addressee which it targets and may contain confidential material that may be protected by the professional secret. The opinions reflected herein are not necessarily the one of the SEEBURGER AG. If you are not the addressee, you have accidentally got this email and are not enabled to use, publish, forward, copy or print it in any way. Neither SEEBURGER AG , nor the sender (Scholz. Ulrich) are liable for viruses, being your own responsibility to check this email and its attachments for this purpose.




--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one
Guillaume Laforge | 8 Oct 2012 15:22
Gravatar

Re: [groovy-user] Groovy and cltool4j: Unable to instantiate target class

And by the way, Groovy comes with its "CliBuilder" which allows you to build such tools.


Here are a few examples of usage:
http://pleac.sourceforge.net/pleac_groovy/userinterfaces.html

Guillaume

On Mon, Oct 8, 2012 at 3:16 PM, Guillaume Laforge <glaforge-yCVjj/EcxBJg9hUCZPvPmw@public.gmane.org> wrote:
Hi Ulrich,

Perhaps you give the version of Java, of Groovy, that you are using. Also the full stacktrace might be good.
And when you say you tried the example, this is the big example we see on the link you posted below?

Guillaume


On Mon, Oct 8, 2012 at 3:06 PM, Scholz. Ulrich <u.scholz <at> seeburger.de> wrote:

Dear all,

 

I’d like to use Groovy to write own shell commands. To ease the command definition, I’d like to use cltool4j, “a simple framework intended to speed development of command-line tools in Java.“

 

Now, If I run the cltool4j example (on the website http://code.google.com/p/cltool4j/) as Java application, it works fine. But if I run it as Groovy script (with ending .groovy) I get

 

Unable to instantiate target class: sun.reflect.NativeMethodAccessorImpl.<init>()

 

Why that?  Thanks, Ulrich




...

     


SEEBURGER AG   Vorstand/Seeburger Executive Board:
Sitz der Gesellschaft/Registered Office:   Bernd Seeburger, Axel Haas, Michael Kleeberg
Edisonstr. 1  
D-75015 Bretten Vorsitzender des Aufsichtsrats/Chairperson of the Seeburger Supervisory Board:
Tel.: 07252 / 96 - 0 Dr. Franz Scherer
Fax: 07252 / 96 - 2222
Internet: http://www.seeburger.de Registergericht/Commercial Register:
e-mail: info-dFjtzhuVO4pM7kwft8N7nw@public.gmane.org HRB 240708 Mannheim


Dieses E-Mail ist nur für den Empfänger bestimmt, an den es gerichtet ist und kann vertrauliches bzw. unter das Berufsgeheimnis fallendes Material enthalten. Jegliche darin enthaltene Ansicht oder Meinungsäußerung ist die des Autors und stellt nicht notwendigerweise die Ansicht oder Meinung der SEEBURGER AG dar. Sind Sie nicht der Empfänger, so haben Sie diese E-Mail irrtümlich erhalten und jegliche Verwendung, Veröffentlichung, Weiterleitung, Abschrift oder jeglicher Druck dieser E-Mail ist strengstens untersagt. Weder die SEEBURGER AG noch der Absender ( Scholz. Ulrich ) übernehmen die Haftung für Viren; es obliegt Ihrer Verantwortung, die E-Mail und deren Anhänge auf Viren zu prüfen.

The present email addresses only the addressee which it targets and may contain confidential material that may be protected by the professional secret. The opinions reflected herein are not necessarily the one of the SEEBURGER AG. If you are not the addressee, you have accidentally got this email and are not enabled to use, publish, forward, copy or print it in any way. Neither SEEBURGER AG , nor the sender (Scholz. Ulrich) are liable for viruses, being your own responsibility to check this email and its attachments for this purpose.




--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one



--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one
Scholz. Ulrich | 9 Oct 2012 14:11
Picon
Favicon

AW: [groovy-user] Groovy and cltool4j: Unable to instantiate target class

Hi Guillaume, thanks for pointing to CliBuilder. I will ask for it in a separate thread.

 

Yes, I was trying to use the class Jgrep as given on the web page. I created a groovy class in Eclipse, copied the code, and ran it with Run as > Groovy script. 

Then the error appears but no stack trace. Nothing else.

 

Java: 1.6.0_33

Groovy: 2.0.2

 

Best, Ulrich

 

Von: Guillaume Laforge [mailto:glaforge-yCVjj/EcxBJg9hUCZPvPmw@public.gmane.org]
Gesendet: Montag, 8. Oktober 2012 15:23
An: user-i9PBDF1N6cxnkHa44VUL00B+6BGkLq7r@public.gmane.org
Betreff: Re: [groovy-user] Groovy and cltool4j: Unable to instantiate target class

 

[…]

 

On Mon, Oct 8, 2012 at 3:16 PM, Guillaume Laforge <glaforge-yCVjj/EcxBJg9hUCZPvPmw@public.gmane.org> wrote:

Hi Ulrich,

 

Perhaps you give the version of Java, of Groovy, that you are using. Also the full stacktrace might be good.

And when you say you tried the example, this is the big example we see on the link you posted below?

 

Guillaume

 

On Mon, Oct 8, 2012 at 3:06 PM, Scholz. Ulrich <u.scholz <at> seeburger.de> wrote:

Dear all,

I’d like to use Groovy to write own shell commands. To ease the command definition, I’d like to use cltool4j, “a simple framework intended to speed development of command-line tools in Java.“

Now, If I run the cltool4j example (on the website http://code.google.com/p/cltool4j/) as Java application, it works fine. But if I run it as Groovy script (with ending .groovy) I get

Unable to instantiate target class: sun.reflect.NativeMethodAccessorImpl.<init>()

Why that?  Thanks, Ulrich

--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one




...

     


SEEBURGER AG   Vorstand/Seeburger Executive Board:
Sitz der Gesellschaft/Registered Office:   Bernd Seeburger, Axel Haas, Michael Kleeberg
Edisonstr. 1  
D-75015 Bretten Vorsitzender des Aufsichtsrats/Chairperson of the Seeburger Supervisory Board:
Tel.: 07252 / 96 - 0 Dr. Franz Scherer
Fax: 07252 / 96 - 2222
Internet: http://www.seeburger.de Registergericht/Commercial Register:
e-mail: info-dFjtzhuVO4pM7kwft8N7nw@public.gmane.org HRB 240708 Mannheim


Dieses E-Mail ist nur für den Empfänger bestimmt, an den es gerichtet ist und kann vertrauliches bzw. unter das Berufsgeheimnis fallendes Material enthalten. Jegliche darin enthaltene Ansicht oder Meinungsäußerung ist die des Autors und stellt nicht notwendigerweise die Ansicht oder Meinung der SEEBURGER AG dar. Sind Sie nicht der Empfänger, so haben Sie diese E-Mail irrtümlich erhalten und jegliche Verwendung, Veröffentlichung, Weiterleitung, Abschrift oder jeglicher Druck dieser E-Mail ist strengstens untersagt. Weder die SEEBURGER AG noch der Absender ( Scholz. Ulrich ) übernehmen die Haftung für Viren; es obliegt Ihrer Verantwortung, die E-Mail und deren Anhänge auf Viren zu prüfen.

The present email addresses only the addressee which it targets and may contain confidential material that may be protected by the professional secret. The opinions reflected herein are not necessarily the one of the SEEBURGER AG. If you are not the addressee, you have accidentally got this email and are not enabled to use, publish, forward, copy or print it in any way. Neither SEEBURGER AG , nor the sender (Scholz. Ulrich) are liable for viruses, being your own responsibility to check this email and its attachments for this purpose.

Guillaume Laforge | 9 Oct 2012 16:53
Gravatar

Re: [groovy-user] Groovy and cltool4j: Unable to instantiate target class

I tried renaming that Java file from the front page of the project to .groovy, and then run it with the jar of the library on the classpath, but I used the -d flag for having some more verbose output. And the results below are strange, as if the annotation classes from that library jar had some issue of some sort and the groovy compiler wouldn't find them in the jar (although they seem to be):


glaforge-mbp:tmp glaforge$ groovy -d -cp ~/Downloads/cltool4j.jar Jgrep
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
/private/tmp/Jgrep.groovy: 5: unable to resolve class BaseCommandlineTool 
  <at> line 5, column 1.
   public class Jgrep extends BaseCommandlineTool {
   ^
org.codehaus.groovy.syntax.SyntaxException: unable to resolve class BaseCommandlineTool 
  <at> line 5, column 1.
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:146)
at org.codehaus.groovy.control.ResolveVisitor.resolveOrFail(ResolveVisitor.java:222)
at org.codehaus.groovy.control.ResolveVisitor.resolveOrFail(ResolveVisitor.java:232)
at org.codehaus.groovy.control.ResolveVisitor.resolveOrFail(ResolveVisitor.java:228)
at org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:1168)
at org.codehaus.groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:141)
at org.codehaus.groovy.control.CompilationUnit$9.call(CompilationUnit.java:624)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:903)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:566)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:515)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:279)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:258)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:244)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:185)
at groovy.lang.GroovyShell$2.run(GroovyShell.java:206)
at groovy.lang.GroovyShell$2.run(GroovyShell.java:204)
at java.security.AccessController.doPrivileged(Native Method)
at groovy.lang.GroovyShell.run(GroovyShell.java:204)
at groovy.lang.GroovyShell.run(GroovyShell.java:150)
at groovy.ui.GroovyMain.processOnce(GroovyMain.java:557)
at groovy.ui.GroovyMain.run(GroovyMain.java:344)
at groovy.ui.GroovyMain.process(GroovyMain.java:330)
at groovy.ui.GroovyMain.processArgs(GroovyMain.java:119)
at groovy.ui.GroovyMain.main(GroovyMain.java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:106)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:128)

/private/tmp/Jgrep.groovy: 7: unable to resolve class Option ,  unable to find class for annotation
  <at> line 7, column 5.
        <at> Option(name = "-C", metaVar = "lines", usage = "Print lines of context following a match")
       ^
org.codehaus.groovy.syntax.SyntaxException: unable to resolve class Option ,  unable to find class for annotation
  <at> line 7, column 5.
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:146)
at org.codehaus.groovy.control.ResolveVisitor.resolveOrFail(ResolveVisitor.java:222)
at org.codehaus.groovy.control.ResolveVisitor.visitAnnotations(ResolveVisitor.java:1042)
at org.codehaus.groovy.ast.ClassCodeExpressionTransformer.visitField(ClassCodeExpressionTransformer.java:63)
at org.codehaus.groovy.control.ResolveVisitor.visitField(ResolveVisitor.java:178)
at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1048)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:50)
at org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:1176)
at org.codehaus.groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:141)
at org.codehaus.groovy.control.CompilationUnit$9.call(CompilationUnit.java:624)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:903)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:566)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:515)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:279)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:258)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:244)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:185)
at groovy.lang.GroovyShell$2.run(GroovyShell.java:206)
at groovy.lang.GroovyShell$2.run(GroovyShell.java:204)
at java.security.AccessController.doPrivileged(Native Method)
at groovy.lang.GroovyShell.run(GroovyShell.java:204)
at groovy.lang.GroovyShell.run(GroovyShell.java:150)
at groovy.ui.GroovyMain.processOnce(GroovyMain.java:557)
at groovy.ui.GroovyMain.run(GroovyMain.java:344)
at groovy.ui.GroovyMain.process(GroovyMain.java:330)
at groovy.ui.GroovyMain.processArgs(GroovyMain.java:119)
at groovy.ui.GroovyMain.main(GroovyMain.java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:106)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:128)

/private/tmp/Jgrep.groovy: 11: unable to resolve class Option ,  unable to find class for annotation
  <at> line 11, column 5.
        <at> Option(name = "-i", usage = "invert match")
       ^
org.codehaus.groovy.syntax.SyntaxException: unable to resolve class Option ,  unable to find class for annotation
  <at> line 11, column 5.
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:146)
at org.codehaus.groovy.control.ResolveVisitor.resolveOrFail(ResolveVisitor.java:222)
at org.codehaus.groovy.control.ResolveVisitor.visitAnnotations(ResolveVisitor.java:1042)
at org.codehaus.groovy.ast.ClassCodeExpressionTransformer.visitField(ClassCodeExpressionTransformer.java:63)
at org.codehaus.groovy.control.ResolveVisitor.visitField(ResolveVisitor.java:178)
at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1048)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:50)
at org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:1176)
at org.codehaus.groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:141)
at org.codehaus.groovy.control.CompilationUnit$9.call(CompilationUnit.java:624)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:903)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:566)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:515)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:279)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:258)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:244)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:185)
at groovy.lang.GroovyShell$2.run(GroovyShell.java:206)
at groovy.lang.GroovyShell$2.run(GroovyShell.java:204)
at java.security.AccessController.doPrivileged(Native Method)
at groovy.lang.GroovyShell.run(GroovyShell.java:204)
at groovy.lang.GroovyShell.run(GroovyShell.java:150)
at groovy.ui.GroovyMain.processOnce(GroovyMain.java:557)
at groovy.ui.GroovyMain.run(GroovyMain.java:344)
at groovy.ui.GroovyMain.process(GroovyMain.java:330)
at groovy.ui.GroovyMain.processArgs(GroovyMain.java:119)
at groovy.ui.GroovyMain.main(GroovyMain.java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:106)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:128)

/private/tmp/Jgrep.groovy: 16: unable to resolve class Argument ,  unable to find class for annotation
  <at> line 16, column 5.
        <at> Argument(index = 0, required = true, metaVar = "pattern")
       ^
org.codehaus.groovy.syntax.SyntaxException: unable to resolve class Argument ,  unable to find class for annotation
  <at> line 16, column 5.
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:146)
at org.codehaus.groovy.control.ResolveVisitor.resolveOrFail(ResolveVisitor.java:222)
at org.codehaus.groovy.control.ResolveVisitor.visitAnnotations(ResolveVisitor.java:1042)
at org.codehaus.groovy.ast.ClassCodeExpressionTransformer.visitField(ClassCodeExpressionTransformer.java:63)
at org.codehaus.groovy.control.ResolveVisitor.visitField(ResolveVisitor.java:178)
at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1048)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:50)
at org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:1176)
at org.codehaus.groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:141)
at org.codehaus.groovy.control.CompilationUnit$9.call(CompilationUnit.java:624)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:903)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:566)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:515)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:279)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:258)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:244)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:185)
at groovy.lang.GroovyShell$2.run(GroovyShell.java:206)
at groovy.lang.GroovyShell$2.run(GroovyShell.java:204)
at java.security.AccessController.doPrivileged(Native Method)
at groovy.lang.GroovyShell.run(GroovyShell.java:204)
at groovy.lang.GroovyShell.run(GroovyShell.java:150)
at groovy.ui.GroovyMain.processOnce(GroovyMain.java:557)
at groovy.ui.GroovyMain.run(GroovyMain.java:344)
at groovy.ui.GroovyMain.process(GroovyMain.java:330)
at groovy.ui.GroovyMain.processArgs(GroovyMain.java:119)
at groovy.ui.GroovyMain.main(GroovyMain.java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:106)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:128)

4 errors


On Tue, Oct 9, 2012 at 2:11 PM, Scholz. Ulrich <u.scholz <at> seeburger.de> wrote:

Hi Guillaume, thanks for pointing to CliBuilder. I will ask for it in a separate thread.

 

Yes, I was trying to use the class Jgrep as given on the web page. I created a groovy class in Eclipse, copied the code, and ran it with Run as > Groovy script. 

Then the error appears but no stack trace. Nothing else.

 

Java: 1.6.0_33

Groovy: 2.0.2

 

Best, Ulrich

 

Von: Guillaume Laforge [mailto:glaforge-yCVjj/EcxBJg9hUCZPvPmw@public.gmane.org]
Gesendet: Montag, 8. Oktober 2012 15:23
An: user-i9PBDF1N6cxnkHa44VUL00B+6BGkLq7r@public.gmane.org
Betreff: Re: [groovy-user] Groovy and cltool4j: Unable to instantiate target class

 

[…]

 

On Mon, Oct 8, 2012 at 3:16 PM, Guillaume Laforge <glaforge-yCVjj/EcxBJg9hUCZPvPmw@public.gmane.org> wrote:

Hi Ulrich,

 

Perhaps you give the version of Java, of Groovy, that you are using. Also the full stacktrace might be good.

And when you say you tried the example, this is the big example we see on the link you posted below?

 

Guillaume

 

On Mon, Oct 8, 2012 at 3:06 PM, Scholz. Ulrich <u.scholz <at> seeburger.de> wrote:

Dear all,

I’d like to use Groovy to write own shell commands. To ease the command definition, I’d like to use cltool4j, “a simple framework intended to speed development of command-line tools in Java.“

Now, If I run the cltool4j example (on the website http://code.google.com/p/cltool4j/) as Java application, it works fine. But if I run it as Groovy script (with ending .groovy) I get

Unable to instantiate target class: sun.reflect.NativeMethodAccessorImpl.<init>()

Why that?  Thanks, Ulrich

--

Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one




...

     


SEEBURGER AG   Vorstand/Seeburger Executive Board:
Sitz der Gesellschaft/Registered Office:   Bernd Seeburger, Axel Haas, Michael Kleeberg
Edisonstr. 1  
D-75015 Bretten Vorsitzender des Aufsichtsrats/Chairperson of the Seeburger Supervisory Board:
Tel.: 07252 / 96 - 0 Dr. Franz Scherer
Fax: 07252 / 96 - 2222
Internet: http://www.seeburger.de Registergericht/Commercial Register:
e-mail: info-dFjtzhuVO4pM7kwft8N7nw@public.gmane.org HRB 240708 Mannheim


Dieses E-Mail ist nur für den Empfänger bestimmt, an den es gerichtet ist und kann vertrauliches bzw. unter das Berufsgeheimnis fallendes Material enthalten. Jegliche darin enthaltene Ansicht oder Meinungsäußerung ist die des Autors und stellt nicht notwendigerweise die Ansicht oder Meinung der SEEBURGER AG dar. Sind Sie nicht der Empfänger, so haben Sie diese E-Mail irrtümlich erhalten und jegliche Verwendung, Veröffentlichung, Weiterleitung, Abschrift oder jeglicher Druck dieser E-Mail ist strengstens untersagt. Weder die SEEBURGER AG noch der Absender ( Scholz. Ulrich ) übernehmen die Haftung für Viren; es obliegt Ihrer Verantwortung, die E-Mail und deren Anhänge auf Viren zu prüfen.

The present email addresses only the addressee which it targets and may contain confidential material that may be protected by the professional secret. The opinions reflected herein are not necessarily the one of the SEEBURGER AG. If you are not the addressee, you have accidentally got this email and are not enabled to use, publish, forward, copy or print it in any way. Neither SEEBURGER AG , nor the sender (Scholz. Ulrich) are liable for viruses, being your own responsibility to check this email and its attachments for this purpose.




--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one
Scholz. Ulrich | 9 Oct 2012 15:10
Picon
Favicon

[groovy-user] groovysh and new classes/commands

Dear all,

 

For my company I have to create a shell that, upon startup, offers some custom commands and is extensible during runtime. We develop our custom commands in Java. The Groovy shell groovysh seems to be a good candidate. But it’s hard for me to get things going.

 

I develop Groovy classes with Eclipse and use Groovy Shell (2.0.2, JVM: 1.6.0_33)

 

Things work if I enter a class on the command line, create an object of that class, and execute it, as described on http://groovy.codehaus.org/Groovy+Shell under Multi-line Expressions, Defining a Class.

Also, I can create a Groovy class in Eclipse and run it with Run as >  Groovy script, although without additional arguments (args[] is an empty array).

 

1.       How do I load a class developed with Eclipse into groovysh such that I can execute it? The class I use is given below. The load command gives an error. 

2.       In the end, I’d like to package all Groovy and Java code of a command together with the required libraries in one zip/jar/… and deploy it to groovysh. Is Groovy/groovysh the tool I’m looking for.

 

I’d appreciate pointers to documentation.

 

Thanks, Ulrich

 

--------------

import org.codehaus.groovy.tools.shell.Groovysh

 

//package com.seeburger.seeshell.log.groovy

 

 

class TestThree

{

    public TestThree(Groovysh xxx)

    {    }

 

    public static void main(String[] args) {

        if(args == null)

        {

            System.out.println ("hello world")

        }

        else if (args != null && args.size() == 0)

        {

            System.out.println ("hello world2")

        }

        else

        {

            System.out.println ("hello world: " + args[0])

        }

    }

}

-------------------

groovy:000> load D:\Workspace\SeeShell\SeeShell\LogCommandsGroovy\src\main\groovy\com\seeburger\seeshell\log\groovy\TestThree.groovy

===> [import org.codehaus.groovy.tools.shell.Groovysh]

===> true

ERROR org.codehaus.groovy.control.MultipleCompilationErrorsException:

startup failed:

groovysh_parse: 5: unexpected token: } <at> line 5, column 10.

       {    }

            ^

 

1 error

 

        at java_lang_Runnable$run.call (Unknown Source)




...

     


SEEBURGER AG   Vorstand/Seeburger Executive Board:
Sitz der Gesellschaft/Registered Office:   Bernd Seeburger, Axel Haas, Michael Kleeberg
Edisonstr. 1  
D-75015 Bretten Vorsitzender des Aufsichtsrats/Chairperson of the Seeburger Supervisory Board:
Tel.: 07252 / 96 - 0 Dr. Franz Scherer
Fax: 07252 / 96 - 2222
Internet: http://www.seeburger.de Registergericht/Commercial Register:
e-mail: info-dFjtzhuVO4pM7kwft8N7nw@public.gmane.org HRB 240708 Mannheim


Dieses E-Mail ist nur für den Empfänger bestimmt, an den es gerichtet ist und kann vertrauliches bzw. unter das Berufsgeheimnis fallendes Material enthalten. Jegliche darin enthaltene Ansicht oder Meinungsäußerung ist die des Autors und stellt nicht notwendigerweise die Ansicht oder Meinung der SEEBURGER AG dar. Sind Sie nicht der Empfänger, so haben Sie diese E-Mail irrtümlich erhalten und jegliche Verwendung, Veröffentlichung, Weiterleitung, Abschrift oder jeglicher Druck dieser E-Mail ist strengstens untersagt. Weder die SEEBURGER AG noch der Absender ( Scholz. Ulrich ) übernehmen die Haftung für Viren; es obliegt Ihrer Verantwortung, die E-Mail und deren Anhänge auf Viren zu prüfen.

The present email addresses only the addressee which it targets and may contain confidential material that may be protected by the professional secret. The opinions reflected herein are not necessarily the one of the SEEBURGER AG. If you are not the addressee, you have accidentally got this email and are not enabled to use, publish, forward, copy or print it in any way. Neither SEEBURGER AG , nor the sender (Scholz. Ulrich) are liable for viruses, being your own responsibility to check this email and its attachments for this purpose.


Gmane