From users-return-4320-apmail-groovy-users-archive=groovy.apache.org@groovy.apache.org Sun Apr 26 06:12:39 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 8227D1967F for ; Sun, 26 Apr 2020 06:12:39 +0000 (UTC) Received: (qmail 41176 invoked by uid 500); 26 Apr 2020 06:12:38 -0000 Delivered-To: apmail-groovy-users-archive@groovy.apache.org Received: (qmail 41103 invoked by uid 500); 26 Apr 2020 06:12:38 -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 41091 invoked by uid 99); 26 Apr 2020 06:12:38 -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:12:38 +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 69C701A408D for ; Sun, 26 Apr 2020 06:12:37 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.302 X-Spam-Level: X-Spam-Status: No, score=0.302 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, MIME_HTML_ONLY=0.3, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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-ec2-va.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id 9udgmBXcDHxn for ; Sun, 26 Apr 2020 06:12:36 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.216.52; helo=mail-pj1-f52.google.com; envelope-from=rathinavelu@gmail.com; receiver= Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by mx1-ec2-va.apache.org (ASF Mail Server at mx1-ec2-va.apache.org) with ESMTPS id BFE0CBB901 for ; Sun, 26 Apr 2020 06:12:35 +0000 (UTC) Received: by mail-pj1-f52.google.com with SMTP id a31so4020744pje.1 for ; Sat, 25 Apr 2020 23:12:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:mime-version:date:from:subject:thread-topic:to :content-transfer-encoding; bh=WA8aPARa5dl7LzA4eMu5kaaUg+qB5zOABTgVsiPgtpo=; b=pLRPv7IWX9tpi1DR3yGFt/EZcrwQwdXxAriSv/U1wagz1rc9ngFe3nYSXobVw76zRD eD8MndUg9g4orjSAZf3j6rN+pbwOwRK9fqNAXj6J7HLGl6cAqC5jN5vum5ZQE1RsDq0K DQHHzkZPWJBHHllGigFWpkhnVZsa+I/CtajpOe31oVAP107DOGFZzvhlkyjiQLknvFwD A+SHchnQBW9vOkPaDJi79WK5GPsTy3Syfw6baal5O6xAKA+dJsuM6WibXqEyL2PIsNin rf95MHVQBthMe1Q2iGcrzBl5jCW4LGU0vP6cpEF/zMEsbc0oIWVAG5XjZJwT2eUboKxa V4JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:mime-version:date:from:subject :thread-topic:to:content-transfer-encoding; bh=WA8aPARa5dl7LzA4eMu5kaaUg+qB5zOABTgVsiPgtpo=; b=MkOwq3IYTir3x9qDIH6dGxhHJtqTwCqprwLjLtcjC+N22dA/LYCX7AgRcpa+KCl3M7 gpdnW8iJCwWIG+jVF6DtvmtodnUL6JSUvLuwBpk96HC+dHscvvD5hb2z4liXFONm1xg7 lylxXZWn6ckkJNbuB+HSWLpy0j6jnN8j5aW/RjxD4sggo6P4NRaVJB3PAwBLMhHa7v2V 5bHonKwUIfcvy5MomhfC01wSOQN9c268T98M6H0aSRsJ0BkJ81t8qPJ3E/SuAZl7pyTR iKjW0p5avO1h3vxbw8MbltjxHKNjCpmcpc9kVAyG5LuGzZ1pVrGNET6SFjHuekRJgFiP F0mQ== X-Gm-Message-State: AGi0PuaOblBUohICdRen9w1pwrpUVve1bpHb62+I8zrFJwEgRefJVJ2T mQrd0xZqGU8jkjfHwI4oDyTm8ntN18M= X-Google-Smtp-Source: APiQypIvlKxut6Uay5F/f7j2SMMekMBl7OVRAsIioRSXbrKQwY8fCKmGFr9y0Jwt2LO226KWOYFUhQ== X-Received: by 2002:a17:902:8eca:: with SMTP id x10mr17934068plo.60.1587881548664; Sat, 25 Apr 2020 23:12:28 -0700 (PDT) Received: from smtp.gmail.com ([2405:201:e808:1fea:c58c:58c:89cf:6018]) by smtp.gmail.com with ESMTPSA id j186sm9441583pfb.220.2020.04.25.23.12.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 Apr 2020 23:12:28 -0700 (PDT) Message-ID: <5ea5264c.1c69fb81.18434.3f14@mx.google.com> MIME-Version: 1.0 Date: Sun, 26 Apr 2020 11:42:22 +0530 From: Rathinavelu Subject: RE: Re: Re: Strategy for optionally excluding a named method parameter? Thread-Topic: RE: Re: Re: Strategy for optionally excluding a named method parameter? To: "users@groovy.apache.org" Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="utf-8"

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

Yes varags. C= ombine 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 se= nt "true"."

Yes You a= re right. The work around is keep the boolean as the last.

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

3.Still your implementation of function is not given, Sir.

T.Rathinavelu

 

Sent from Mail for Windows 10

 

From: David Karr
Sent: Sunday, April 26, 2020 11:34 AM
= To: users@groovy.apache.o= rg
Subject: Re: Re: Strategy for optionally excluding a named= method parameter?

 

=

 

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

Sir,  I do not un= derstand the NEED for your explanation,Sir for I have not 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 is correct.

 

=

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

 

So an work aroun= d if the Boolean is last the situation is Ok

2. calling a functi= on with any number of parameters  involves varag; calling with<= b> named parameters involves   map. They are combined = here.

 

Those are the problems addressed. F= irst line of my mail

Both named and varag

says t= hat.

 

Frankly, I can't understand your point= at all.  At first, I thought you didn't understand my problem, and we= re pointing out irrelevant facts. This reply makes me think that perhaps yo= u noticed some indication of something actually going wrong, but I really c= an't tell.  Please try again to describe what I have "correctly p= ointed out".

 

<= /div>

<= b>Sent: Sunday, April 26, 2020 9:00 AM
To: users@groovy.apache.org; David Karr=
Subject: Re: Strategy for optionally excluding a named method pa= rameter?

 

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

 

You=E2=80=99re doing a =E2=80=9Cprintl= n=E2=80=9D on the first arg (args.one), then a print on the second arg (arg= s.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

 &n= bsp;            = ;            &n= bsp;            = ;string (linefeed)

      true

=  

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

 

     string (the line fieed in prin= tln)

     false (print, no linefeed) string (= linefeed)

      true

 

So. w/o the explanations,  looks exactly what you have

     string

     false= string

     true

 

From: Rathinavelu <rathinavelu@gmail.com>
Reply-To: <users@groovy.apache.o= rg>
Date: Saturday, April 25, 2020 at 9:23 PM
To: "users@= groovy.apache.org" <users@groovy.apache.org>, "users@groovy.apache.org"= ; <users@gr= oovy.apache.org>, David Karr <davidmichaelkarr@gmail.com>
Subje= ct: RE: Re: Strategy for optionally excluding a named method parameter?=

 

Both named and varag=

 

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

<= p class=3DMsoNormal style=3D'mso-margin-top-alt:auto;mso-margin-bottom-alt:= auto'>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][stri= ng]

[true][null]

[false][null]

[true][null]

[false][null]

[true][null]

[false]

&= nbsp;

Please as a work around keep the boolean as the last= parameter. Since map is a subclass of  Object, the func= tion polymorphically accepts map object . But why Boolean be the las= t 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 p= erhaps  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@gr= oovy.apache.org; David Karr
Subject: Re: Strategy for optionally e= xcluding a named method parameter?

 

Hi David,
=
since, as was mentioned, named parameters are implemented as a map unde= rneath in Groovy, you should be able to remove the map entry of the paramet= er you do not want to pass, though I did not try this myself...

Chee= rs,
mg

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

&= nbsp;

 

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

<= div>

Named parameters are not available in Gr= oovy, say, as in Python., though they say it is. Groovy has only mapped par= ameters. The earlier mail works for a single =E2=80=98named=E2=80=99 parame= ter; if there are more parameters 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.Rathi= navelu

 

= The code sample looks something like this:

 

<= /div>

    functionName param1: value,

        param2: value,

        param3: value,

=

        param4: value,=

        ...

        param25: value

 

For instance, we need to mak= e either the previous call or the following:

 

    functionName param1: value,

<= /div>

        param2: value,<= /p>

        param3: val= ue,

        ...

        param25: value

=

 

Where the "param4" key an= d value are not provided.  Presently, we have an "if" checki= ng for a condition, followed by the "true" block with the first v= ersion of the function call with 25 parameters, followed by the "else&= quot; and the "false" block with the second version, 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.

&nbs= p;

 

Sent from Mail for Windows 10<= /p>

 

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

 

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

<= div>

 

I'm working with an api that is somewhat dumb in one respect.  The m= ethod we call takes ~25 parameters.  We send them as named parameters.= One of the parameters is of boolean type.  What we've discovered from= testing is that if we send a value as either "true" or "fal= se", it acts as if we sent "true".  If we construct the= call without that parameter entirely, it acts as if we sent "false&qu= ot;. I tried making it send null, but that just causes it to fail at runtim= e.  We presently have an "if" for that one flag, with two ca= lls to the method, one taking 25 parameters, the other taking 24.  It = is really obnoxious.

 

Obviously, the proper fix is to change the= ir api so that it works correctly.  The reality is, that's not going t= o happen any time soon in geological terms.

 

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

=  

 

 

 

 

 

=