You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by Les Hartzman <lh...@gmail.com> on 2017/01/27 18:15:14 UTC
Syntax question using (identifier 1, identifier 2) on LHS of =
Hi,
I just saw a reference to using the above syntax, specifically as follows:
def (string1, string2) = "part1-part2".tokenize("-")
This assigns string1 "part1" and string2 "part2".
So my main question is what is this referred to as?
You can't do:
String (string1, string2) = "part1-part2".tokenize("-")
I did find out that you can do:
String string1
String string2
(string1, string2) = "part1-part2".tokenize("-")
Thanks.
Les
Re: Syntax question using (identifier 1, identifier 2) on LHS of =
Posted by Guillaume Laforge <gl...@gmail.com>.
Well, here, it's not only an assignment but a declaration, and for
declaration, yes, you have to use def unfortunately.
On Fri, Jan 27, 2017 at 8:37 PM, Les Hartzman <lh...@gmail.com> wrote:
> Are you saying it needs to be:
>
> def (String string1, String string2) = "part1-part2".tokenize("-")
>
> ?
>
> Thanks for the link on multiple assignments.
>
>
> On Fri, Jan 27, 2017 at 11:15 AM, Guillaume Laforge <gl...@gmail.com>
> wrote:
>
>> Actually, scratch that, the def is required.
>> Somehow, I feel that it could be made optional, and that would be more
>> elegant :-)
>>
>> On Fri, Jan 27, 2017 at 8:13 PM, Guillaume Laforge <gl...@gmail.com>
>> wrote:
>>
>>> I wouldn't use the def:
>>>
>>> (String string1, String string2) = "part1-part2".tokenize("-")
>>>
>>> (the def is redundant there)
>>>
>>> On Fri, Jan 27, 2017 at 7:55 PM, Dinko Srkoč <di...@gmail.com>
>>> wrote:
>>>
>>>> On 27 January 2017 at 19:15, Les Hartzman <lh...@gmail.com> wrote:
>>>> > Hi,
>>>> >
>>>> > I just saw a reference to using the above syntax, specifically as
>>>> follows:
>>>> >
>>>> > def (string1, string2) = "part1-part2".tokenize("-")
>>>> >
>>>> > This assigns string1 "part1" and string2 "part2".
>>>> >
>>>> > So my main question is what is this referred to as?
>>>>
>>>> It's called multiple assignment.
>>>>
>>>> >
>>>> > You can't do:
>>>> >
>>>> > String (string1, string2) = "part1-part2".tokenize("-")
>>>>
>>>> Well, you couldn't. What if types were different?
>>>>
>>>> But you could do it like this:
>>>>
>>>> def (String string1, String string2) = "part1-part2".tokenize("-")
>>>>
>>>> More on multiple assignments here:
>>>> http://groovy-lang.org/semantics.html#_multiple_assignment
>>>>
>>>> Cheers,
>>>> Dinko
>>>>
>>>> >
>>>> > I did find out that you can do:
>>>> >
>>>> > String string1
>>>> > String string2
>>>> > (string1, string2) = "part1-part2".tokenize("-")
>>>> >
>>>> > Thanks.
>>>> >
>>>> > Les
>>>> >
>>>>
>>>
>>>
>>>
>>> --
>>> 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>
>>>
>>
>>
>>
>> --
>> 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>
>>
>
>
--
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: Syntax question using (identifier 1, identifier 2) on LHS of =
Posted by Les Hartzman <lh...@gmail.com>.
Are you saying it needs to be:
def (String string1, String string2) = "part1-part2".tokenize("-")
?
Thanks for the link on multiple assignments.
On Fri, Jan 27, 2017 at 11:15 AM, Guillaume Laforge <gl...@gmail.com>
wrote:
> Actually, scratch that, the def is required.
> Somehow, I feel that it could be made optional, and that would be more
> elegant :-)
>
> On Fri, Jan 27, 2017 at 8:13 PM, Guillaume Laforge <gl...@gmail.com>
> wrote:
>
>> I wouldn't use the def:
>>
>> (String string1, String string2) = "part1-part2".tokenize("-")
>>
>> (the def is redundant there)
>>
>> On Fri, Jan 27, 2017 at 7:55 PM, Dinko Srkoč <di...@gmail.com>
>> wrote:
>>
>>> On 27 January 2017 at 19:15, Les Hartzman <lh...@gmail.com> wrote:
>>> > Hi,
>>> >
>>> > I just saw a reference to using the above syntax, specifically as
>>> follows:
>>> >
>>> > def (string1, string2) = "part1-part2".tokenize("-")
>>> >
>>> > This assigns string1 "part1" and string2 "part2".
>>> >
>>> > So my main question is what is this referred to as?
>>>
>>> It's called multiple assignment.
>>>
>>> >
>>> > You can't do:
>>> >
>>> > String (string1, string2) = "part1-part2".tokenize("-")
>>>
>>> Well, you couldn't. What if types were different?
>>>
>>> But you could do it like this:
>>>
>>> def (String string1, String string2) = "part1-part2".tokenize("-")
>>>
>>> More on multiple assignments here:
>>> http://groovy-lang.org/semantics.html#_multiple_assignment
>>>
>>> Cheers,
>>> Dinko
>>>
>>> >
>>> > I did find out that you can do:
>>> >
>>> > String string1
>>> > String string2
>>> > (string1, string2) = "part1-part2".tokenize("-")
>>> >
>>> > Thanks.
>>> >
>>> > Les
>>> >
>>>
>>
>>
>>
>> --
>> 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>
>>
>
>
>
> --
> 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: Syntax question using (identifier 1, identifier 2) on LHS of =
Posted by Guillaume Laforge <gl...@gmail.com>.
Actually, scratch that, the def is required.
Somehow, I feel that it could be made optional, and that would be more
elegant :-)
On Fri, Jan 27, 2017 at 8:13 PM, Guillaume Laforge <gl...@gmail.com>
wrote:
> I wouldn't use the def:
>
> (String string1, String string2) = "part1-part2".tokenize("-")
>
> (the def is redundant there)
>
> On Fri, Jan 27, 2017 at 7:55 PM, Dinko Srkoč <di...@gmail.com>
> wrote:
>
>> On 27 January 2017 at 19:15, Les Hartzman <lh...@gmail.com> wrote:
>> > Hi,
>> >
>> > I just saw a reference to using the above syntax, specifically as
>> follows:
>> >
>> > def (string1, string2) = "part1-part2".tokenize("-")
>> >
>> > This assigns string1 "part1" and string2 "part2".
>> >
>> > So my main question is what is this referred to as?
>>
>> It's called multiple assignment.
>>
>> >
>> > You can't do:
>> >
>> > String (string1, string2) = "part1-part2".tokenize("-")
>>
>> Well, you couldn't. What if types were different?
>>
>> But you could do it like this:
>>
>> def (String string1, String string2) = "part1-part2".tokenize("-")
>>
>> More on multiple assignments here:
>> http://groovy-lang.org/semantics.html#_multiple_assignment
>>
>> Cheers,
>> Dinko
>>
>> >
>> > I did find out that you can do:
>> >
>> > String string1
>> > String string2
>> > (string1, string2) = "part1-part2".tokenize("-")
>> >
>> > Thanks.
>> >
>> > Les
>> >
>>
>
>
>
> --
> 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>
>
--
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: Syntax question using (identifier 1, identifier 2) on LHS of =
Posted by Guillaume Laforge <gl...@gmail.com>.
I wouldn't use the def:
(String string1, String string2) = "part1-part2".tokenize("-")
(the def is redundant there)
On Fri, Jan 27, 2017 at 7:55 PM, Dinko Srkoč <di...@gmail.com> wrote:
> On 27 January 2017 at 19:15, Les Hartzman <lh...@gmail.com> wrote:
> > Hi,
> >
> > I just saw a reference to using the above syntax, specifically as
> follows:
> >
> > def (string1, string2) = "part1-part2".tokenize("-")
> >
> > This assigns string1 "part1" and string2 "part2".
> >
> > So my main question is what is this referred to as?
>
> It's called multiple assignment.
>
> >
> > You can't do:
> >
> > String (string1, string2) = "part1-part2".tokenize("-")
>
> Well, you couldn't. What if types were different?
>
> But you could do it like this:
>
> def (String string1, String string2) = "part1-part2".tokenize("-")
>
> More on multiple assignments here:
> http://groovy-lang.org/semantics.html#_multiple_assignment
>
> Cheers,
> Dinko
>
> >
> > I did find out that you can do:
> >
> > String string1
> > String string2
> > (string1, string2) = "part1-part2".tokenize("-")
> >
> > Thanks.
> >
> > Les
> >
>
--
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: Syntax question using (identifier 1, identifier 2) on LHS of =
Posted by Dinko Srkoč <di...@gmail.com>.
On 27 January 2017 at 19:15, Les Hartzman <lh...@gmail.com> wrote:
> Hi,
>
> I just saw a reference to using the above syntax, specifically as follows:
>
> def (string1, string2) = "part1-part2".tokenize("-")
>
> This assigns string1 "part1" and string2 "part2".
>
> So my main question is what is this referred to as?
It's called multiple assignment.
>
> You can't do:
>
> String (string1, string2) = "part1-part2".tokenize("-")
Well, you couldn't. What if types were different?
But you could do it like this:
def (String string1, String string2) = "part1-part2".tokenize("-")
More on multiple assignments here:
http://groovy-lang.org/semantics.html#_multiple_assignment
Cheers,
Dinko
>
> I did find out that you can do:
>
> String string1
> String string2
> (string1, string2) = "part1-part2".tokenize("-")
>
> Thanks.
>
> Les
>