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 B96881F463 for ; Fri, 13 Sep 2019 15:46:00 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 69D3A120A1C; Sat, 14 Sep 2019 00:45:53 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id CB9091209CC for ; Sat, 14 Sep 2019 00:45:50 +0900 (JST) Received: by filter0183p3mdw1.sendgrid.net with SMTP id filter0183p3mdw1-25784-5D7BB9B3-70 2019-09-13 15:45:55.358625437 +0000 UTC m=+63050.925659205 Received: from herokuapp.com (unknown [54.242.69.183]) by ismtpd0001p1iad1.sendgrid.net (SG) with ESMTP id -Dk_QS79Se-ERV-don79xw for ; Fri, 13 Sep 2019 15:45:55.334 +0000 (UTC) Date: Fri, 13 Sep 2019 15:45:55 +0000 (UTC) From: shevegen@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 70484 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?6lbdtOg4RDRLuxD00eQtQKgoNAsge5d4xND7cbMQd0yT+KDIneUKq9VvDbLEj1?= =?us-ascii?Q?VDCUbxpjbZUPY8z3msm=2FzoY=2F4TRH3Rnt6+MPkeQ?= =?us-ascii?Q?MsYT+PI=2F=2FGOhRceUicdQNNVgu7GL90HKn0m3i+0?= =?us-ascii?Q?JgMZzHw=2FVsccVdyXow80pOQOnrlhhcJg1jYbf25?= =?us-ascii?Q?o6OHsyIOYjfwcFopkGs8Z8t3XPOfL1YDZJQ=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 94930 Subject: [ruby-core:94930] [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). Actually that reminds me - mame mentioned that the ruby core team needs a motivation/impetus if a change is necessary based on real usage. So I think this may be a good call for ruby users to comment in particular when it may affect them (either way) in actual code. Me personally I am not affected in either way, but it may be a good idea to get a survey/query to ruby users out there to comment, in particular when it may affect them in their own code base or a code base they use/depend on. ---------------------------------------- Feature #16166: Remove exceptional treatment of *foo when it is the sole block parameter https://bugs.ruby-lang.org/issues/16166#change-81546 * 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/