From users-return-4319-apmail-groovy-users-archive=groovy.apache.org@groovy.apache.org Sun Apr 26 06:04:21 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 54D5B19650 for ; Sun, 26 Apr 2020 06:04:21 +0000 (UTC) Received: (qmail 32396 invoked by uid 500); 26 Apr 2020 06:04:20 -0000 Delivered-To: apmail-groovy-users-archive@groovy.apache.org Received: (qmail 32279 invoked by uid 500); 26 Apr 2020 06:04:19 -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 32265 invoked by uid 99); 26 Apr 2020 06:04:18 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 26 Apr 2020 06:04:18 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id DEE841A0DDF for ; Sun, 26 Apr 2020 06:04:17 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.2 X-Spam-Level: * X-Spam-Status: No, score=1.2 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-he-de.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id XMzU4GL-riMj for ; Sun, 26 Apr 2020 06:04:16 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=2607:f8b0:4864:20::32e; helo=mail-ot1-x32e.google.com; envelope-from=davidmichaelkarr@gmail.com; receiver= Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by mx1-he-de.apache.org (ASF Mail Server at mx1-he-de.apache.org) with ESMTPS id 770167DD96 for ; Sun, 26 Apr 2020 06:04:15 +0000 (UTC) Received: by mail-ot1-x32e.google.com with SMTP id m13so20353858otf.6 for ; Sat, 25 Apr 2020 23:04:15 -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=kLT87U7GdYRcPBdQy1i/h1MRbRq+UCP20SxBNxcnfZ8=; b=AsunymFT61BDchaV2WOGaWLRkezl/0wTcw/nq34yhWLSw+rOiasx2mz2LkH1MYLsbk 1EMmijCdYV7AKZEDfuQDOh0mO7vN5AbMDJg9/rMR8dKbaXK2zCA0JTRNyVSPaAM+Vjya 67qbHYLlKE4prvrdyLkkzwTw4cpjK+cqTEVVgvKv/OxpYXaDvKOLYNRMXp2BMcbcuHx4 WNw47/lW6rUNpredkeWPh+1JhJcIhN3aeQtnrMkmP2pr5o7J9EyGEV2E3RX6tuc49MhJ FF1dXrQP3NvDAVgGmEiH6u2pUTs2y6inZOBy6P5RNRAwEGmKjsBoRUNjZDyBOI+ItWDN xOeA== 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=kLT87U7GdYRcPBdQy1i/h1MRbRq+UCP20SxBNxcnfZ8=; b=rSg+AfdLKcPGpcEBRlR1aIZNtptlhFNURCkwf7GrJ99GpugIqfBavjXPLEc1KKqlWR xp8cczGQkFFS601cESIDOshPt1o4cWPXTclnZyoLSrMGyokuSt1FqQisxw9VwLkh+CWw fRFuUPEUAMPPHU67a0AGLgP4kc1iVv8OGLDk3Qd2o+/8xiFOYEw7+d+dE7izfqEQGmL6 gv2YLQmpdthhzNBL0YqLCsO3vVgXYq7M03W8LkBZnF9pVwlSFvbQaGomaKF2aj8IjNrP B19kAbE6f75jy+ZPh3qxKiOh2jktcg+rC9VDMR9E3IdOdme2PPogBoceLK27HZDTey9W rBog== X-Gm-Message-State: AGi0PuZh+4Gaq/kyDlAw0Kuwk8S21FKGYBpEluDhyrpxTiPvv3Kcx0NW /OjkqlulW6+0WA3IiUg+kRuS0OubFyxrFDAvVMSfV0nx X-Google-Smtp-Source: APiQypL8Og8V9+26JBAKT5oEC50paTQ2zIokiwSJ3CrNMnsbVySg+mn8Q3ORVP5T5S2QVEvUgsky7rtwS5nHX6xwc7c= X-Received: by 2002:a9d:1462:: with SMTP id h89mr14514328oth.18.1587881053851; Sat, 25 Apr 2020 23:04:13 -0700 (PDT) MIME-Version: 1.0 References: <5ea51f43.1c69fb81.8676f.b712@mx.google.com> In-Reply-To: <5ea51f43.1c69fb81.8676f.b712@mx.google.com> From: David Karr Date: Sat, 25 Apr 2020 23:04:01 -0700 Message-ID: Subject: Re: Re: Strategy for optionally excluding a named method parameter? To: users@groovy.apache.org Content-Type: multipart/alternative; boundary="0000000000002915ae05a42b5ef0" --0000000000002915ae05a42b5ef0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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. This reply makes me think that perhaps you noticed some indication of something 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? > > > > > > > > > > > --0000000000002915ae05a42b5ef0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

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>
Reply-= To: <us= ers@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 <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--