Re: About array initializer of Java style for Groovy 3

2017-01-24 Thread Jochen Theodorou



On 24.01.2017 10:54, Remi Forax wrote:

Also note that in Java
  Integer[] o =  { 3 }; and int[] o =  { 3 };
both work but
  Object o =  { 3 };
does not compile because the syntax '{' '}' with no explicit array type
do inference (and here Object is not an array so the inference fails).

Supporting only explicit array initialization seems to be the right choice !


do if I understand this right parrot will now (after another great 
change from Daniel Sun) not support Integer[] o =  { 3 }.


But I think we could support the cases described here. Only thing we 
have to do is if the declaring side uses an array type. So I would parse 
Integer[] o =  { 3 } as a declaration with the right side being a 
closure expression and then transform it to an array init... or fail if 
the left side is no array type.


bye Jochen


Re: About array initializer of Java style for Groovy 3

2017-01-24 Thread Daniel Sun
Hi Rémi,

  The improvement has been completed in my groovy-parser repository, it
is being tested now. I'll sync them to parrot branch of apache/groovy later
:)

  Thanks for your clear explanation and advice!

Cheers,
Daniel.Sun



--
View this message in context: 
http://groovy.329449.n5.nabble.com/About-array-initializer-of-Java-style-for-Groovy-3-tp5737941p5737953.html
Sent from the Groovy Dev mailing list archive at Nabble.com.


Re: About array initializer of Java style for Groovy 3

2017-01-24 Thread Remi Forax
Also note that in Java 
Integer[] o = { 3 }; and int[] o = { 3 }; 
both work but 
Object o = { 3 }; 
does not compile because the syntax '{' '}' with no explicit array type do 
inference (and here Object is not an array so the inference fails). 

Supporting only explicit array initialization seems to be the right choice ! 

Rémi 

> De: "Daniel Sun" 
> À: d...@groovy.incubator.apache.org
> Envoyé: Mardi 24 Janvier 2017 10:42:03
> Objet: Re: About array initializer of Java style for Groovy 3

> +1

> 在 "Guillaume Laforge [via Groovy]" ,2017年1月24日
> 下午5:19写道:

>> Good point.
>> We should definitely avoid confusion as much as possible, and avoid 
>> introducing
>> ambiguities.

>> On Tue, Jan 24, 2017 at 10:12 AM, Andres Almiray < [hidden email] > wrote:

>>> I think we should support only explicit array initilization with array type,
>>> that is "new int[] { 2 }" for compatibility's sake.

>>> Sent from my iPhone

>>> On 24 Jan 2017, at 09:59, Daniel Sun < [hidden email] > wrote:

>>>> or we just support new int[] {1,2,3} ?

>>>> 在 "Guillaume Laforge [via Groovy]" ,2017年1月24日
>>>> 16:54写道:

>>>>> What happens for def a = { 2 }, is it parsed as a closure or an array
>>>>> initializer?

>>>>> On Tue, Jan 24, 2017 at 9:52 AM, Daniel Sun < [hidden email] > wrote:

>>>>>> Hi Andres,

>>>>>> Parrot can parse ` def a = {1, 2, 3}` properly, but it can not parse
>>>>>> `{1, 2, 3}`, which is not supported by Java too.

>>>>>> This is the initial implementation :)
>>>>>> https://github.com/danielsun1106/groovy-parser/commit/96e6c923a4d09d48448f8731a314c918ee6c0e7c

>>>>>> Cheers,
>>>>>> Daniel.Sun

>>>>>> --
>>>>>> View this message in context:
>>>>>> http://groovy.329449.n5.nabble.com/About-array-initializer-of-Java-style-for-Groovy-3-tp5737941p5737944.html
>>>>>> Sent from the Groovy Dev mailing list archive at Nabble.com .

>>>>> --
>>>>> Guillaume Laforge
>>>>> Apache Groovy committer & PMC Vice-President
>>>>> Developer Advocate @ Google Cloud Platform

>>>>> Blog: http://glaforge.appspot.com/
>>>>> Social: @glaforge / Google+

>>>>> If you reply to this email, your message will be added to the discussion 
>>>>> below:
>>>>> http://groovy.329449.n5.nabble.com/About-array-initializer-of-Java-style-for-Groovy-3-tp5737941p5737945.html
>>>>> To unsubscribe from About array initializer of Java style for Groovy 3, 
>>>>> click
>>>>> here .
>>>>> NAML

>>>> View this message in context: Re: About array initializer of Java style for
>>>> Groovy 3
>>>> Sent from the Groovy Dev mailing list archive at Nabble.com .

>> --
>> Guillaume Laforge
>> Apache Groovy committer & PMC Vice-President
>> Developer Advocate @ Google Cloud Platform

>> Blog: http://glaforge.appspot.com/
>> Social: @glaforge / Google+

>> If you reply to this email, your message will be added to the discussion 
>> below:
>> http://groovy.329449.n5.nabble.com/About-array-initializer-of-Java-style-for-Groovy-3-tp5737941p5737949.html
>> To unsubscribe from About array initializer of Java style for Groovy 3, click
>> here .
>> NAML

> View this message in context: Re: About array initializer of Java style for
> Groovy 3
> Sent from the Groovy Dev mailing list archive at Nabble.com.


Re: About array initializer of Java style for Groovy 3

2017-01-24 Thread Daniel Sun
+1



在 "Guillaume Laforge [via Groovy]" 
,2017年1月24日 下午5:19写道:

Good point.
We should definitely avoid confusion as much as possible, and avoid introducing 
ambiguities.

On Tue, Jan 24, 2017 at 10:12 AM, Andres Almiray <[hidden email]> wrote:
I think we should support only explicit array initilization with array type, 
that is "new int[] { 2 }" for compatibility's sake.

Sent from my iPhone

On 24 Jan 2017, at 09:59, Daniel Sun <[hidden email]> wrote:

or we just support new int[] {1,2,3}  ?



在 "Guillaume Laforge [via Groovy]" ,2017年1月24日 16:54写道:

What happens for def a = { 2 }, is it parsed as a closure or an array 
initializer?

On Tue, Jan 24, 2017 at 9:52 AM, Daniel Sun <[hidden email]> wrote:
Hi Andres,

   Parrot can parse ` def a = {1, 2, 3}` properly, but it can not parse
`{1, 2, 3}`, which is not supported by Java too.

   This is the initial implementation :)
https://github.com/danielsun1106/groovy-parser/commit/96e6c923a4d09d48448f8731a314c918ee6c0e7c


Cheers,
Daniel.Sun




--
View this message in context: 
http://groovy.329449.n5.nabble.com/About-array-initializer-of-Java-style-for-Groovy-3-tp5737941p5737944.html
Sent from the Groovy Dev mailing list archive at Nabble.com<http://Nabble.com>.



--
Guillaume Laforge
Apache Groovy committer & PMC Vice-President
Developer Advocate @ Google Cloud Platform

Blog: http://glaforge.appspot.com/
Social: @glaforge<http://twitter.com/glaforge> / 
Google+<https://plus.google.com/u/0/114130972232398734985/posts>



If you reply to this email, your message will be added to the discussion below:
http://groovy.329449.n5.nabble.com/About-array-initializer-of-Java-style-for-Groovy-3-tp5737941p5737945.html
To unsubscribe from About array initializer of Java style for Groovy 3, click 
here.
NAML<http://groovy.329449.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>

________________
View this message in context: Re: About array initializer of Java style for 
Groovy 
3<http://groovy.329449.n5.nabble.com/About-array-initializer-of-Java-style-for-Groovy-3-tp5737941p5737947.html>
Sent from the Groovy Dev mailing list 
archive<http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html> at 
Nabble.com<http://Nabble.com>.



--
Guillaume Laforge
Apache Groovy committer & PMC Vice-President
Developer Advocate @ Google Cloud Platform

Blog: http://glaforge.appspot.com/
Social: @glaforge<http://twitter.com/glaforge> / 
Google+<https://plus.google.com/u/0/114130972232398734985/posts>


____
If you reply to this email, your message will be added to the discussion below:
http://groovy.329449.n5.nabble.com/About-array-initializer-of-Java-style-for-Groovy-3-tp5737941p5737949.html
To unsubscribe from About array initializer of Java style for Groovy 3, click 
here<http://groovy.329449.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5737941&code=cmVhbGJsdWVzdW5AaG90bWFpbC5jb218NTczNzk0MXwxMTQ2MjE4MjI1>.
NAML<http://groovy.329449.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>




--
View this message in context: 
http://groovy.329449.n5.nabble.com/About-array-initializer-of-Java-style-for-Groovy-3-tp5737941p5737950.html
Sent from the Groovy Dev mailing list archive at Nabble.com.

Re: About array initializer of Java style for Groovy 3

2017-01-24 Thread Guillaume Laforge
Good point.
We should definitely avoid confusion as much as possible, and avoid
introducing ambiguities.

On Tue, Jan 24, 2017 at 10:12 AM, Andres Almiray  wrote:

> I think we should support only explicit array initilization with array
> type, that is "new int[] { 2 }" for compatibility's sake.
>
> Sent from my iPhone
>
> On 24 Jan 2017, at 09:59, Daniel Sun  wrote:
>
> or we just support new int[] {1,2,3}  ?
>
>
>
> 在 "Guillaume Laforge [via Groovy]"  <http:///user/SendEmail.jtp?type=node&node=5737947&i=0>>,2017年1月24日
> 16:54写道:
>
> What happens for def a = { 2 }, is it parsed as a closure or an array
> initializer?
>
> On Tue, Jan 24, 2017 at 9:52 AM, Daniel Sun <[hidden email]> wrote:
>
>> Hi Andres,
>>
>>Parrot can parse ` def a = {1, 2, 3}` properly, but it can not
>> parse
>> `{1, 2, 3}`, which is not supported by Java too.
>>
>>This is the initial implementation :)
>> https://github.com/danielsun1106/groovy-parser/commit/
>> 96e6c923a4d09d48448f8731a314c918ee6c0e7c
>>
>>
>> Cheers,
>> Daniel.Sun
>>
>>
>>
>>
>> --
>> View this message in context: http://groovy.329449.n5.
>> nabble.com/About-array-initializer-of-Java-style-for-
>> Groovy-3-tp5737941p5737944.html
>> Sent from the Groovy Dev mailing list archive at Nabble.com.
>>
>
>
>
> --
> Guillaume Laforge
> Apache Groovy committer & PMC Vice-President
> Developer Advocate @ Google Cloud Platform
>
> Blog: http://glaforge.appspot.com/
> Social: @glaforge <http://twitter.com/glaforge> / Google+
> <https://plus.google.com/u/0/114130972232398734985/posts>
>
>
> --
> If you reply to this email, your message will be added to the discussion
> below:
> http://groovy.329449.n5.nabble.com/About-array-
> initializer-of-Java-style-for-Groovy-3-tp5737941p5737945.html
> To unsubscribe from About array initializer of Java style for Groovy 3, click
> here.
> NAML
> <http://groovy.329449.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>
>
> --
> View this message in context: Re: About array initializer of Java style
> for Groovy 3
> <http://groovy.329449.n5.nabble.com/About-array-initializer-of-Java-style-for-Groovy-3-tp5737941p5737947.html>
> Sent from the Groovy Dev mailing list archive
> <http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html> at Nabble.com
> .
>
>


-- 
Guillaume Laforge
Apache Groovy committer & PMC Vice-President
Developer Advocate @ Google Cloud Platform

Blog: http://glaforge.appspot.com/
Social: @glaforge <http://twitter.com/glaforge> / Google+
<https://plus.google.com/u/0/114130972232398734985/posts>


Re: About array initializer of Java style for Groovy 3

2017-01-24 Thread Andres Almiray
I think we should support only explicit array initilization with array type, 
that is "new int[] { 2 }" for compatibility's sake. 

Sent from my iPhone

> On 24 Jan 2017, at 09:59, Daniel Sun  wrote:
> 
> or we just support new int[] {1,2,3}  ?
> 
> 
> 
> 在 "Guillaume Laforge [via Groovy]" ,2017年1月24日 
> 16:54写道:
> What happens for def a = { 2 }, is it parsed as a closure or an array 
> initializer?
> 
>> On Tue, Jan 24, 2017 at 9:52 AM, Daniel Sun <[hidden email]> wrote:
>> Hi Andres,
>> 
>>Parrot can parse ` def a = {1, 2, 3}` properly, but it can not parse
>> `{1, 2, 3}`, which is not supported by Java too.
>> 
>>This is the initial implementation :)
>> https://github.com/danielsun1106/groovy-parser/commit/96e6c923a4d09d48448f8731a314c918ee6c0e7c
>> 
>> 
>> Cheers,
>> Daniel.Sun
>> 
>> 
>> 
>> 
>> --
>> View this message in context: 
>> http://groovy.329449.n5.nabble.com/About-array-initializer-of-Java-style-for-Groovy-3-tp5737941p5737944.html
>> Sent from the Groovy Dev mailing list archive at Nabble.com.
> 
> 
> 
> -- 
> Guillaume Laforge
> Apache Groovy committer & PMC Vice-President
> Developer Advocate @ Google Cloud Platform
> 
> Blog: http://glaforge.appspot.com/
> Social: @glaforge / Google+
> 
> 
> If you reply to this email, your message will be added to the discussion 
> below:
> http://groovy.329449.n5.nabble.com/About-array-initializer-of-Java-style-for-Groovy-3-tp5737941p5737945.html
> To unsubscribe from About array initializer of Java style for Groovy 3, click 
> here.
> NAML
> 
> View this message in context: Re: About array initializer of Java style for 
> Groovy 3
> Sent from the Groovy Dev mailing list archive at Nabble.com.


Re: About array initializer of Java style for Groovy 3

2017-01-24 Thread Daniel Sun
or we just support new int[] {1,2,3}  ?



在 "Guillaume Laforge [via Groovy]" 
,2017年1月24日 16:54写道:

What happens for def a = { 2 }, is it parsed as a closure or an array 
initializer?

On Tue, Jan 24, 2017 at 9:52 AM, Daniel Sun <[hidden email]> wrote:
Hi Andres,

   Parrot can parse ` def a = {1, 2, 3}` properly, but it can not parse
`{1, 2, 3}`, which is not supported by Java too.

   This is the initial implementation :)
https://github.com/danielsun1106/groovy-parser/commit/96e6c923a4d09d48448f8731a314c918ee6c0e7c


Cheers,
Daniel.Sun




--
View this message in context: 
http://groovy.329449.n5.nabble.com/About-array-initializer-of-Java-style-for-Groovy-3-tp5737941p5737944.html
Sent from the Groovy Dev mailing list archive at Nabble.com.



--
Guillaume Laforge
Apache Groovy committer & PMC Vice-President
Developer Advocate @ Google Cloud Platform

Blog: http://glaforge.appspot.com/
Social: @glaforge<http://twitter.com/glaforge> / 
Google+<https://plus.google.com/u/0/114130972232398734985/posts>



If you reply to this email, your message will be added to the discussion below:
http://groovy.329449.n5.nabble.com/About-array-initializer-of-Java-style-for-Groovy-3-tp5737941p5737945.html
To unsubscribe from About array initializer of Java style for Groovy 3, click 
here<http://groovy.329449.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5737941&code=cmVhbGJsdWVzdW5AaG90bWFpbC5jb218NTczNzk0MXwxMTQ2MjE4MjI1>.
NAML<http://groovy.329449.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>




--
View this message in context: 
http://groovy.329449.n5.nabble.com/About-array-initializer-of-Java-style-for-Groovy-3-tp5737941p5737947.html
Sent from the Groovy Dev mailing list archive at Nabble.com.

Re: About array initializer of Java style for Groovy 3

2017-01-24 Thread Daniel Sun
closure



在 "Guillaume Laforge [via Groovy]" 
,2017年1月24日 16:54写道:

What happens for def a = { 2 }, is it parsed as a closure or an array 
initializer?

On Tue, Jan 24, 2017 at 9:52 AM, Daniel Sun <[hidden email]> wrote:
Hi Andres,

   Parrot can parse ` def a = {1, 2, 3}` properly, but it can not parse
`{1, 2, 3}`, which is not supported by Java too.

   This is the initial implementation :)
https://github.com/danielsun1106/groovy-parser/commit/96e6c923a4d09d48448f8731a314c918ee6c0e7c


Cheers,
Daniel.Sun




--
View this message in context: 
http://groovy.329449.n5.nabble.com/About-array-initializer-of-Java-style-for-Groovy-3-tp5737941p5737944.html
Sent from the Groovy Dev mailing list archive at Nabble.com.



--
Guillaume Laforge
Apache Groovy committer & PMC Vice-President
Developer Advocate @ Google Cloud Platform

Blog: http://glaforge.appspot.com/
Social: @glaforge<http://twitter.com/glaforge> / 
Google+<https://plus.google.com/u/0/114130972232398734985/posts>



If you reply to this email, your message will be added to the discussion below:
http://groovy.329449.n5.nabble.com/About-array-initializer-of-Java-style-for-Groovy-3-tp5737941p5737945.html
To unsubscribe from About array initializer of Java style for Groovy 3, click 
here<http://groovy.329449.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5737941&code=cmVhbGJsdWVzdW5AaG90bWFpbC5jb218NTczNzk0MXwxMTQ2MjE4MjI1>.
NAML<http://groovy.329449.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>




--
View this message in context: 
http://groovy.329449.n5.nabble.com/About-array-initializer-of-Java-style-for-Groovy-3-tp5737941p5737946.html
Sent from the Groovy Dev mailing list archive at Nabble.com.

Re: About array initializer of Java style for Groovy 3

2017-01-24 Thread Guillaume Laforge
What happens for def a = { 2 }, is it parsed as a closure or an array
initializer?

On Tue, Jan 24, 2017 at 9:52 AM, Daniel Sun  wrote:

> Hi Andres,
>
>Parrot can parse ` def a = {1, 2, 3}` properly, but it can not parse
> `{1, 2, 3}`, which is not supported by Java too.
>
>This is the initial implementation :)
> https://github.com/danielsun1106/groovy-parser/commit/
> 96e6c923a4d09d48448f8731a314c918ee6c0e7c
>
>
> Cheers,
> Daniel.Sun
>
>
>
>
> --
> View this message in context: http://groovy.329449.n5.
> nabble.com/About-array-initializer-of-Java-style-for-
> Groovy-3-tp5737941p5737944.html
> Sent from the Groovy Dev mailing list archive at Nabble.com.
>



-- 
Guillaume Laforge
Apache Groovy committer & PMC Vice-President
Developer Advocate @ Google Cloud Platform

Blog: http://glaforge.appspot.com/
Social: @glaforge <http://twitter.com/glaforge> / Google+
<https://plus.google.com/u/0/114130972232398734985/posts>


Re: About array initializer of Java style for Groovy 3

2017-01-24 Thread Daniel Sun
Hi Andres,

   Parrot can parse ` def a = {1, 2, 3}` properly, but it can not parse
`{1, 2, 3}`, which is not supported by Java too.

   This is the initial implementation :)
https://github.com/danielsun1106/groovy-parser/commit/96e6c923a4d09d48448f8731a314c918ee6c0e7c


Cheers,
Daniel.Sun




--
View this message in context: 
http://groovy.329449.n5.nabble.com/About-array-initializer-of-Java-style-for-Groovy-3-tp5737941p5737944.html
Sent from the Groovy Dev mailing list archive at Nabble.com.


Re: About array initializer of Java style for Groovy 3

2017-01-24 Thread Andres Almiray
Can this feature be added without the parser getting confused with {1, 2,
3}, thinking it's a closure instead of an initializer?
AFAIK this is the same reason why instance initializers are not supported
by Groovy.

If it can be done then great! This would remove one gotcha when migratation
Java code to Groovy :-)

Cheers,
Andres

---
Java Champion; Groovy Enthusiast
http://jroller.com/aalmiray
http://www.linkedin.com/in/aalmiray
--
What goes up, must come down. Ask any system administrator.
There are 10 types of people in the world: Those who understand binary, and
those who don't.
To understand recursion, we must first understand recursion.

On Tue, Jan 24, 2017 at 8:14 AM, Daniel Sun  wrote:

> Hi all,
>
>Java supports specifing initial values while creating arrays, e.g.
> `new int[] {1, 2, 3}`, `new String[] { hello(), world() }`, etc. I plan to
> add this syntax for Groovy 3 to improve the compatibility between Groovy
> and
> Java.
>
>Any thoughts?
>
> Cheers,
> Daniel.Sun
>
>
>
> --
> View this message in context: http://groovy.329449.n5.
> nabble.com/About-array-initializer-of-Java-style-for-
> Groovy-3-tp5737941.html
> Sent from the Groovy Dev mailing list archive at Nabble.com.
>


About array initializer of Java style for Groovy 3

2017-01-23 Thread Daniel Sun
Hi all,

   Java supports specifing initial values while creating arrays, e.g.
`new int[] {1, 2, 3}`, `new String[] { hello(), world() }`, etc. I plan to
add this syntax for Groovy 3 to improve the compatibility between Groovy and
Java. 

   Any thoughts?

Cheers,
Daniel.Sun



--
View this message in context: 
http://groovy.329449.n5.nabble.com/About-array-initializer-of-Java-style-for-Groovy-3-tp5737941.html
Sent from the Groovy Dev mailing list archive at Nabble.com.