* [ruby-dev:52146] [Ruby master Bug#21123] instance_exec with curried proc
@ 2025-02-07 14:54 taichi730 (Taichi Ishitani) via ruby-dev
2025-02-07 21:21 ` [ruby-dev:52147] " mame (Yusuke Endoh) via ruby-dev
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: taichi730 (Taichi Ishitani) via ruby-dev @ 2025-02-07 14:54 UTC (permalink / raw)
To: ruby-dev; +Cc: taichi730 (Taichi Ishitani)
Issue #21123 has been reported by taichi730 (Taichi Ishitani).
----------------------------------------
Bug #21123: instance_exec with curried proc
https://bugs.ruby-lang.org/issues/21123
* Author: taichi730 (Taichi Ishitani)
* Status: Open
* ruby -v: 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
I have a question about behavior of `#instance_exec` with a curried proc.
When running `#instance_exex` with a curried proc, it appears that the given proc is executed on the context where it is created but not the receiver object.
Example code:
```ruby
a = Object.new
def a.foo(n)
p
end
b = proc { |n| foo(n) }.curry
a.instance_exec(0, &b)
```
Execution result:
```
$ ruby test.rb
test.rb:6:in 'block in <main>': undefined method 'foo' for main (NoMethodError)
b = proc { |n| foo(n) }.curry
^^^
Did you mean? for
from test.rb:7:in 'BasicObject#instance_exec'
from test.rb:7:in '<main>'
```
Is this intentional behavior?
I expect that the given curried proc is also executed on the context of the receiver object like a non-curried proc.
--
https://bugs.ruby-lang.org/
_______________________________________________
ruby-dev mailing list -- ruby-dev@ml.ruby-lang.org
To unsubscribe send an email to ruby-dev-leave@ml.ruby-lang.org
^ permalink raw reply [flat|nested] 4+ messages in thread
* [ruby-dev:52147] [Ruby master Bug#21123] instance_exec with curried proc
2025-02-07 14:54 [ruby-dev:52146] [Ruby master Bug#21123] instance_exec with curried proc taichi730 (Taichi Ishitani) via ruby-dev
@ 2025-02-07 21:21 ` mame (Yusuke Endoh) via ruby-dev
2025-02-08 15:44 ` [ruby-dev:52148] " taichi730 (Taichi Ishitani) via ruby-dev
2025-02-09 8:49 ` [ruby-dev:52149] " byroot (Jean Boussier) via ruby-dev
2 siblings, 0 replies; 4+ messages in thread
From: mame (Yusuke Endoh) via ruby-dev @ 2025-02-07 21:21 UTC (permalink / raw)
To: ruby-dev; +Cc: mame (Yusuke Endoh)
Issue #21123 has been updated by mame (Yusuke Endoh).
I believe this behavior is by design.
`Proc#curry` returns a wrapper Proc that calls to a given Proc. In other words, your code is essentially the same as the following code.
```ruby
a = Object.new
def a.foo(n)
p
end
b = proc { |n| foo(n) }
b2 = proc { |n| b.call(n) }
a.instance_exec(0, &b2)
```
`instance_exec` replaces self in the context of Proc `b2`, but it does not propagate to the context of Proc `b`.
----------------------------------------
Bug #21123: instance_exec with curried proc
https://bugs.ruby-lang.org/issues/21123#change-111792
* Author: taichi730 (Taichi Ishitani)
* Status: Open
* ruby -v: 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
I have a question about behavior of `#instance_exec` with a curried proc.
When running `#instance_exex` with a curried proc, it appears that the given proc is executed on the context where it is created but not the receiver object.
Example code:
```ruby
a = Object.new
def a.foo(n)
p
end
b = proc { |n| foo(n) }.curry
a.instance_exec(0, &b)
```
Execution result:
```
$ ruby test.rb
test.rb:6:in 'block in <main>': undefined method 'foo' for main (NoMethodError)
b = proc { |n| foo(n) }.curry
^^^
Did you mean? for
from test.rb:7:in 'BasicObject#instance_exec'
from test.rb:7:in '<main>'
```
Is this intentional behavior?
I expect that the given curried proc is also executed on the context of the receiver object like a non-curried proc.
--
https://bugs.ruby-lang.org/
_______________________________________________
ruby-dev mailing list -- ruby-dev@ml.ruby-lang.org
To unsubscribe send an email to ruby-dev-leave@ml.ruby-lang.org
^ permalink raw reply [flat|nested] 4+ messages in thread
* [ruby-dev:52148] [Ruby master Bug#21123] instance_exec with curried proc
2025-02-07 14:54 [ruby-dev:52146] [Ruby master Bug#21123] instance_exec with curried proc taichi730 (Taichi Ishitani) via ruby-dev
2025-02-07 21:21 ` [ruby-dev:52147] " mame (Yusuke Endoh) via ruby-dev
@ 2025-02-08 15:44 ` taichi730 (Taichi Ishitani) via ruby-dev
2025-02-09 8:49 ` [ruby-dev:52149] " byroot (Jean Boussier) via ruby-dev
2 siblings, 0 replies; 4+ messages in thread
From: taichi730 (Taichi Ishitani) via ruby-dev @ 2025-02-08 15:44 UTC (permalink / raw)
To: ruby-dev; +Cc: taichi730 (Taichi Ishitani)
Issue #21123 has been updated by taichi730 (Taichi Ishitani).
Hi @mame san,
Thanks for your explanation and I understood the reason of this behavior.
I have no reasonable thought but I think it would be nice that curried blocks are able to be executed by `#instance_exec`.
----------------------------------------
Bug #21123: instance_exec with curried proc
https://bugs.ruby-lang.org/issues/21123#change-111796
* Author: taichi730 (Taichi Ishitani)
* Status: Open
* ruby -v: 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
I have a question about behavior of `#instance_exec` with a curried proc.
When running `#instance_exex` with a curried proc, it appears that the given proc is executed on the context where it is created but not the receiver object.
Example code:
```ruby
a = Object.new
def a.foo(n)
p
end
b = proc { |n| foo(n) }.curry
a.instance_exec(0, &b)
```
Execution result:
```
$ ruby test.rb
test.rb:6:in 'block in <main>': undefined method 'foo' for main (NoMethodError)
b = proc { |n| foo(n) }.curry
^^^
Did you mean? for
from test.rb:7:in 'BasicObject#instance_exec'
from test.rb:7:in '<main>'
```
Is this intentional behavior?
I expect that the given curried proc is also executed on the context of the receiver object like a non-curried proc.
--
https://bugs.ruby-lang.org/
_______________________________________________
ruby-dev mailing list -- ruby-dev@ml.ruby-lang.org
To unsubscribe send an email to ruby-dev-leave@ml.ruby-lang.org
^ permalink raw reply [flat|nested] 4+ messages in thread
* [ruby-dev:52149] [Ruby master Bug#21123] instance_exec with curried proc
2025-02-07 14:54 [ruby-dev:52146] [Ruby master Bug#21123] instance_exec with curried proc taichi730 (Taichi Ishitani) via ruby-dev
2025-02-07 21:21 ` [ruby-dev:52147] " mame (Yusuke Endoh) via ruby-dev
2025-02-08 15:44 ` [ruby-dev:52148] " taichi730 (Taichi Ishitani) via ruby-dev
@ 2025-02-09 8:49 ` byroot (Jean Boussier) via ruby-dev
2 siblings, 0 replies; 4+ messages in thread
From: byroot (Jean Boussier) via ruby-dev @ 2025-02-09 8:49 UTC (permalink / raw)
To: ruby-dev; +Cc: byroot (Jean Boussier)
Issue #21123 has been updated by byroot (Jean Boussier).
Status changed from Open to Rejected
I agree with @mame this isn't a bug, and by design.
And I don't see how it could reasonably be changed without breaking lots of code.
----------------------------------------
Bug #21123: instance_exec with curried proc
https://bugs.ruby-lang.org/issues/21123#change-111805
* Author: taichi730 (Taichi Ishitani)
* Status: Rejected
* ruby -v: 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
I have a question about behavior of `#instance_exec` with a curried proc.
When running `#instance_exex` with a curried proc, it appears that the given proc is executed on the context where it is created but not the receiver object.
Example code:
```ruby
a = Object.new
def a.foo(n)
p
end
b = proc { |n| foo(n) }.curry
a.instance_exec(0, &b)
```
Execution result:
```
$ ruby test.rb
test.rb:6:in 'block in <main>': undefined method 'foo' for main (NoMethodError)
b = proc { |n| foo(n) }.curry
^^^
Did you mean? for
from test.rb:7:in 'BasicObject#instance_exec'
from test.rb:7:in '<main>'
```
Is this intentional behavior?
I expect that the given curried proc is also executed on the context of the receiver object like a non-curried proc.
--
https://bugs.ruby-lang.org/
_______________________________________________
ruby-dev mailing list -- ruby-dev@ml.ruby-lang.org
To unsubscribe send an email to ruby-dev-leave@ml.ruby-lang.org
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-02-09 8:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-07 14:54 [ruby-dev:52146] [Ruby master Bug#21123] instance_exec with curried proc taichi730 (Taichi Ishitani) via ruby-dev
2025-02-07 21:21 ` [ruby-dev:52147] " mame (Yusuke Endoh) via ruby-dev
2025-02-08 15:44 ` [ruby-dev:52148] " taichi730 (Taichi Ishitani) via ruby-dev
2025-02-09 8:49 ` [ruby-dev:52149] " byroot (Jean Boussier) via ruby-dev
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).