From: realfengjia@... Date: 2020-01-11T11:49:04+00:00 Subject: [ruby-core:96786] [Ruby master Bug#16496] Numbered Parameter not parsed properly in lambda 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/ Unsubscribe: