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 [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6032A1831C for ; Sat, 8 Aug 2015 17:00:11 +0000 (UTC) Received: (qmail 40255 invoked by uid 500); 8 Aug 2015 17:00:11 -0000 Delivered-To: apmail-groovy-users-archive@groovy.apache.org Received: (qmail 40222 invoked by uid 500); 8 Aug 2015 17:00:11 -0000 Mailing-List: contact users-help@groovy.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@groovy.incubator.apache.org Delivered-To: mailing list users@groovy.incubator.apache.org Received: (qmail 40212 invoked by uid 99); 8 Aug 2015 17:00:11 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 08 Aug 2015 17:00:11 +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 B90C01A9AC7 for ; Sat, 8 Aug 2015 17:00:10 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.9 X-Spam-Level: ** X-Spam-Status: No, score=2.9 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=3, SPF_PASS=-0.001, URIBL_BLOCKED=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-eu-west.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id gWdWoZqtXxD7 for ; Sat, 8 Aug 2015 17:00:03 +0000 (UTC) Received: from mail-yk0-f181.google.com (mail-yk0-f181.google.com [209.85.160.181]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTPS id 2C48F20FA9 for ; Sat, 8 Aug 2015 17:00:03 +0000 (UTC) Received: by ykcq64 with SMTP id q64so105995967ykc.2 for ; Sat, 08 Aug 2015 10:00:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=HDOUSM7qsJuQjnuC8AXOeLYbVeALBwtrErCWQTyNW/E=; b=ZWP0I2n5vD9Xb7c0rjfNvjoLKTMkDVD3sktucybuO6ZJqgNhVYxIaNxwsuUEBE1oP7 7/4nS4M8nJJakkf65m/3P2Ag4sov5gwJPNr8hfOsLjTxrNTJ+U27MGJftxm5f9DblEmg JKnE/hreQ8bR6PoIOe4+i32H4Nw1gun6Fr3v0ceF5l46cSvZ4bP9xnLVC8/Hhr7uaWgj 4WFHJ8PDgDxJf0H19r6ZVgsQWwhTH0TCVd9rnPjspXjTSk05nbGuf1w60dC+VvmCmJ5N zqO2So5D79jLtnLHE/Jg3qYtx+JLCtWDbEpmDlTBsKacauOjoqcOE56XEAa/KsizZluE nJLA== MIME-Version: 1.0 X-Received: by 10.170.211.133 with SMTP id c127mr13555256ykf.59.1439053202177; Sat, 08 Aug 2015 10:00:02 -0700 (PDT) Received: by 10.129.34.139 with HTTP; Sat, 8 Aug 2015 10:00:02 -0700 (PDT) In-Reply-To: References: Date: Sat, 8 Aug 2015 10:00:02 -0700 Message-ID: Subject: Re: Curious that Groovy case can match values that are not equal to the candidate From: Owen Rubel To: users@groovy.incubator.apache.org Content-Type: multipart/alternative; boundary=001a11394e68edc45b051ccfae1d --001a11394e68edc45b051ccfae1d Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Yeah I knew that. Love the fact that regex is now being used for pattern matching where pattern matching is called for in Groovy. Have to wonder why no one thought of this before :) Owen Rubel 415-971-0976 orubel@gmail.com On Sat, Aug 8, 2015 at 9:09 AM, Guillaume Laforge wrote: > You can use closures for arbitrary conditions (the return value is > evaluated via Groovy truth), or regexes so it checks the toString of the > value, etc. > > Pretty powerful! > Le 8 ao=C3=BBt 2015 17:09, "Owen Rubel" a =C3=A9crit : > >> Fascinating. Had no idea. Learn something new every day :) >> >> Owen Rubel >> 415-971-0976 >> orubel@gmail.com >> >> On Fri, Aug 7, 2015 at 10:21 PM, Guillaume Laforge >> wrote: >> >>> Hi David, >>> >>> Groovy 's switch is a bit special and his beyond Java' s. >>> Please have a look at the documentation about it. >>> When a list is passed, it checks if the element is contained within. >>> >>> Guillaume >>> Le 7 ao=C3=BBt 2015 23:07, "KARR, DAVID" a =C3=A9crit = : >>> >>>> Reading REGINA, I find this detail of Groovy semantics very curious: >>>> ---------------------- >>>> def myList =3D ['a', 'b', 'c'] >>>> switch ('c') { >>>> case myList: assert true;break; >>>> default: assert false;break; >>>> } >>>> -------------- >>>> >>>> In all the languages I'm aware of with some sort of "switch/case" >>>> construct, you can always assume that if the "case" matches, then the >>>> "case" value "is equal to" the switch candidate. This is the first ti= me >>>> I've seen this not be the case. >>>> >>>> I certainly understand what Groovy is doing here, and I appreciate the >>>> power of it, it's just a bit surprising. >>>> >>> >> --001a11394e68edc45b051ccfae1d Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Yeah I knew that. Love the fact that regex is now being us= ed for pattern matching where pattern matching is called for in Groovy. Hav= e to wonder why no one thought of this before :)

Owen Rubel
4= 15-971-0976
orubel= @gmail.com

On Sat, Aug 8, 2015 at 9:09 AM, Guillaume La= forge <glaforge@gmail.com> wrote:

You can use closures for arbitrary conditions (the = return value is evaluated via Groovy truth), or regexes so it checks the to= String of the value, etc.

Pretty powerful!

Le=C2=A08 ao=C3=BBt 2015 17:09, "Owen Rubel= " <orubel@gma= il.com> a =C3=A9crit=C2=A0:
Fascinating. Had no idea. Learn something n= ew every day :)

On Fri, Aug 7, 2015 at 10:21 PM, Guillaume L= aforge <glaforge@gmail.com> wrote:

Hi David,

Groovy 's switch is a bit special and his beyond Java= 9; s.
Please have a look at the documentation about it.
When a list is passed, it checks if the element is contained within.

Guillaume

Le=C2=A07 ao=C3=BBt 2015 23:07, "KARR, DAVI= D" <dk068x@att.= com> a =C3=A9crit=C2=A0:
Reading REGINA, I find this detail of Groovy semantics very c= urious:
----------------------
def myList =3D ['a', 'b', 'c']
switch ('c') {
case myList: assert true;break;
default: assert false;break;
}
--------------

In all the languages I'm aware of with some sort of "switch/case&q= uot; construct, you can always assume that if the "case" matches,= then the "case" value "is equal to" the switch candida= te.=C2=A0 This is the first time I've seen this not be the case.

I certainly understand what Groovy is doing here, and I appreciate the powe= r of it, it's just a bit surprising.


--001a11394e68edc45b051ccfae1d--