From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-2.9 required=3.0 tests=AWL,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id B250D1F463 for ; Fri, 13 Sep 2019 15:44:36 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 40781120A06; Sat, 14 Sep 2019 00:44:27 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 0150A120A06 for ; Sat, 14 Sep 2019 00:44:24 +0900 (JST) Received: by filter0172p3mdw1.sendgrid.net with SMTP id filter0172p3mdw1-32033-5D7BB956-BD 2019-09-13 15:44:22.792212371 +0000 UTC m=+63724.599685378 Received: from herokuapp.com (unknown [54.242.69.183]) by ismtpd0029p1iad2.sendgrid.net (SG) with ESMTP id R1ZibQ_OQoG4Cn_DzhLj3Q for ; Fri, 13 Sep 2019 15:44:22.726 +0000 (UTC) Date: Fri, 13 Sep 2019 15:44:22 +0000 (UTC) From: shevegen@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 70483 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 16166 X-Redmine-Issue-Author: sawa X-Redmine-Sender: shevegen X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?6lbdtOg4RDRLuxD00eQtQKgoNAsge5d4xND7cbMQd0yBGUJ77=2FSQOo6zayAMcK?= =?us-ascii?Q?6aDztjWA3FoXEDj8MvBn6cGtF6K1iIHqRoWIAxW?= =?us-ascii?Q?QihSilJ=2FxL+YR2nk0ajjOFs+FgkPqGwKfx4s=2FIK?= =?us-ascii?Q?9gyilB7vgEhkTJgx45P+bXZ4WwJVgACh3=2FVE=2FrY?= =?us-ascii?Q?I0giY5PyTn2SBTCFXbIIw2rsCfmtgf455Vg=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 94929 Subject: [ruby-core:94929] [Ruby master Feature#16166] Remove exceptional treatment of *foo when it is the sole block parameter X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #16166 has been updated by shevegen (Robert A. Heiler). > We need an evidence that the behavior actually confuses > many people, at least. It does not confuse me because ... I try to avoid it altogether. :D I think sawa's issue can be a bit shortened (sorry!) to the last comparison: instance_exec(["a"]){|*foo| foo} # => [["a"]] instance_exec(["a"]){|*foo| foo} # => ["a"] Although I may miss (or not completely understand) all of the reasoning, I think that change would make sense (to me) - but I may not understand the consequences. I only remember even matz having fun in a presentation with the whole keyword arg situation before. ;) (One reason why I try to actually avoid keywords is because I find them more difficult to deal/cope with than oldschool options hash. But I guess this may differ from ruby user to ruby user since it is a personal preference.) Perhaps there should be a simple and consistent rule for how * and ** is to be interpreted at all times, including what should happen if both are used at the same time. What I find indeed a bit confusing is that * changes if ** is also used. That part is very strange to me personally. Might also be mentioned in the documentation, but for me personally, I gladly stick to the simpler variants. :D ---------------------------------------- Feature #16166: Remove exceptional treatment of *foo when it is the sole block parameter https://bugs.ruby-lang.org/issues/16166#change-81545 * Author: sawa (Tsuyoshi Sawada) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- In the parameter signature of a code block for a method that is not involved in method definition or creation of lambda objects, two types of arguments `["a"]` and `"a"` are neutralized: ```ruby instance_exec(["a"]){|foo, bar| foo} # => "a" instance_exec("a"){|foo, bar| foo} # => "a" instance_exec(["a"]){|*foo, **bar| foo} # => ["a"] instance_exec("a"){|*foo, **bar| foo} # => ["a"] ``` This is the same behavior as with assignment constructions: ```ruby foo, bar = ["a"]; foo # => "a" foo, bar = "a"; foo # => "a" *foo = ["a"]; foo # => ["a"] *foo = "a"; foo # => ["a"] ``` And it contrasts with constructions involved in method definition or creation of lambda objects, where the distinction is preserved: ```ruby lambda{|foo| foo}.call(["a"]) # => ["a"] lambda{|foo| foo}.call("a") # => "a" ->(foo){foo}.call(["a"]) # => ["a"] ->(foo){foo}.call("a") # => "a" lambda{|*foo| foo}.call(["a"]) # => [["a"]] lambda{|*foo| foo}.call("a") # => ["a"] ->(*foo){foo}.call(["a"]) # => [["a"]] ->(*foo){foo}.call("a") # => ["a"] ``` However, when `*foo` is the sole parameter of a code block for a method that is not involved in method definition or creation of lambda objects, `["a"]` and `"a"` are not neutralized: ```ruby instance_exec(["a"]){|*foo| foo} # => [["a"]] instance_exec("a"){|*foo| foo} # => ["a"] ``` behaving in contrast to assignment constructions, and rather on a par with constructions involved in method definition or creation of lambda objects. Particularly, existence or absence of another parameter `**bar` entirely changes what `foo` refers to: ```ruby instance_exec(["a"]){|*foo| foo} # => [["a"]] instance_exec(["a"]){|*foo, **bar| foo} # => ["a"] ``` I find this behavior inconsistent and confusing. I would like to request to remove this exceptional treatment of splatted parameter `*foo` when it is the sole parameter in a code block. I request this behavior: ```ruby instance_exec(["a"]){|*foo| foo} # => ["a"] ``` -- https://bugs.ruby-lang.org/