* [ruby-core:120252] [Ruby master Bug#20955] Subtle differences with Proc#parameters for anonymous parameters
@ 2024-12-15 19:53 zverok (Victor Shepelev) via ruby-core
2024-12-16 15:18 ` [ruby-core:120261] " bkuhlmann (Brooke Kuhlmann) via ruby-core
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: zverok (Victor Shepelev) via ruby-core @ 2024-12-15 19:53 UTC (permalink / raw)
To: ruby-core; +Cc: zverok (Victor Shepelev)
Issue #20955 has been reported by zverok (Victor Shepelev).
----------------------------------------
Bug #20955: Subtle differences with Proc#parameters for anonymous parameters
https://bugs.ruby-lang.org/issues/20955
* 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/
^ permalink raw reply [flat|nested] 9+ messages in thread
* [ruby-core:120261] [Ruby master Bug#20955] Subtle differences with Proc#parameters for anonymous parameters
2024-12-15 19:53 [ruby-core:120252] [Ruby master Bug#20955] Subtle differences with Proc#parameters for anonymous parameters zverok (Victor Shepelev) via ruby-core
@ 2024-12-16 15:18 ` bkuhlmann (Brooke Kuhlmann) via ruby-core
2024-12-16 15:24 ` [ruby-core:120262] " zverok (Victor Shepelev) via ruby-core
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: bkuhlmann (Brooke Kuhlmann) via ruby-core @ 2024-12-16 15:18 UTC (permalink / raw)
To: ruby-core; +Cc: bkuhlmann (Brooke Kuhlmann)
Issue #20955 has been updated by bkuhlmann (Brooke Kuhlmann).
Good catch. I would expect the following behavor:
```
proc { it }.parameters #=> [[:opt, :it]]
lambda { it }.parameters #=> [[:req, :it]]
```
This would be consistent with existing behavior as shown with the `x` and `_1` variables. Is there a reason why `it` would need to behave differently?
----------------------------------------
Bug #20955: Subtle differences with Proc#parameters for anonymous parameters
https://bugs.ruby-lang.org/issues/20955#change-111027
* 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/
^ permalink raw reply [flat|nested] 9+ messages in thread
* [ruby-core:120262] [Ruby master Bug#20955] Subtle differences with Proc#parameters for anonymous parameters
2024-12-15 19:53 [ruby-core:120252] [Ruby master Bug#20955] Subtle differences with Proc#parameters for anonymous parameters zverok (Victor Shepelev) via ruby-core
2024-12-16 15:18 ` [ruby-core:120261] " bkuhlmann (Brooke Kuhlmann) via ruby-core
@ 2024-12-16 15:24 ` zverok (Victor Shepelev) via ruby-core
2024-12-16 17:13 ` [ruby-core:120263] " bkuhlmann (Brooke Kuhlmann) via ruby-core
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: zverok (Victor Shepelev) via ruby-core @ 2024-12-16 15:24 UTC (permalink / raw)
To: ruby-core; +Cc: zverok (Victor Shepelev)
Issue #20955 has been updated by zverok (Victor Shepelev).
@bkuhlmann The only possible reason is not to confuse with this:
```ruby
proc { |it| }.parameters # the parameter is literally named "it"
```
I am not sure it matters much, but maybe in somebody’s metaprogramming... I don’t remember seeing libraries in Ruby that changed behavior depending on parameter names (and changing it on parameter name `it` seems even less plausible), but theoretically, it _could_ happen.
(The situation is unlike `_1`, which is NOT allowed to be an explicit parameter name.)
----------------------------------------
Bug #20955: Subtle differences with Proc#parameters for anonymous parameters
https://bugs.ruby-lang.org/issues/20955#change-111028
* 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/
^ permalink raw reply [flat|nested] 9+ messages in thread
* [ruby-core:120263] [Ruby master Bug#20955] Subtle differences with Proc#parameters for anonymous parameters
2024-12-15 19:53 [ruby-core:120252] [Ruby master Bug#20955] Subtle differences with Proc#parameters for anonymous parameters zverok (Victor Shepelev) via ruby-core
2024-12-16 15:18 ` [ruby-core:120261] " bkuhlmann (Brooke Kuhlmann) via ruby-core
2024-12-16 15:24 ` [ruby-core:120262] " zverok (Victor Shepelev) via ruby-core
@ 2024-12-16 17:13 ` bkuhlmann (Brooke Kuhlmann) via ruby-core
2024-12-16 19:42 ` [ruby-core:120267] " zverok (Victor Shepelev) via ruby-core
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: bkuhlmann (Brooke Kuhlmann) via ruby-core @ 2024-12-16 17:13 UTC (permalink / raw)
To: ruby-core; +Cc: bkuhlmann (Brooke Kuhlmann)
Issue #20955 has been updated by bkuhlmann (Brooke Kuhlmann).
@zverok Makes sense...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 realize this would break backwards compatibility in terms of semantic versioning, though._
That said, I can provide an example of `it` -- as currently implemented in Ruby 3.4.0-rc1 -- that would cause issues with my [Marameters](https://alchemists.io/projects/marameters) gem. ⚠️ Please note that the syntax I'm showing you is for the next _major_ release of the gem once Ruby 3.4.0 is released:
``` ruby
parameters = proc { it }.parameters
signature = Marameters.signature(parameters).to_s # " = nil"
Demo = Module.new do
module_eval <<~METHOD, __FILE__, __LINE__ + 1
def self.test(#{signature}) = "This is a demo."
METHOD
end
Demo.test # syntax errors found (SyntaxError)
# ↑ This is because a method signature of `test( = nil)` is definitely not syntactically valid.
```
I can definitely fix my Marameters gem to account for this use case but would be nice to ensure `Method#parameters` _always_ answers an array than can immediately be used to _dynamically_ build a new method signature that is _syntactically correct_.
----------------------------------------
Bug #20955: Subtle differences with Proc#parameters for anonymous parameters
https://bugs.ruby-lang.org/issues/20955#change-111030
* 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/
^ permalink raw reply [flat|nested] 9+ messages in thread
* [ruby-core:120267] [Ruby master Bug#20955] Subtle differences with Proc#parameters for anonymous parameters
2024-12-15 19:53 [ruby-core:120252] [Ruby master Bug#20955] Subtle differences with Proc#parameters for anonymous parameters zverok (Victor Shepelev) via ruby-core
` (2 preceding siblings ...)
2024-12-16 17:13 ` [ruby-core:120263] " bkuhlmann (Brooke Kuhlmann) via ruby-core
@ 2024-12-16 19:42 ` zverok (Victor Shepelev) via ruby-core
2024-12-17 0:03 ` [ruby-core:120273] " bkuhlmann (Brooke Kuhlmann) via ruby-core
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: zverok (Victor Shepelev) via ruby-core @ 2024-12-16 19:42 UTC (permalink / raw)
To: ruby-core; +Cc: zverok (Victor Shepelev)
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/
^ permalink raw reply [flat|nested] 9+ messages in thread
* [ruby-core:120273] [Ruby master Bug#20955] Subtle differences with Proc#parameters for anonymous parameters
2024-12-15 19:53 [ruby-core:120252] [Ruby master Bug#20955] Subtle differences with Proc#parameters for anonymous parameters zverok (Victor Shepelev) via ruby-core
` (3 preceding siblings ...)
2024-12-16 19:42 ` [ruby-core:120267] " zverok (Victor Shepelev) via ruby-core
@ 2024-12-17 0:03 ` bkuhlmann (Brooke Kuhlmann) via ruby-core
2024-12-19 7:11 ` [ruby-core:120318] " k0kubun (Takashi Kokubun) via ruby-core
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: bkuhlmann (Brooke Kuhlmann) via ruby-core @ 2024-12-17 0:03 UTC (permalink / raw)
To: ruby-core; +Cc: bkuhlmann (Brooke Kuhlmann)
Issue #20955 has been updated by bkuhlmann (Brooke Kuhlmann).
Thanks. When I mentioned "consistency" I was mostly concerned about getting a parameters array from `Proc#parameters` that I could use to construct an equivalent method signature but this won't be a problem with normal method signatures (well, sort of), only procs/lambdas will exhibit this behavior. I guess this is OK but does feel weird especially since you can end up with a required/optional parameter with no name. The only non-proc situation I can think of is when using a required parameter with array destructuring. Example:
``` ruby
def demo((one, two)) = puts "One: #{one}, Two: #{two}"
method(:demo).parameters # [[:req]]
```
----------------------------------------
Bug #20955: Subtle differences with Proc#parameters for anonymous parameters
https://bugs.ruby-lang.org/issues/20955#change-111040
* 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/
^ permalink raw reply [flat|nested] 9+ messages in thread
* [ruby-core:120318] [Ruby master Bug#20955] Subtle differences with Proc#parameters for anonymous parameters
2024-12-15 19:53 [ruby-core:120252] [Ruby master Bug#20955] Subtle differences with Proc#parameters for anonymous parameters zverok (Victor Shepelev) via ruby-core
` (4 preceding siblings ...)
2024-12-17 0:03 ` [ruby-core:120273] " bkuhlmann (Brooke Kuhlmann) via ruby-core
@ 2024-12-19 7:11 ` k0kubun (Takashi Kokubun) via ruby-core
2024-12-23 4:53 ` [ruby-core:120371] " k0kubun (Takashi Kokubun) via ruby-core
2025-01-14 17:11 ` [ruby-core:120666] " alanwu (Alan Wu) via ruby-core
7 siblings, 0 replies; 9+ messages in thread
From: k0kubun (Takashi Kokubun) via ruby-core @ 2024-12-19 7:11 UTC (permalink / raw)
To: ruby-core; +Cc: k0kubun (Takashi Kokubun)
Issue #20955 has been updated by k0kubun (Takashi Kokubun).
Agreed that `it` should work like `_1` here. You couldn't distinguish `proc {it}.parameters` with `proc {|it|}.parameters`, but these procs work in the same way anyway, so it shouldn't matter.
Note that nobu's PR https://github.com/ruby/ruby/pull/12398 for https://bugs.ruby-lang.org/issues/20965 fixes this too.
----------------------------------------
Bug #20955: Subtle differences with Proc#parameters for anonymous parameters
https://bugs.ruby-lang.org/issues/20955#change-111088
* 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/
^ permalink raw reply [flat|nested] 9+ messages in thread
* [ruby-core:120371] [Ruby master Bug#20955] Subtle differences with Proc#parameters for anonymous parameters
2024-12-15 19:53 [ruby-core:120252] [Ruby master Bug#20955] Subtle differences with Proc#parameters for anonymous parameters zverok (Victor Shepelev) via ruby-core
` (5 preceding siblings ...)
2024-12-19 7:11 ` [ruby-core:120318] " k0kubun (Takashi Kokubun) via ruby-core
@ 2024-12-23 4:53 ` k0kubun (Takashi Kokubun) via ruby-core
2025-01-14 17:11 ` [ruby-core:120666] " alanwu (Alan Wu) via ruby-core
7 siblings, 0 replies; 9+ messages in thread
From: k0kubun (Takashi Kokubun) via ruby-core @ 2024-12-23 4:53 UTC (permalink / raw)
To: ruby-core; +Cc: k0kubun (Takashi Kokubun)
Issue #20955 has been updated by k0kubun (Takashi Kokubun).
Status changed from Closed to Open
Since fixing this raised issues like https://bugs.ruby-lang.org/issues/20970 and it's too close to the release to design the behavior properly, we reverted https://github.com/ruby/ruby/pull/12398 for Ruby 3.4.
----------------------------------------
Bug #20955: Subtle differences with Proc#parameters for anonymous parameters
https://bugs.ruby-lang.org/issues/20955#change-111148
* 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/
^ permalink raw reply [flat|nested] 9+ messages in thread
* [ruby-core:120666] [Ruby master Bug#20955] Subtle differences with Proc#parameters for anonymous parameters
2024-12-15 19:53 [ruby-core:120252] [Ruby master Bug#20955] Subtle differences with Proc#parameters for anonymous parameters zverok (Victor Shepelev) via ruby-core
` (6 preceding siblings ...)
2024-12-23 4:53 ` [ruby-core:120371] " k0kubun (Takashi Kokubun) via ruby-core
@ 2025-01-14 17:11 ` alanwu (Alan Wu) via ruby-core
7 siblings, 0 replies; 9+ messages in thread
From: alanwu (Alan Wu) via ruby-core @ 2025-01-14 17:11 UTC (permalink / raw)
To: ruby-core; +Cc: alanwu (Alan Wu)
Issue #20955 has been updated by alanwu (Alan Wu).
Status changed from Open to Closed
AFAICT #20974 fully addressed the issue in the OP, and `it` behaves the same as anonymous destructuring parameters.
```shell
$ ./miniruby -ve 'p proc { it }.parameters #=> [[:opt, nil]]
p lambda { it }.parameters #=> [[:req]]'
ruby 3.5.0dev (2025-01-14T16:46:11Z master b076e9b7ac) +PRISM [arm64-darwin24]
[[:opt]]
[[:req]]
```
----------------------------------------
Bug #20955: Subtle differences with Proc#parameters for anonymous parameters
https://bugs.ruby-lang.org/issues/20955#change-111491
* Author: zverok (Victor Shepelev)
* Status: Closed
* 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/
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-01-14 17:12 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-15 19:53 [ruby-core:120252] [Ruby master Bug#20955] Subtle differences with Proc#parameters for anonymous parameters zverok (Victor Shepelev) via ruby-core
2024-12-16 15:18 ` [ruby-core:120261] " bkuhlmann (Brooke Kuhlmann) via ruby-core
2024-12-16 15:24 ` [ruby-core:120262] " zverok (Victor Shepelev) via ruby-core
2024-12-16 17:13 ` [ruby-core:120263] " bkuhlmann (Brooke Kuhlmann) via ruby-core
2024-12-16 19:42 ` [ruby-core:120267] " zverok (Victor Shepelev) via ruby-core
2024-12-17 0:03 ` [ruby-core:120273] " bkuhlmann (Brooke Kuhlmann) via ruby-core
2024-12-19 7:11 ` [ruby-core:120318] " k0kubun (Takashi Kokubun) via ruby-core
2024-12-23 4:53 ` [ruby-core:120371] " k0kubun (Takashi Kokubun) via ruby-core
2025-01-14 17:11 ` [ruby-core:120666] " alanwu (Alan Wu) via ruby-core
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).