From users-return-4321-apmail-groovy-users-archive=groovy.apache.org@groovy.apache.org Sun Apr 26 14:41:50 2020 Return-Path: X-Original-To: apmail-groovy-users-archive@minotaur.apache.org Delivered-To: apmail-groovy-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by minotaur.apache.org (Postfix) with SMTP id 7D23E19662 for ; Sun, 26 Apr 2020 14:41:50 +0000 (UTC) Received: (qmail 17180 invoked by uid 500); 26 Apr 2020 14:41:49 -0000 Delivered-To: apmail-groovy-users-archive@groovy.apache.org Received: (qmail 17161 invoked by uid 500); 26 Apr 2020 14:41:49 -0000 Mailing-List: contact users-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@groovy.apache.org Delivered-To: mailing list users@groovy.apache.org Received: (qmail 17151 invoked by uid 99); 26 Apr 2020 14:41:49 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 26 Apr 2020 14:41:49 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id E5068C025E for ; Sun, 26 Apr 2020 14:41:48 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.18 X-Spam-Level: * X-Spam-Status: No, score=1.18 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.2, KAM_LINEPADDING=1.2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd1-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-ec2-va.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id subi3-ZqNr2z for ; Sun, 26 Apr 2020 14:41:47 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.210.53; helo=mail-ot1-f53.google.com; envelope-from=davidmichaelkarr@gmail.com; receiver= Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) by mx1-ec2-va.apache.org (ASF Mail Server at mx1-ec2-va.apache.org) with ESMTPS id 0D47DBB8FE for ; Sun, 26 Apr 2020 14:41:47 +0000 (UTC) Received: by mail-ot1-f53.google.com with SMTP id e20so21552028otk.12 for ; Sun, 26 Apr 2020 07:41:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=NnMrU+ZXukFIQfLb/6K4wVzQBhS/SRwdmyUJa+J+eEg=; b=c/NQUftvR8SvYQYDls3oY/U03pHa5wcfiZbhulggk0pSJN48CE8Xndqf4vVKzpv8Vb M1L7hyTzwDFVrYc3Ov/gH6zjkbeLpiRz+GuFUySSjiNKMRgtY7/XJld4zYIPWHy6a2GE REUqn/zttxNqn5OWun4BlL2loEiR057F6W68djhYnS/lHmHds54bWKya2tAqwqGBH5fQ oVu52wdcpm9pDu9z810dk2358eMcAwRgaRtWsRJppXv/zj6C2mV14F7lWb0AvERnbsw0 nEufOWm+q4i7oKdMUN1KbWsc/w2Zrm9qFICt1whAevwhOgtPL4/15km8J53wLjn9vlMt AL4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=NnMrU+ZXukFIQfLb/6K4wVzQBhS/SRwdmyUJa+J+eEg=; b=YAMJU8bOwWb630P5maRnY9OmrMPMAZBKwrnP1yxMhXxnPSSWs3dRdZebGvrba5AUW6 WIcNGGJK0eXfh1BZrfnYfZrLLJr2ighoJZ43aAWotY6snRTN3AqwzaYWp+VnvZXbteEl 5Hbc7SRqbtrOFy8qbSPiO93mJgQmaLfaJQ0DgdDo1JkXoXvLDDYQrzdTIAgzCPwEgdSS B3mp5aZ+mxsuYKb3Ws26YW56locqyRi580q7PUL4YmJ/JCyjc9XhWGg5vEJnvXafrMcu 8OJ9ysrvQ2Ejsrs6Dq3oPPErG4oMWihbTKBgT9W83HXflZorkJq4C016DjnySiEOMEgy Jxgw== X-Gm-Message-State: AGi0PuaGVdRZ2vuJTO0WyBJUW9rqHfhBQE/ZYGpdl4idfii2UCDlfJnz Z01KsgDyHYlZBr008UUO4PXF7iKauNfJTuITtf6Ui7eR X-Google-Smtp-Source: APiQypIhEsjx/m34+E9cWNAHXuJ7vaEYRsICdm+GzaDkyHbDx2HbUCwojBBYUygey6mmixn1xkX849Qdj+vNaxjmowg= X-Received: by 2002:aca:843:: with SMTP id 64mr13900924oii.56.1587912106290; Sun, 26 Apr 2020 07:41:46 -0700 (PDT) MIME-Version: 1.0 References: <5ea5264c.1c69fb81.18434.3f14@mx.google.com> In-Reply-To: <5ea5264c.1c69fb81.18434.3f14@mx.google.com> From: David Karr Date: Sun, 26 Apr 2020 07:41:32 -0700 Message-ID: Subject: Re: Re: Re: Strategy for optionally excluding a named method parameter? To: users@groovy.apache.org Content-Type: multipart/alternative; boundary="00000000000007b42705a4329900" --00000000000007b42705a4329900 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Apr 25, 2020 at 11:12 PM Rathinavelu wrote: > 1. *Is there a concise groovy syntax we could use that would optionally > include or exclude a single parameter to the method?* > > Yes *varags.* Combine* varag *and *map* if named parameter is also > required; *varag* with *Object[] args* parameter does the job > > 2*."What we've discovered from testing is that if we send a value as > either "true" or "false", it acts as if we sent "true"."* > > Yes You are right. The work around is keep the boolean as the last. > So are you saying that if I rearrange the map parameters so that this boolean parameter is last, and I provide a "false" value for it, that the function should properly detect it as "false", but if it's not the last parameter, it would think the value is "true"? Please check,Sir, and correct me if I am wrong. > > 3.Still your implementation of function is not given, Sir. > That's because I don't own it, and I don't have it. In fact, since we're working with Jenkins shared libraries, I can't even get access to the class files. T.Rathinavelu > > > > Sent from Mail for > Windows 10 > > > > *From: *David Karr > *Sent: *Sunday, April 26, 2020 11:34 AM > *To: *users@groovy.apache.org > *Subject: *Re: Re: Strategy for optionally excluding a named method > parameter? > > > > > > On Sat, Apr 25, 2020 at 10:42 PM Rathinavelu > wrote: > > Sir, I do not understand the NEED for your explanation,Sir for I have no= t > asked for one!!. Please go through original trigger. > > Mr.Karr was discussing * correctly * > > 1. misbehavior of boolean parameter in the middle of 24 parameters. He i= s > *correct.* > > > > If Boolean is lonely param it works OK. But Mr.Karr=E2=80=99s situation i= s real > use case. In the middle both false and true evaluate as false as Mr.Karr > correctly points out. > > > > So an work around if the Boolean is last the situation is Ok > > 2. calling a function with any number of parameters involves *varag; *ca= lling > with* named parameters *involves * map. *They are combined here. > > > > Those are the problems addressed. First line of my mail > > *Both named and varag* > > says that. > > > > Frankly, I can't understand your point at all. At first, I thought you > didn't understand my problem, and were pointing out irrelevant facts. Thi= s > reply makes me think that perhaps you noticed some indication of somethin= g > actually going wrong, but I really can't tell. Please try again to > describe what I have "correctly pointed out". > > > > *Sent: *Sunday, April 26, 2020 9:00 AM > *To: *users@groovy.apache.org; David Karr > *Subject: *Re: Strategy for optionally excluding a named method parameter= ? > > > > It=E2=80=99s doing what you programmed it to do. > > > > You=E2=80=99re doing a =E2=80=9Cprintln=E2=80=9D on the first arg (args.o= ne), then a print on the > second arg (args.two. > > > > So on your first 2 calls=E2=80=A6 > > > > f(one: =E2=80=9Cstring=E2=80=9D, two: false), prints > > string (the line fieed in println) > > false (no linefeed) > > > > then f(one: =E2=80=9Cstring=E2=80=9D, two: true), prints > > string (linefeed) > > true > > > > So if you combine the outputs, it=E2=80=99s indeed > > > > string (the line fieed in println) > > false (print, no linefeed) string (linefeed) > > true > > > > So. w/o the explanations, looks exactly what you have > > string > > false string > > true > > > > *From: *Rathinavelu > *Reply-To: * > *Date: *Saturday, April 25, 2020 at 9:23 PM > *To: *"users@groovy.apache.org" , " > users@groovy.apache.org" , David Karr < > davidmichaelkarr@gmail.com> > *Subject: *RE: Re: Strategy for optionally excluding a named method > parameter? > > > > *Both named and varag* > > > > def f(Object[] args){ println args.one > > print args.two } > > f(one: "string",two:false) > > f(one:"string", two:true) > > f(two:false) > > f(two:true) > > f(two: 1=3D=3D2) > > f(two: 1=3D=3D1) > > f(two: 1=3D=3D2) > > > > [string] > > [false][string] > > [true][null] > > [false][null] > > [true][null] > > [false][null] > > [true][null] > > [false] > > > > Please as a work around keep the *boolean* as the last parameter. Since > *map* is a subclass of *Object,* the function polymorphically accepts *m= ap > object* . But why Boolean be the last to work? Sorry, Sir! I am into > groovy only from last week! A long way to go! > > The reason for always =E2=80=98false=E2=80=99 in the middle perhaps is = =E2=80=9Cinvisible input=E2=80=9D. > Last output has no [null] > > T.Rathinavelu > > > > Sent from Mail for > Windows 10 > > > > *From: *MG > *Sent: *Sunday, April 26, 2020 5:00 AM > *To: *users@groovy.apache.org; David Karr > *Subject: *Re: Strategy for optionally excluding a named method parameter= ? > > > > Hi David, > > since, as was mentioned, named parameters are implemented as a map > underneath in Groovy, you should be able to remove the map entry of the > parameter you do not want to pass, though I did not try this myself... > > Cheers, > mg > > On 25/04/2020 20:57, David Karr wrote: > > > > > > On Sat, Apr 25, 2020 at 2:00 AM Rathinavelu wrote= : > > Named parameters are not available in Groovy, say, as in Python., though > they say it is. Groovy has only mapped parameters. The earlier mail works > for a single =E2=80=98named=E2=80=99 parameter; if there are more paramet= ers Groovy does > not work as =E2=80=98expected=E2=80=99; it treats them only as positional= parameters. > > Kindly mail me an use-case. > > T.Rathinavelu > > > > The code sample looks something like this: > > > > functionName param1: value, > > param2: value, > > param3: value, > > param4: value, > > ... > > param25: value > > > > For instance, we need to make either the previous call or the following: > > > > functionName param1: value, > > param2: value, > > param3: value, > > ... > > param25: value > > > > Where the "param4" key and value are not provided. Presently, we have an > "if" checking for a condition, followed by the "true" block with the firs= t > version of the function call with 25 parameters, followed by the "else" a= nd > the "false" block with the second version, which has 24 parameters, all t= he > same values as in the first block, except for the one key and value not > provided in the second version. > > > > > > Sent from Mail for > Windows 10 > > > > *From: *David Karr > *Sent: *Saturday, April 25, 2020 1:48 AM > *To: *users@groovy.apache.org > *Subject: *Strategy for optionally excluding a named method parameter? > > > > Lately my only Groovy work is scripted pipelines in Jenkins, version > 2.89.4 . > > > > I'm working with an api that is somewhat dumb in one respect. The method > we call takes ~25 parameters. We send them as named parameters. One of t= he > parameters is of boolean type. What we've discovered from testing is tha= t > if we send a value as either "true" or "false", it acts as if we sent > "true". If we construct the call without that parameter entirely, it act= s > as if we sent "false". I tried making it send null, but that just causes = it > to fail at runtime. We presently have an "if" for that one flag, with tw= o > calls to the method, one taking 25 parameters, the other taking 24. It i= s > really obnoxious. > > > > Obviously, the proper fix is to change their api so that it works > correctly. The reality is, that's not going to happen any time soon in > geological terms. > > > > Is there a concise groovy syntax we could use that would optionally > include or exclude a single parameter to the method? > > > > > > > > > > > > > --00000000000007b42705a4329900 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

On Sat, Apr 25, 2020 at 11:12 PM Rathinavelu <rathinavelu@gmail.com> wrote:

1. <= i>Is there a concise groovy syntax we could use that would optionally inclu= de or exclude a single parameter to the method?

Yes varags. Combine varag and map if = named parameter is also required; varag with Object[] args pa= rameter does the job

2."What we've d= iscovered from testing is that if we send a value as either "true"= ; or "false", it acts as if we sent "true"."

Yes You are right. The work around i= s keep the boolean as the last.


=
So are you saying that if I rearrange the map parameters so that this = boolean parameter is last, and I provide a "false" value for it, = that the function should properly detect it as "false", but if it= 's not the last parameter, it would think the value is "true"= ?

Please check,Sir, and correct me if I am wrong.

3.Still your implementation of function is not given, S= ir.


That's because I do= n't own it, and I don't have it. In fact, since we're working w= ith Jenkins shared libraries, I can't even get access to the class file= s.

<= p class=3D"MsoNormal">T.Rathinavelu

=C2=A0=

Sent from Mail for Windows 10

=

=C2=A0

From: David Karr
Sent: Sunda= y, April 26, 2020 11:34 AM
To: users@groovy.apache.org
Subject: R= e: Re: Strategy for optionally excluding a named method parameter?

=C2=A0

=C2=A0

On Sat, Apr 25, 2= 020 at 10:42 PM Rathinavelu <rathinavelu@gmail.com> wrote:

Sir, =C2=A0I do not understand the NEED for your explanati= on,Sir for I have not asked for one!!. Please go through original trigger.<= /p>

Mr.Karr was discussing =C2=A0=C2=A0correctly <= /b>

1. misbehavior of boolean =C2=A0parameter in = the middle of 24 parameters. He is correct.

=C2=A0

If Boolean is lonely param it works OK. = But Mr.Karr=E2=80=99s situation is real use case. In the middle both false = and true evaluate as false as Mr.Karr correctly points out.

=C2=A0

So an work around if the Boolea= n is last the situation is Ok

2. calling a funct= ion with any number of parameters=C2=A0 involves varag; calling with= named parameters involves =C2=A0=C2=A0map. They are combined= here.

=C2=A0

Th= ose are the problems addressed. First line of my mail

Both named and varag

says that.

=C2=A0

=

Frankly, I can't understand your poin= t at all.=C2=A0 At first, I thought you didn't understand my problem, a= nd were pointing out irrelevant facts. This reply makes me think that perha= ps you noticed some indication of something actually going wrong, but I rea= lly can't tell.=C2=A0 Please try again to describe what I have "co= rrectly pointed out".

=C2= =A0

Sent: Sunday, Apri= l 26, 2020 9:00 AM
To: users@groovy.apache.org; David Karr
Subject: Re: = Strategy for optionally excluding a named method parameter?

=C2=A0

It=E2=80=99s doing what you pro= grammed it to do.

=C2=A0

You=E2=80=99re doing a =E2=80=9Cprintln=E2=80=9D on the first arg (args.o= ne), then a print on the second arg (args.two.

= =C2=A0

So on your first 2 calls=E2=80=A6

=C2=A0

f(one: =E2=80=9Cstring= =E2=80=9D, two: false), prints

=C2=A0=C2=A0=C2=A0= =C2=A0 string (the line fieed in println)

=C2=A0= =C2=A0=C2=A0=C2=A0 false (no linefeed)

=C2=A0

=

then f(one: =E2=80=9Cstring=E2=80=9D, two: true), pr= ints

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0string (linefeed)

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 true

= =C2=A0

So if you combine the outputs, it=E2=80=99= s indeed

=C2=A0

=C2=A0= =C2=A0=C2=A0=C2=A0 string (the line fieed in println)

=C2=A0=C2=A0=C2=A0=C2=A0 false (print, no linefeed) string (linefeed)<= /p>

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 true

=C2=A0

So. w/o the explanations, = =C2=A0looks exactly what you have

=C2=A0=C2=A0=C2= =A0 =C2=A0string

=C2=A0=C2=A0=C2=A0=C2=A0 false s= tring

=C2=A0=C2=A0=C2=A0=C2=A0 true

=C2=A0

From: Rathinavelu <rathinavelu@gmail.com>
Reply-To: <
users@groovy.apache.org>
Date: Saturday, = April 25, 2020 at 9:23 PM
To: "users@groovy.apache.org" <users@groovy.apache= .org>, "users@groovy.apache.org" <users@groovy.apache.org>, David Karr &= lt;davidmic= haelkarr@gmail.com>
Subject: RE: Re: Strategy for optional= ly excluding a named method parameter?

=C2=A0

Both named and varag<= /p>

=C2=A0

def f(Object[] a= rgs){ println args.one

print args.two }

f(one: "string",two:false)

f(one:"string", two:true)

f(two:fa= lse)

f(two:true)

f(two:= 1=3D=3D2)

f(two: 1=3D=3D1)

f(two: 1=3D=3D2)

=C2=A0

[string]

[false][string]

[true][null]

[false][null]

[true][null]

[false][null]

[true][null]

[false]

=C2=A0

Please as a work around kee= p the boolean as the last parameter. Since map is a subclass = of =C2=A0Object, the function polymorphically accepts map object<= /b> . But why Boolean be the last to work? Sorry, Sir! I am into groovy onl= y from last week! A long way to go!

The reason fo= r always =E2=80=98false=E2=80=99 in the middle perhaps =C2=A0is =E2=80=9Cin= visible input=E2=80=9D. Last output has no [null]

T.Rathinavelu

=C2=A0

S= ent from Mail for Windows 10

=C2=A0

From:= MG
S= ent: Sunday, April 26, 2020 5:00 AM
To: users@groovy.apache.org; David KarrSubject: Re: Strategy for optionally excluding a named method param= eter?

=C2=A0

Hi David,

since, as was mentioned, named pa= rameters are implemented as a map underneath in Groovy, you should be able = to remove the map entry of the parameter you do not want to pass, though I = did not try this myself...

Cheers,
mg

On 25/04/2020 20:57, David Karr wrote:

=C2=A0

=

=C2=A0

On = Sat, Apr 25, 2020 at 2:00 AM Rathinavelu <rathinavelu@gmail.com> wrote:=

Named parame= ters are not available in Groovy, say, as in Python., though they say it is= . Groovy has only mapped parameters. The earlier mail works for a single = =E2=80=98named=E2=80=99 parameter; if there are more parameters Groovy does= not work as =E2=80=98expected=E2=80=99; it treats them only as positional = parameters.

Kindly m= ail me an use-case.

= T.Rathinavelu

=C2= =A0

The code sample looks something li= ke this:

=C2=A0

=C2=A0=C2=A0=C2=A0 functionName param1: value,

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 param2: = value,

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 param3: value,

=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 param4: value,

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ...

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 param25: val= ue

=C2=A0

For instance, we need to make either the previous call or the foll= owing:

=C2=A0

=C2=A0=C2=A0=C2=A0 functionName param1: value,

<= div>

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 param= 2: value,

=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 param3: value,

=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ...

=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 param25: value

=C2=A0

Where the "= param4" key and value are not provided.=C2=A0 Presently, we have an &q= uot;if" checking for a condition, followed by the "true" blo= ck with the first version of the function call with 25 parameters, followed= by the "else" and the "false" block with the second ve= rsion, which has 24 parameters, all the same values as in the first block, = except for the one key and value not provided in the second version.

=C2=A0

=C2=A0

Sent from Mail for Windows 10

=C2=A0

From: David Karr
Sent: Saturday, April 25, 2020 1:48 AM
To:
users= @groovy.apache.org
Subject: Strategy for optionally excluding= a named method parameter?

=C2=A0

Lately my only Groovy work is scripted pipelines in Jenkins,= version 2.89.4 .

=C2=A0

I'm working with an api that is somewhat dumb in one respect.=C2= =A0 The method we call takes ~25 parameters.=C2=A0 We send them as named pa= rameters. One of the parameters is of boolean type.=C2=A0 What we've di= scovered from testing is that if we send a value as either "true"= or "false", it acts as if we sent "true".=C2=A0 If we = construct the call without that parameter entirely, it acts as if we sent &= quot;false". I tried making it send null, but that just causes it to f= ail at runtime.=C2=A0 We presently have an "if" for that one flag= , with two calls to the method, one taking 25 parameters, the other taking = 24.=C2=A0 It is really obnoxious.

=C2=A0

Obviously, the proper fix is to change their api so= that it works correctly.=C2=A0 The reality is, that's not going to hap= pen any time soon in geological terms.

=C2=A0

Is there a concise groovy syntax we could use t= hat would optionally include or exclude a single parameter to the method?

=C2= =A0

=C2=A0

=

=C2=A0

=C2=A0

=C2=A0

=C2=A0

--00000000000007b42705a4329900--