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 22B411F463 for ; Thu, 26 Sep 2019 17:31:05 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 4F2E2120AAC; Fri, 27 Sep 2019 02:30:55 +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 7FDF21208A8 for ; Fri, 27 Sep 2019 02:30:52 +0900 (JST) Received: by filter0104p3las1.sendgrid.net with SMTP id filter0104p3las1-29704-5D8CF5CD-87 2019-09-26 17:30:53.797426448 +0000 UTC m=+252655.422653809 Received: from herokuapp.com (unknown [34.207.207.12]) by ismtpd0087p1iad2.sendgrid.net (SG) with ESMTP id fMXdAm6oTeOE-xqIGZBkEw for ; Thu, 26 Sep 2019 17:30:53.622 +0000 (UTC) Date: Thu, 26 Sep 2019 17:30:53 +0000 (UTC) From: XrXr@users.noreply.github.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 70671 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 16178 X-Redmine-Issue-Author: Eregon X-Redmine-Issue-Assignee: matz X-Redmine-Sender: alanwu 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?PWg67P6owy8ojUUZg1G=2FQM4Z0jTQ2XLCqLM8Y2L8tUvRFuUPM6+aKANjRFY5CJ?= =?us-ascii?Q?rIjmSXtroCMiL6psRiFqMGyhejkJQtXraZgQ6iu?= =?us-ascii?Q?PQL9XaAOe9Uu=2Ff9LFkXnM4Xh1Xryhi6X2Bd0fjt?= =?us-ascii?Q?V2IKOsEbwmL7P1IkVCpVRPC0eQsbsGC=2FX+Kmgfc?= =?us-ascii?Q?LFK3g9dkq02IMNhVPB0kQi4prz4yzR02ueQ=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 95116 Subject: [ruby-core:95116] [Ruby master Bug#16178] Numbered parameters: _1 should be the same as |x| and _0 should not exist 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 #16178 has been updated by alanwu (Alan Wu). Eregon (Benoit Daloze) wrote: > Dan0042 (Daniel DeLorme) wrote: > > > How would we define the current semantics, without being very complex or confusing? > > > > Beautifully simple: > > _0 is a single implicit parameter, as in x in { |x| } > > _1 is the first numbered parameter, as in x in { |x,y,z,etc| } > > That's incomplete, it's much more tricky than that in the now previous semantics: > `_1` is the first numbered parameter, as in `x` in `{ |x,y,z,etc| }` if there are at least 2 numbered parameters or the first parameter's runtime value is not an Array, otherwise extracts the first argument of the first parameter. That's still incomplete, since it doesn't explain why `_1` doesn't decompose when used in lambdas. If it always decomposes, it'd be more self consistent. Anyways, I like the new rule better, since it has less corner cases. ---------------------------------------- Bug #16178: Numbered parameters: _1 should be the same as |x| and _0 should not exist https://bugs.ruby-lang.org/issues/16178#change-81750 * Author: Eregon (Benoit Daloze) * Status: Closed * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * Target version: * ruby -v: ruby 2.7.0dev (2019-09-24T12:57:54Z master 0e84eecc17) [x86_64-linux] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- Currently on trunk: ```ruby array = ["string", 42, [1, 2]] array.map { |x| x * 2 } # => ["stringstring", 84, [1, 2, 1, 2]] array.map { _1 * 2 } # => ["stringstring", 84, 2] ``` Oops, this trivial code just lost data and completely ignored the element class! This is clearly contrary to intuition and is very dangerous. Using `_0` instead has the correct behavior but it's clear we use 1-based indexing for numbered parameters, and it doesn't solve that `_1` has dangerous behavior. Basically the current behavior is that `_0` is the same as `|x|` and `_1` is the same as `|x,|`. `|x,|` is almost never used in Ruby, and for good reasons, it just throws away data/information/the class of the object. Such a dangerous operation should only be done when it's explicit, and the trailing comma in `|x,|` shows that, but `_1` does not. So let's make `_1` be `|x|` and remove `_0`. I am going to be harsh, but this discussion has gone too long without any serious written argument for the current behavior: I believe it's irrational and irresponsible to have `_1` be `|x,|`, it's just going to lead to nasty bugs. Try to convince me otherwise. If not, in one week I want to apply this change. >From the discussion in https://bugs.ruby-lang.org/issues/15723#note-127 and in https://bugs.ruby-lang.org/issues/15708 Some reactions to this behavior in https://twitter.com/eregontp/status/1115318993299083265 -- https://bugs.ruby-lang.org/