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 CADD618731 for ; Tue, 1 Dec 2015 16:20:04 +0000 (UTC) Received: (qmail 95963 invoked by uid 500); 1 Dec 2015 16:19:06 -0000 Delivered-To: apmail-groovy-users-archive@groovy.apache.org Received: (qmail 95934 invoked by uid 500); 1 Dec 2015 16:19:06 -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 95924 invoked by uid 99); 1 Dec 2015 16:19:06 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Dec 2015 16:19:06 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id C5911C059C for ; Tue, 1 Dec 2015 16:19:05 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.12 X-Spam-Level: X-Spam-Status: No, score=-0.12 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Authentication-Results: spamd4-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 (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id cPd15HkuZuas for ; Tue, 1 Dec 2015 16:19:00 +0000 (UTC) Received: from mail-wm0-f48.google.com (mail-wm0-f48.google.com [74.125.82.48]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTPS id 285EB2074C for ; Tue, 1 Dec 2015 16:19:00 +0000 (UTC) Received: by wmvv187 with SMTP id v187so214748944wmv.1 for ; Tue, 01 Dec 2015 08:18:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=eeCPybItdwDS0KUfW4lte7EsnwwxLQ1gO7sSWXWzL1A=; b=WMt87yOmvisKnbPLCAPOG2c+AmCfdgKJh4xOIUYxiF3VkAnd9p49vt1Wi4eWTR6zg/ ZcFkQektmqA969GDAeaBKcH6hAp0AKFlV6FJpPQTFKr/Fr80sB2f3IHFPp1XE5z4j6CG DHdhTOPX+Pt3S7k1D1X2LOGDEWcK1QJn8CMqL+2DwolGf6PxPA/OU95R7mcQxHMXYYkk t7aXc72sO2VAegDX47R2NxfQ3CRdC0GNpseUQDkqHnenj5USj61x5rDgKfErHp+WHOHi CMsamg5ZOBWX+o/lm7Y/yOn18hSLqqVWSpJFMbL4Ai7W5YC1lemLYj+KrlqwRcyZI6k6 67pw== MIME-Version: 1.0 X-Received: by 10.28.50.70 with SMTP id y67mr38102851wmy.91.1448986739906; Tue, 01 Dec 2015 08:18:59 -0800 (PST) Received: by 10.194.137.102 with HTTP; Tue, 1 Dec 2015 08:18:59 -0800 (PST) Date: Tue, 1 Dec 2015 17:18:59 +0100 Message-ID: Subject: "External" closures, why? From: alessio To: users@groovy.incubator.apache.org Content-Type: text/plain; charset=UTF-8 Hi, I have just started to dig into Groovy and have been mostly impressed by what it offers, however when I had a look at handling database calls (http://docs.groovy-lang.org/latest/html/api/groovy/sql/Sql.html) I stumbled upon a rather weird syntax sql.eachRow('select * from PROJECT where name=:foo', [foo:'Gradle']) { // process row } Usually I'd say this is a "regular" block scope but in this context it was obviously a closure/function pointer/callback. It took me a while to dig into this to find out that it can also be passed as second argument to the method and was added in 2.2 http://www.groovy-lang.org/semantics.html#_calling_a_method_accepting_a_sam_type_with_a_closure https://issues.apache.org/jira/browse/GROOVY-6188 (the JSR link does not work anymore) My question now is, why? Apparently pre-2.2 one had to cast the closure to the appropriate type. But why making it possible to actually define the closure outside of the respective call? At least for me this is HIGHLY confusing. Thanks