You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by Guy Matz <gu...@gmail.com> on 2017/07/17 20:18:00 UTC

foo() || return false ?

Hello!
I'm trying to do the following in scriptler (Jenkins), but I can't get this
to work:
doSomething() || return false

This fails in scripler with:

Execution of script [promoteBuild.groovy] failed -
org.codehaus.groovy.control.MultipleCompilationErrorsException:
startup failed:
Script1.groovy: 51: unexpected token: return @ line 51, column 85.
   doSomething() || return fal


Anyone know why this seemingly valid groovy does not work in scriptler?


Thanks!


P.S. - I asked the jenkins community but no one responded

Re: foo() || return false ?

Posted by Guy Matz <gu...@gmail.com>.
That's totally acceptable.  Thank you!!

On Tue, Jul 18, 2017 at 9:18 AM, John Wagenleitner <
john.wagenleitner@gmail.com> wrote:

> How about
>
> if (!doSomething()) return false
>
>
> On Tue, Jul 18, 2017 at 7:00 AM, Guy Matz <gu...@gmail.com> wrote:
>
>> Right!  This is what I'm trying to do, but in a more concise way . . .
>>  any thoughts anyone?
>>
>> On Mon, Jul 17, 2017 at 8:43 PM, J. David Beutel <li...@getsu.com> wrote:
>>
>>> I guess OP wants to do:
>>>
>>> if (!doSomething()) {
>>>     return false
>>> }
>>>
>>> I don't know any groovy way to do that, though.
>>>
>>>
>>> On 2017-07-17 15:21 , John Wagenleitner wrote:
>>>
>>> Since the `||` operator expects an expression a return statement is not
>>> valid there.  If the goal is to call the method `doSomething()` and then
>>> return false, then both can be put on separate lines or a semicolon can be
>>> used to separate the statements to keep it a one-liner, e.g.,
>>> `doSomething(); return false`.
>>>
>>> On Mon, Jul 17, 2017 at 5:24 PM, Guy Matz <gu...@gmail.com> wrote:
>>>
>>>> Thanks so much for the reply!  I'm not trying to do this, though: ||
>>>> false
>>>>
>>>> I'm trying to do this: || return false
>>>>
>>>> Is there a more groovy way?
>>>>
>>>> Thanks!!
>>>>
>>>>
>>>> On Mon, Jul 17, 2017 at 5:06 PM, John Wagenleitner <
>>>> john.wagenleitner@gmail.com> wrote:
>>>>
>>>>> That is not a valid start of an expression which is expected for the
>>>>> binary expression (expr || expr) so that's why it wont compile. I am not
>>>>> familiar with Scriptler and it is hard to tell without some more context,
>>>>> but how about just:
>>>>>
>>>>> doSomething()
>>>>>
>>>>> You can simplify by dropping the `|| false`.  If that's the last line
>>>>> in a boolean returning method/context it will return true if doSomething()
>>>>> returns a non-null/non-zero/non-false value, else false.  Otherwise you
>>>>> could coerce the value to a boolean with:
>>>>>
>>>>> doSomething() as boolean
>>>>>
>>>>>
>>>>> On Mon, Jul 17, 2017 at 1:18 PM, Guy Matz <gu...@gmail.com> wrote:
>>>>>
>>>>>> Hello!
>>>>>> I'm trying to do the following in scriptler (Jenkins), but I can't
>>>>>> get this to work:
>>>>>> doSomething() || return false
>>>>>>
>>>>>> This fails in scripler with:
>>>>>>
>>>>>> Execution of script [promoteBuild.groovy] failed - org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
>>>>>> Script1.groovy: 51: unexpected token: return @ line 51, column 85.
>>>>>>    doSomething() || return fal
>>>>>>
>>>>>> Anyone know why this seemingly valid groovy does not work in scriptler?
>>>>>>
>>>>>> Thanks!
>>>>>>
>>>>>> P.S. - I asked the jenkins community but no one responded
>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>>
>>
>

Re: foo() || return false ?

Posted by John Wagenleitner <jo...@gmail.com>.
How about

if (!doSomething()) return false


On Tue, Jul 18, 2017 at 7:00 AM, Guy Matz <gu...@gmail.com> wrote:

> Right!  This is what I'm trying to do, but in a more concise way . . .
>  any thoughts anyone?
>
> On Mon, Jul 17, 2017 at 8:43 PM, J. David Beutel <li...@getsu.com> wrote:
>
>> I guess OP wants to do:
>>
>> if (!doSomething()) {
>>     return false
>> }
>>
>> I don't know any groovy way to do that, though.
>>
>>
>> On 2017-07-17 15:21 , John Wagenleitner wrote:
>>
>> Since the `||` operator expects an expression a return statement is not
>> valid there.  If the goal is to call the method `doSomething()` and then
>> return false, then both can be put on separate lines or a semicolon can be
>> used to separate the statements to keep it a one-liner, e.g.,
>> `doSomething(); return false`.
>>
>> On Mon, Jul 17, 2017 at 5:24 PM, Guy Matz <gu...@gmail.com> wrote:
>>
>>> Thanks so much for the reply!  I'm not trying to do this, though: ||
>>> false
>>>
>>> I'm trying to do this: || return false
>>>
>>> Is there a more groovy way?
>>>
>>> Thanks!!
>>>
>>>
>>> On Mon, Jul 17, 2017 at 5:06 PM, John Wagenleitner <
>>> john.wagenleitner@gmail.com> wrote:
>>>
>>>> That is not a valid start of an expression which is expected for the
>>>> binary expression (expr || expr) so that's why it wont compile. I am not
>>>> familiar with Scriptler and it is hard to tell without some more context,
>>>> but how about just:
>>>>
>>>> doSomething()
>>>>
>>>> You can simplify by dropping the `|| false`.  If that's the last line
>>>> in a boolean returning method/context it will return true if doSomething()
>>>> returns a non-null/non-zero/non-false value, else false.  Otherwise you
>>>> could coerce the value to a boolean with:
>>>>
>>>> doSomething() as boolean
>>>>
>>>>
>>>> On Mon, Jul 17, 2017 at 1:18 PM, Guy Matz <gu...@gmail.com> wrote:
>>>>
>>>>> Hello!
>>>>> I'm trying to do the following in scriptler (Jenkins), but I can't get
>>>>> this to work:
>>>>> doSomething() || return false
>>>>>
>>>>> This fails in scripler with:
>>>>>
>>>>> Execution of script [promoteBuild.groovy] failed - org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
>>>>> Script1.groovy: 51: unexpected token: return @ line 51, column 85.
>>>>>    doSomething() || return fal
>>>>>
>>>>> Anyone know why this seemingly valid groovy does not work in scriptler?
>>>>>
>>>>> Thanks!
>>>>>
>>>>> P.S. - I asked the jenkins community but no one responded
>>>>>
>>>>>
>>>>
>>>
>>
>>
>

Re: foo() || return false ?

Posted by Paul Moore <p....@gmail.com>.
Why do you need something "more concise"? It seems pretty OK to me...

On 18 July 2017 at 15:00, Guy Matz <gu...@gmail.com> wrote:
> Right!  This is what I'm trying to do, but in a more concise way . . .  any
> thoughts anyone?
>
> On Mon, Jul 17, 2017 at 8:43 PM, J. David Beutel <li...@getsu.com> wrote:
>>
>> I guess OP wants to do:
>>
>> if (!doSomething()) {
>>     return false
>> }

Re: foo() || return false ?

Posted by Guy Matz <gu...@gmail.com>.
Right!  This is what I'm trying to do, but in a more concise way . . .  any
thoughts anyone?

On Mon, Jul 17, 2017 at 8:43 PM, J. David Beutel <li...@getsu.com> wrote:

> I guess OP wants to do:
>
> if (!doSomething()) {
>     return false
> }
>
> I don't know any groovy way to do that, though.
>
>
> On 2017-07-17 15:21 , John Wagenleitner wrote:
>
> Since the `||` operator expects an expression a return statement is not
> valid there.  If the goal is to call the method `doSomething()` and then
> return false, then both can be put on separate lines or a semicolon can be
> used to separate the statements to keep it a one-liner, e.g.,
> `doSomething(); return false`.
>
> On Mon, Jul 17, 2017 at 5:24 PM, Guy Matz <gu...@gmail.com> wrote:
>
>> Thanks so much for the reply!  I'm not trying to do this, though: ||
>> false
>>
>> I'm trying to do this: || return false
>>
>> Is there a more groovy way?
>>
>> Thanks!!
>>
>>
>> On Mon, Jul 17, 2017 at 5:06 PM, John Wagenleitner <
>> john.wagenleitner@gmail.com> wrote:
>>
>>> That is not a valid start of an expression which is expected for the
>>> binary expression (expr || expr) so that's why it wont compile. I am not
>>> familiar with Scriptler and it is hard to tell without some more context,
>>> but how about just:
>>>
>>> doSomething()
>>>
>>> You can simplify by dropping the `|| false`.  If that's the last line in
>>> a boolean returning method/context it will return true if doSomething()
>>> returns a non-null/non-zero/non-false value, else false.  Otherwise you
>>> could coerce the value to a boolean with:
>>>
>>> doSomething() as boolean
>>>
>>>
>>> On Mon, Jul 17, 2017 at 1:18 PM, Guy Matz <gu...@gmail.com> wrote:
>>>
>>>> Hello!
>>>> I'm trying to do the following in scriptler (Jenkins), but I can't get
>>>> this to work:
>>>> doSomething() || return false
>>>>
>>>> This fails in scripler with:
>>>>
>>>> Execution of script [promoteBuild.groovy] failed - org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
>>>> Script1.groovy: 51: unexpected token: return @ line 51, column 85.
>>>>    doSomething() || return fal
>>>>
>>>> Anyone know why this seemingly valid groovy does not work in scriptler?
>>>>
>>>> Thanks!
>>>>
>>>> P.S. - I asked the jenkins community but no one responded
>>>>
>>>>
>>>
>>
>
>

Re: foo() || return false ?

Posted by Thibault Kruse <ti...@googlemail.com>.
It's probably a good thing this is not possible, as nobody wants to read
code like:
if (foo () || return false) {
  return true;
}


This works though:

return doSomething() && {doOtherThings()}
Which might be good enough.

On Jul 18, 2017 10:43 AM, "J. David Beutel" <li...@getsu.com> wrote:

> I guess OP wants to do:
>
> if (!doSomething()) {
>     return false
> }
>
> I don't know any groovy way to do that, though.
>
> On 2017-07-17 15:21 , John Wagenleitner wrote:
>
> Since the `||` operator expects an expression a return statement is not
> valid there.  If the goal is to call the method `doSomething()` and then
> return false, then both can be put on separate lines or a semicolon can be
> used to separate the statements to keep it a one-liner, e.g.,
> `doSomething(); return false`.
>
> On Mon, Jul 17, 2017 at 5:24 PM, Guy Matz <gu...@gmail.com> wrote:
>
>> Thanks so much for the reply!  I'm not trying to do this, though: ||
>> false
>>
>> I'm trying to do this: || return false
>>
>> Is there a more groovy way?
>>
>> Thanks!!
>>
>>
>> On Mon, Jul 17, 2017 at 5:06 PM, John Wagenleitner <
>> john.wagenleitner@gmail.com> wrote:
>>
>>> That is not a valid start of an expression which is expected for the
>>> binary expression (expr || expr) so that's why it wont compile. I am not
>>> familiar with Scriptler and it is hard to tell without some more context,
>>> but how about just:
>>>
>>> doSomething()
>>>
>>> You can simplify by dropping the `|| false`.  If that's the last line in
>>> a boolean returning method/context it will return true if doSomething()
>>> returns a non-null/non-zero/non-false value, else false.  Otherwise you
>>> could coerce the value to a boolean with:
>>>
>>> doSomething() as boolean
>>>
>>>
>>> On Mon, Jul 17, 2017 at 1:18 PM, Guy Matz <gu...@gmail.com> wrote:
>>>
>>>> Hello!
>>>> I'm trying to do the following in scriptler (Jenkins), but I can't get
>>>> this to work:
>>>> doSomething() || return false
>>>>
>>>> This fails in scripler with:
>>>>
>>>> Execution of script [promoteBuild.groovy] failed - org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
>>>> Script1.groovy: 51: unexpected token: return @ line 51, column 85.
>>>>    doSomething() || return fal
>>>>
>>>>  Anyone know why this seemingly valid groovy does not work in scriptler?
>>>>
>>>>  Thanks!
>>>>
>>>>  P.S. - I asked the jenkins community but no one responded
>>>>
>>>>
>>>
>>
>
>

Re: foo() || return false ?

Posted by "J. David Beutel" <li...@getsu.com>.
I guess OP wants to do:

if (!doSomething()) {
     return false
}

I don't know any groovy way to do that, though.

On 2017-07-17 15:21 , John Wagenleitner wrote:
> Since the `||` operator expects an expression a return statement is 
> not valid there.  If the goal is to call the method `doSomething()` 
> and then return false, then both can be put on separate lines or a 
> semicolon can be used to separate the statements to keep it a 
> one-liner, e.g., `doSomething(); return false`.
>
> On Mon, Jul 17, 2017 at 5:24 PM, Guy Matz <guymatz@gmail.com 
> <ma...@gmail.com>> wrote:
>
>     Thanks so much for the reply!  I'm not trying to do this, though:
>     || false
>
>     I'm trying to do this: || return false
>
>     Is there a more groovy way?
>
>     Thanks!!
>
>
>     On Mon, Jul 17, 2017 at 5:06 PM, John Wagenleitner
>     <john.wagenleitner@gmail.com <ma...@gmail.com>>
>     wrote:
>
>         That is not a valid start of an expression which is expected
>         for the binary expression (expr || expr) so that's why it wont
>         compile. I am not familiar with Scriptler and it is hard to
>         tell without some more context, but how about just:
>
>         doSomething()
>
>         You can simplify by dropping the `|| false`.  If that's the
>         last line in a boolean returning method/context it will return
>         true if doSomething() returns a non-null/non-zero/non-false
>         value, else false.  Otherwise you could coerce the value to a
>         boolean with:
>
>         doSomething() as boolean
>
>
>         On Mon, Jul 17, 2017 at 1:18 PM, Guy Matz <guymatz@gmail.com
>         <ma...@gmail.com>> wrote:
>
>             Hello!
>             I'm trying to do the following in scriptler (Jenkins), but
>             I can't get this to work:
>             doSomething() || return false
>
>             This fails in scripler with:
>
>             Execution of script [promoteBuild.groovy] failed -org.codehaus.groovy.control.Mu
>             <http://org.codehaus.groovy.control.Mu>ltipleCompilationErrorsException: startup failed:
>             Script1.groovy: 51: unexpected token: return @ line 51, column 85.
>                 doSomething() || return fal
>
>             Anyone know why this seemingly valid groovy does not work in scriptler?
>
>             Thanks!
>
>             P.S. - I asked the jenkins community but no one responded
>
>
>
>


Re: foo() || return false ?

Posted by John Wagenleitner <jo...@gmail.com>.
Since the `||` operator expects an expression a return statement is not
valid there.  If the goal is to call the method `doSomething()` and then
return false, then both can be put on separate lines or a semicolon can be
used to separate the statements to keep it a one-liner, e.g.,
`doSomething(); return false`.

On Mon, Jul 17, 2017 at 5:24 PM, Guy Matz <gu...@gmail.com> wrote:

> Thanks so much for the reply!  I'm not trying to do this, though: || false
>
> I'm trying to do this: || return false
>
> Is there a more groovy way?
>
> Thanks!!
>
>
> On Mon, Jul 17, 2017 at 5:06 PM, John Wagenleitner <
> john.wagenleitner@gmail.com> wrote:
>
>> That is not a valid start of an expression which is expected for the
>> binary expression (expr || expr) so that's why it wont compile. I am not
>> familiar with Scriptler and it is hard to tell without some more context,
>> but how about just:
>>
>> doSomething()
>>
>> You can simplify by dropping the `|| false`.  If that's the last line in
>> a boolean returning method/context it will return true if doSomething()
>> returns a non-null/non-zero/non-false value, else false.  Otherwise you
>> could coerce the value to a boolean with:
>>
>> doSomething() as boolean
>>
>>
>> On Mon, Jul 17, 2017 at 1:18 PM, Guy Matz <gu...@gmail.com> wrote:
>>
>>> Hello!
>>> I'm trying to do the following in scriptler (Jenkins), but I can't get
>>> this to work:
>>> doSomething() || return false
>>>
>>> This fails in scripler with:
>>>
>>> Execution of script [promoteBuild.groovy] failed - org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
>>> Script1.groovy: 51: unexpected token: return @ line 51, column 85.
>>>    doSomething() || return fal
>>>
>>>
>>> Anyone know why this seemingly valid groovy does not work in scriptler?
>>>
>>>
>>> Thanks!
>>>
>>>
>>> P.S. - I asked the jenkins community but no one responded
>>>
>>>
>>
>

Re: foo() || return false ?

Posted by Guy Matz <gu...@gmail.com>.
Thanks so much for the reply!  I'm not trying to do this, though: || false

I'm trying to do this: || return false

Is there a more groovy way?

Thanks!!


On Mon, Jul 17, 2017 at 5:06 PM, John Wagenleitner <
john.wagenleitner@gmail.com> wrote:

> That is not a valid start of an expression which is expected for the
> binary expression (expr || expr) so that's why it wont compile. I am not
> familiar with Scriptler and it is hard to tell without some more context,
> but how about just:
>
> doSomething()
>
> You can simplify by dropping the `|| false`.  If that's the last line in a
> boolean returning method/context it will return true if doSomething()
> returns a non-null/non-zero/non-false value, else false.  Otherwise you
> could coerce the value to a boolean with:
>
> doSomething() as boolean
>
>
> On Mon, Jul 17, 2017 at 1:18 PM, Guy Matz <gu...@gmail.com> wrote:
>
>> Hello!
>> I'm trying to do the following in scriptler (Jenkins), but I can't get
>> this to work:
>> doSomething() || return false
>>
>> This fails in scripler with:
>>
>> Execution of script [promoteBuild.groovy] failed - org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
>> Script1.groovy: 51: unexpected token: return @ line 51, column 85.
>>    doSomething() || return fal
>>
>>
>> Anyone know why this seemingly valid groovy does not work in scriptler?
>>
>>
>> Thanks!
>>
>>
>> P.S. - I asked the jenkins community but no one responded
>>
>>
>

Re: foo() || return false ?

Posted by John Wagenleitner <jo...@gmail.com>.
That is not a valid start of an expression which is expected for the binary
expression (expr || expr) so that's why it wont compile. I am not familiar
with Scriptler and it is hard to tell without some more context, but how
about just:

doSomething()

You can simplify by dropping the `|| false`.  If that's the last line in a
boolean returning method/context it will return true if doSomething()
returns a non-null/non-zero/non-false value, else false.  Otherwise you
could coerce the value to a boolean with:

doSomething() as boolean


On Mon, Jul 17, 2017 at 1:18 PM, Guy Matz <gu...@gmail.com> wrote:

> Hello!
> I'm trying to do the following in scriptler (Jenkins), but I can't get
> this to work:
> doSomething() || return false
>
> This fails in scripler with:
>
> Execution of script [promoteBuild.groovy] failed - org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> Script1.groovy: 51: unexpected token: return @ line 51, column 85.
>    doSomething() || return fal
>
>
> Anyone know why this seemingly valid groovy does not work in scriptler?
>
>
> Thanks!
>
>
> P.S. - I asked the jenkins community but no one responded
>
>