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=-3.9 required=3.0 tests=BAYES_00, 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 5B2CE1F463 for ; Mon, 2 Dec 2019 15:55:37 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id E1EB1120912; Tue, 3 Dec 2019 00:55:25 +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 074FB12090C for ; Tue, 3 Dec 2019 00:55:23 +0900 (JST) Received: by filter0181p3mdw1.sendgrid.net with SMTP id filter0181p3mdw1-14486-5DE533F2-39 2019-12-02 15:55:30.771365561 +0000 UTC m=+1094398.805043994 Received: from herokuapp.com (unknown [18.212.157.225]) by ismtpd0040p1iad2.sendgrid.net (SG) with ESMTP id GCqrWYM1S22OeQaHAxt5IQ for ; Mon, 02 Dec 2019 15:55:30.614 +0000 (UTC) Date: Mon, 02 Dec 2019 15:55:30 +0000 (UTC) From: daniel@dan42.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 71699 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 16166 X-Redmine-Issue-Author: sawa X-Redmine-Sender: Dan0042 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?8sy4RigFvRTdBfCVJrT9zb2J88PC92TMQwdNgaWYaq583Ef+=2FCHeE+X8WKWgq7?= =?us-ascii?Q?8ikoBrk+EfuZwCQ5RexhRpQBg1rYWqVmEYJS+d4?= =?us-ascii?Q?77qe02XCgaSK8V7D4MnAE9r7YLVAdK0DbjZdEpX?= =?us-ascii?Q?5mBqWfN26Wk8SVzTgYYot96hJXLMMA6QuijNu4f?= =?us-ascii?Q?PfeWwptuIJP2s3oveKq06Oeou0QQkdO58LA=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 96059 Subject: [ruby-core:96059] [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="iso-8859-1" Content-Transfer-Encoding: quoted-printable Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #16166 has been updated by Dan0042 (Daniel DeLorme). Eregon (Benoit Daloze) wrote: > The `*rest` parameter will not splat either, or it would delegate argumen= ts incorrectly. Thanks! Finally I can see some meaning behind the madness. Normally I would= expect `proc{ |*a| }.call([1,2])` to behave like the assignment `*a =3D [1= ,2]` but it does not. But now I can see that `proc{ |*a| foo(*a) }.call(arg= 1)` would not work if `arg1` happened to be an array. However I still believe that the current behavior for `proc{ |*a| }` is wro= ng. If you want that particular case of delegation to work you should simpl= y use a lambda instead of a proc. Having that special exception where a pro= c behaves like a lambda just for `*rest`... it makes things overly complica= ted. I mean, even mame says he cannot understand the condition! With all du= e respect to Matz, this would be much simpler if we could say that all proc= s behave with assignment semantics, and lambdas with parameter semantics. Of course the backward compatibility is an issue but that can be handled wi= th proper deprecation warnings. I think that would be a worthwhile change f= or ruby. My 2=A2. ---------------------------------------- Feature #16166: Remove exceptional treatment of *foo when it is the sole bl= ock parameter https://bugs.ruby-lang.org/issues/16166#change-82905 * 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 involve= d in method definition or creation of lambda objects, two types of argument= s `["a"]` and `"a"` are neutralized: ```ruby instance_exec(["a"]){|foo, bar| foo} # =3D> "a" instance_exec("a"){|foo, bar| foo} # =3D> "a" instance_exec(["a"]){|*foo, **bar| foo} # =3D> ["a"] instance_exec("a"){|*foo, **bar| foo} # =3D> ["a"] ``` This is the same behavior as with assignment constructions: ```ruby foo, bar =3D ["a"]; foo # =3D> "a" foo, bar =3D "a"; foo # =3D> "a" *foo =3D ["a"]; foo # =3D> ["a"] *foo =3D "a"; foo # =3D> ["a"] ``` And it contrasts with constructions involved in method definition or creati= on of lambda objects, where the distinction is preserved: ```ruby lambda{|foo| foo}.call(["a"]) # =3D> ["a"] lambda{|foo| foo}.call("a") # =3D> "a" ->(foo){foo}.call(["a"]) # =3D> ["a"] ->(foo){foo}.call("a") # =3D> "a" lambda{|*foo| foo}.call(["a"]) # =3D> [["a"]] lambda{|*foo| foo}.call("a") # =3D> ["a"] ->(*foo){foo}.call(["a"]) # =3D> [["a"]] ->(*foo){foo}.call("a") # =3D> ["a"] ``` However, when `*foo` is the sole parameter of a code block for a method tha= t is not involved in method definition or creation of lambda objects, `["a"= ]` and `"a"` are not neutralized: ```ruby instance_exec(["a"]){|*foo| foo} # =3D> [["a"]] instance_exec("a"){|*foo| foo} # =3D> ["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 ch= anges what `foo` refers to: ```ruby instance_exec(["a"]){|*foo| foo} # =3D> [["a"]] instance_exec(["a"]){|*foo, **bar| foo} # =3D> ["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} # =3D> ["a"] ``` -- = https://bugs.ruby-lang.org/ Unsubscribe: