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.6 required=3.0 tests=BAYES_00, 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 A8DCA1F885 for ; Sat, 11 Jan 2020 11:49:32 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 689A4120A82; Sat, 11 Jan 2020 20:49:07 +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 F2989120A75 for ; Sat, 11 Jan 2020 20:49:03 +0900 (JST) Received: by filterdrecv-p3mdw1-56c97568b5-2vkp8 with SMTP id filterdrecv-p3mdw1-56c97568b5-2vkp8-20-5E19B630-1 2020-01-11 11:49:04.002115592 +0000 UTC m=+2199957.244706195 Received: from herokuapp.com (unknown [54.224.129.129]) by ismtpd0052p1mdw1.sendgrid.net (SG) with ESMTP id Ti7kWTjzQqK89KyGMeojDQ for ; Sat, 11 Jan 2020 11:49:03.748 +0000 (UTC) Date: Sat, 11 Jan 2020 11:49:04 +0000 (UTC) From: realfengjia@foxmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 72449 X-Redmine-Project: ruby-master X-Redmine-Issue-Id: 16496 X-Redmine-Issue-Author: JustinFeng X-Redmine-Sender: JustinFeng 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?tJnAg3QxZ+bWapezgnsbzoIBMwnFp7r8mZuUa+K7+LqEBX9XxV8EhwUTOY0oiQ?= =?us-ascii?Q?kTMZLnAFxieBdzy7n7K66aA8Z8Pps0RR8F3J9RL?= =?us-ascii?Q?oLsAkGuKhzcechDf+L5hHxwBZQZi79Bqwx3Yfh4?= =?us-ascii?Q?9s5RpkF1Q5A3A73I+Nhde6V2zpjXsc6CNosHuhz?= =?us-ascii?Q?Gwhhz+4l4TYjsaq1IgXZ9Ykw3=2FVlBKkaPeTiNPS?= =?us-ascii?Q?zLC71N0gmcjBAzt54=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 96786 Subject: [ruby-core:96786] [Ruby master Bug#16496] Numbered Parameter not parsed properly in lambda 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 #16496 has been updated by JustinFeng (Justin Feng). mame (Yusuke Endoh) wrote: > `_1 *1` is parsed as `_1(*1)`, a call to a method `_1` with a variable-length argument with `1`. It is the same as `p * ary` and `p *ary`. You can see a warning under verbose mode: > > ``` > $ ruby -w -e '-> { _1 *1 }.call' > -e:1: warning: `*' interpreted as argument prefix > ... > ``` > > It is difficult to change until a method name `_1` is valid. Hi Yusuke, thank you for the reply understand there is limitation on the numbered parameter, just feel it's mame (Yusuke Endoh) wrote: > `_1 *1` is parsed as `_1(*1)`, a call to a method `_1` with a variable-length argument with `1`. It is the same as `p * ary` and `p *ary`. You can see a warning under verbose mode: > > ``` > $ ruby -w -e '-> { _1 *1 }.call' > -e:1: warning: `*' interpreted as argument prefix > ... > ``` > > It is difficult to change until a method name `_1` is valid. Hi Yusuke, thank you for the reply, good to understand what caused the issue However, it just makes me feel the numbered parameter behaves different from traditional block parameter ``` 2.7.0 :001 > l = lambda {|p| p *1 } 2.7.0 :002 > l[2] => 2 2.7.0 :003 > l = lambda {|p| p * 1 } 2.7.0 :004 > l[2] => 2 ``` ---------------------------------------- Bug #16496: Numbered Parameter not parsed properly in lambda https://bugs.ruby-lang.org/issues/16496#change-83780 * Author: JustinFeng (Justin Feng) * Status: Rejected * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin18] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- The space between `*` and `1` changes the lambda behaviour, looks like numbered parameter `_1` is not parsed properly ``` 2.7.0 :001 > l = -> { _1 * 1 } 2.7.0 :002 > l[2] => 2 2.7.0 :003 > l2 = -> { _1 *1 } 2.7.0 :004 > l2[2] Traceback (most recent call last): 5: from /Users/justin.feng/.rvm/rubies/ruby-2.7.0/bin/irb:23:in `
' 4: from /Users/justin.feng/.rvm/rubies/ruby-2.7.0/bin/irb:23:in `load' 3: from /Users/justin.feng/.rvm/rubies/ruby-2.7.0/lib/ruby/gems/2.7.0/gems/irb-1.2.1/exe/irb:11:in `' 2: from (irb):4 1: from (irb):3:in `block in irb_binding' ArgumentError (wrong number of arguments (given 1, expected 0)) 2.7.0 :005 > ``` -- https://bugs.ruby-lang.org/