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

Sir,= =C2=A0I do not understand the NEED for your explanation,Sir for I have not= asked for one!!. Please go through original trigger.

Mr.Karr was discussing =C2=A0=C2=A0correctly

=

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

=C2=A0

If Boolean is lonely param it wor= ks 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 Boolean is last the situation is Ok

2. calling a function with any number of parameters=C2=A0 involves va= rag; calling with named parameters involves =C2=A0=C2=A0map. = They are combined here.

= =C2=A0

Those are the problem= s addressed. First line of my mail

Both named = and varag

says that.

<= /div>

Frankly, I can't understand your = point at all.=C2=A0 At first, I thought you didn't understand my proble= m, and were pointing out irrelevant facts. This reply makes me think that p= erhaps you noticed some indication of something actually going wrong, but I= really can't tell.=C2=A0 Please try again to describe what I have &quo= t;correctly pointed out".

Sent: Sunday, April 26, 2020 9:00 AM
To: <= /b>users@groov= y.apache.org; David Karr
Subject: Re: Strategy for optionally exclud= ing a named method parameter?

=C2=A0

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

=C2=A0

You=E2=80=99re doing a =E2=80=9Cprintln=E2=80=9D on the firs= t arg (args.one), then a print on the second arg (args.two.

=C2=A0

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

<= /u>=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

the= n f(one: =E2=80=9Cstring=E2=80=9D, two: true), prints

=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 co= mbine the outputs, it=E2=80=99s 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)

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 true<= /u>

=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 string=

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

=C2=A0

From: Rathinavelu <rathinavelu@gmail.com>
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 <davidmichaelkarr@gmail.com= >
Subject: RE: Re: Strategy for optionally excluding a nam= ed method parameter?

=C2=A0

Both named and = varag

=C2=A0

<= p class=3D"MsoNormal">def f(Object[] args){ println args.one<= /p>

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)

=C2=A0=

[string]

[false][string]

[true][null= ]

[false][null]

[true][null]

[= false][null]

[true][null]=

[false]

=C2=A0

Please as a work around = keep the boolean as the last parameter. Since map is a subcla= ss of =C2=A0Object, the function polymorphically accepts map obje= ct . 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 =C2= =A0is =E2=80=9Cinvisible input=E2=80=9D. Last output has no [null]

T.Rathinavelu

=C2=A0

Sent from Mai= l for Windows 10

=C2=A0<= u>

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?

=C2=A0

Hi David,

since, as was mentioned, named paramet= ers are implemented as a map underneath in Groovy, you should be able to re= move the map entry of the parameter you do not want to pass, though I did n= ot try this myself...

Cheers,
mg

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

= =C2=A0

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

<= blockquote style=3D"border-color:currentcolor currentcolor currentcolor rgb= (204,204,204);border-style:none none none solid;border-width:medium medium = medium 1pt;padding:0in 0in 0in 6pt;margin:5pt 0in 5pt 4.8pt">

Named parameters are not av= ailable in Groovy, say, as in Python., though they say it is. Groovy has on= ly 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 mai= l me an use-case.

T.Rathinavelu

=C2=A0

The code sample looks something like 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 par= am2: value,

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

<= p class=3D"MsoNormal">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 param4: va= lue,

=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

<= p class=3D"MsoNormal">For instance, we need to make either the previous cal= l or the following:

=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 ...

=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 "if" checking for a= condition, followed by the "true" block with the first version o= f the function call with 25 parameters, followed by the "else" an= d the "false" block with the second version, which has 24 paramet= ers, 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<= u>

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

=C2=A0

Lat= ely my only Groovy work is scripted pipelines in Jenkins, version 2.89.4 .<= u>

=C2=A0

I'm working with an api that is somewhat dumb in one r= espect.=C2=A0 The method we call takes ~25 parameters.=C2=A0 We send them a= s named parameters. One of the parameters is of boolean type.=C2=A0 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".=C2= =A0 If we construct the call without that parameter entirely, it acts as if= we sent "false". I tried making it send null, but that just caus= es it to fail at runtime.=C2=A0 We presently have an "if" for tha= t one flag, with two calls to the method, one taking 25 parameters, the oth= er 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 re= ality is, that's not going to happen any time soon in geological terms.=

=C2=A0

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

=C2=A0

=C2=A0

=C2=A0

=C2= =A0

=C2=A0

<= /div>
--0000000000002915ae05a42b5ef0--