From: "zverok (Victor Shepelev) via ruby-core" <ruby-core@...> Date: 2024-12-16T19:42:19+00:00 Subject: [ruby-core:120267] [Ruby master Bug#20955] Subtle differences with Proc#parameters for anonymous parameters Issue #20955 has been updated by zverok (Victor Shepelev). > but this behavior would be nice (again, thinking in terms of consistency): ```ruby proc { |_1| }.parameters # _1 is reserved for numbered parameter (SyntaxError) proc { |it| }.parameters # it is a reserved block parameter (SyntaxError) ``` I believe that when `it` was introduced, it was common understanding that it should be as non-invasive as humanly possible, so it should never be deprecated as a local variable name or explicit parameter name. It is a common short word, so amount of codebases that use it, including as an explicit name, is probably significant (as a shortcut for `it`em, or "`i`ndex of `t`ime point" or somesuch). `it` and `_1` are explicitly not, and would not be, consistent by this account and by several others (say, allowing usage in the nested blocks ��� though the latter seems less justified to me). ---------------------------------------- Bug #20955: Subtle differences with Proc#parameters for anonymous parameters https://bugs.ruby-lang.org/issues/20955#change-111034 * Author: zverok (Victor Shepelev) * Status: Open * ruby -v: ruby 3.4.0dev (2024-12-15T13:36:38Z master 366fd9642f) +PRISM [x86_64-linux] * Backport: 3.1: DONTNEED, 3.2: DONTNEED, 3.3: DONTNEED ---------------------------------------- ```ruby p proc { |x| }.parameters #=> [[:opt, :x]] p lambda { |x| }.parameters #=> [[:req, :x]] p proc { _1 }.parameters #=> [[:opt, :_1]] p lambda { _1 }.parameters #=> [[:req, :_1]] p proc { it }.parameters #=> [[:opt, nil]] p lambda { it }.parameters #=> [[:req]] ``` Note the last pair; here are two small confusing problems: 1. For proc, unlike numbered parameters, the parameter name is `nil` (not `it`). This, though, can be justified to distinguish from `proc { |it| }` case 2. But also, `proc` has this `nil` for a parameter name, while `lambda` has not. I am not sure what the ���most logical��� thing to do here, but I believe that at least `proc { it }` and `lambda { it }` should be made consistent with each other. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/