* [ruby-core:71664] [Ruby trunk - Feature #11737] [Open] Pass in expression to then block in `case expression`
[not found] <redmine.issue-11737.20151124205922@ruby-lang.org>
@ 2015-11-24 20:59 ` 6ftdan
2015-11-24 21:03 ` [ruby-core:71665] [Ruby trunk - Feature #11737] " 6ftdan
` (7 subsequent siblings)
8 siblings, 0 replies; 9+ messages in thread
From: 6ftdan @ 2015-11-24 20:59 UTC (permalink / raw)
To: ruby-core
Issue #11737 has been reported by Daniel P. Clark.
----------------------------------------
Feature #11737: Pass in expression to then block in `case expression`
https://bugs.ruby-lang.org/issues/11737
* Author: Daniel P. Clark
* Status: Open
* Priority: Normal
* Assignee:
----------------------------------------
Ruby's `case <expression>` scenario allows the expression to be tested in the `when` test with `:===`, but in the then block the expression is not accessible. Only if the expression has been assigned to a variable beforehand can it be checked.
~~~ruby
case 4
when ->i{ puts :when; true}
->i{ puts i}
else
:foo
end
# when
# => #<Proc:0x00000000d91e58@(irb):16 (lambda)>
case 4
when ->i{ puts :when; true}
puts _
else
:foo
end
# when
# #<Proc:0x00000000d91e58@(irb):16 (lambda)>
# => nil
case 4
when 4
then _
end
# => nil
case 4
when 4
then ->i{puts i}
end
# => #<Proc:0x000000015f9be0@(irb):36 (lambda)>
~~~
If some one wanted to give an expression after case that wasn't assigned to a variable then there is no access to it in the then block.
I suggest assigning the expression to the `_` variable during a case/when/then scenario. Here's a rather contrived example use case.
~~~ruby
case Enumerator.new do |y| y << 1; y << 2; y << 3; end
when ->e{ 2.times e.next; true}
then _.peek
end == 3
~~~
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 9+ messages in thread
* [ruby-core:71665] [Ruby trunk - Feature #11737] Pass in expression to then block in `case expression`
[not found] <redmine.issue-11737.20151124205922@ruby-lang.org>
2015-11-24 20:59 ` [ruby-core:71664] [Ruby trunk - Feature #11737] [Open] Pass in expression to then block in `case expression` 6ftdan
@ 2015-11-24 21:03 ` 6ftdan
2015-11-25 18:56 ` [ruby-core:71686] " 6ftdan
` (6 subsequent siblings)
8 siblings, 0 replies; 9+ messages in thread
From: 6ftdan @ 2015-11-24 21:03 UTC (permalink / raw)
To: ruby-core
Issue #11737 has been updated by Daniel P. Clark.
Please fix the when scenario in the last example
~~~ruby
case Enumerator.new do |y| y << 1; y << 2; y << 3; end
when ->e{ 2.times{e.next}; true}
then _.peek
end == 3
~~~
----------------------------------------
Feature #11737: Pass in expression to then block in `case expression`
https://bugs.ruby-lang.org/issues/11737#change-55067
* Author: Daniel P. Clark
* Status: Open
* Priority: Normal
* Assignee:
----------------------------------------
Ruby's `case <expression>` scenario allows the expression to be tested in the `when` test with `:===`, but in the then block the expression is not accessible. Only if the expression has been assigned to a variable beforehand can it be checked.
~~~ruby
case 4
when ->i{ puts :when; true}
->i{ puts i}
else
:foo
end
# when
# => #<Proc:0x00000000d91e58@(irb):16 (lambda)>
case 4
when ->i{ puts :when; true}
puts _
else
:foo
end
# when
# #<Proc:0x00000000d91e58@(irb):16 (lambda)>
# => nil
case 4
when 4
then _
end
# => nil
case 4
when 4
then ->i{puts i}
end
# => #<Proc:0x000000015f9be0@(irb):36 (lambda)>
~~~
If some one wanted to give an expression after case that wasn't assigned to a variable then there is no access to it in the then block.
I suggest assigning the expression to the `_` variable during a case/when/then scenario. Here's a rather contrived example use case.
~~~ruby
case Enumerator.new do |y| y << 1; y << 2; y << 3; end
when ->e{ 2.times e.next; true}
then _.peek
end == 3
~~~
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 9+ messages in thread
* [ruby-core:71686] [Ruby trunk - Feature #11737] Pass in expression to then block in `case expression`
[not found] <redmine.issue-11737.20151124205922@ruby-lang.org>
2015-11-24 20:59 ` [ruby-core:71664] [Ruby trunk - Feature #11737] [Open] Pass in expression to then block in `case expression` 6ftdan
2015-11-24 21:03 ` [ruby-core:71665] [Ruby trunk - Feature #11737] " 6ftdan
@ 2015-11-25 18:56 ` 6ftdan
2015-11-28 0:10 ` [ruby-core:71715] " nobu
` (5 subsequent siblings)
8 siblings, 0 replies; 9+ messages in thread
From: 6ftdan @ 2015-11-25 18:56 UTC (permalink / raw)
To: ruby-core
Issue #11737 has been updated by Daniel P. Clark.
Since https://bugs.ruby-lang.org/issues/11734#note-3 has informed me the `_` is an IRB feature and Minitest uses `_()` in its test suite perhaps we should not use `_` for the case/when/then.
How about `__case__`
~~~ruby
case Enumerator.new do |y| y << 1; y << 2; y << 3; end
when ->e{ 2.times{e.next}; true}
then __case__.peek
end == 3
~~~
----------------------------------------
Feature #11737: Pass in expression to then block in `case expression`
https://bugs.ruby-lang.org/issues/11737#change-55090
* Author: Daniel P. Clark
* Status: Open
* Priority: Normal
* Assignee:
----------------------------------------
Ruby's `case <expression>` scenario allows the expression to be tested in the `when` test with `:===`, but in the then block the expression is not accessible. Only if the expression has been assigned to a variable beforehand can it be checked.
~~~ruby
case 4
when ->i{ puts :when; true}
->i{ puts i}
else
:foo
end
# when
# => #<Proc:0x00000000d91e58@(irb):16 (lambda)>
case 4
when ->i{ puts :when; true}
puts _
else
:foo
end
# when
# #<Proc:0x00000000d91e58@(irb):16 (lambda)>
# => nil
case 4
when 4
then _
end
# => nil
case 4
when 4
then ->i{puts i}
end
# => #<Proc:0x000000015f9be0@(irb):36 (lambda)>
~~~
If some one wanted to give an expression after case that wasn't assigned to a variable then there is no access to it in the then block.
I suggest assigning the expression to the `_` variable during a case/when/then scenario. Here's a rather contrived example use case.
~~~ruby
case Enumerator.new do |y| y << 1; y << 2; y << 3; end
when ->e{ 2.times e.next; true}
then _.peek
end == 3
~~~
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 9+ messages in thread
* [ruby-core:71715] [Ruby trunk - Feature #11737] Pass in expression to then block in `case expression`
[not found] <redmine.issue-11737.20151124205922@ruby-lang.org>
` (2 preceding siblings ...)
2015-11-25 18:56 ` [ruby-core:71686] " 6ftdan
@ 2015-11-28 0:10 ` nobu
2015-11-28 8:56 ` [ruby-core:71719] " 6ftdan
` (4 subsequent siblings)
8 siblings, 0 replies; 9+ messages in thread
From: nobu @ 2015-11-28 0:10 UTC (permalink / raw)
To: ruby-core
Issue #11737 has been updated by Nobuyoshi Nakada.
It reminded me a rejected proposal:
~~~ruby
case expr
when matcher => result
...
end
~~~
----------------------------------------
Feature #11737: Pass in expression to then block in `case expression`
https://bugs.ruby-lang.org/issues/11737#change-55121
* Author: Daniel P. Clark
* Status: Open
* Priority: Normal
* Assignee:
----------------------------------------
Ruby's `case <expression>` scenario allows the expression to be tested in the `when` test with `:===`, but in the then block the expression is not accessible. Only if the expression has been assigned to a variable beforehand can it be checked.
~~~ruby
case 4
when ->i{ puts :when; true}
->i{ puts i}
else
:foo
end
# when
# => #<Proc:0x00000000d91e58@(irb):16 (lambda)>
case 4
when ->i{ puts :when; true}
puts _
else
:foo
end
# when
# #<Proc:0x00000000d91e58@(irb):16 (lambda)>
# => nil
case 4
when 4
then _
end
# => nil
case 4
when 4
then ->i{puts i}
end
# => #<Proc:0x000000015f9be0@(irb):36 (lambda)>
~~~
If some one wanted to give an expression after case that wasn't assigned to a variable then there is no access to it in the then block.
I suggest assigning the expression to the `_` variable during a case/when/then scenario. Here's a rather contrived example use case.
~~~ruby
case Enumerator.new do |y| y << 1; y << 2; y << 3; end
when ->e{ 2.times e.next; true}
then _.peek
end == 3
~~~
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 9+ messages in thread
* [ruby-core:71719] [Ruby trunk - Feature #11737] Pass in expression to then block in `case expression`
[not found] <redmine.issue-11737.20151124205922@ruby-lang.org>
` (3 preceding siblings ...)
2015-11-28 0:10 ` [ruby-core:71715] " nobu
@ 2015-11-28 8:56 ` 6ftdan
2015-12-03 4:07 ` [ruby-core:71810] " s.wanabe
` (3 subsequent siblings)
8 siblings, 0 replies; 9+ messages in thread
From: 6ftdan @ 2015-11-28 8:56 UTC (permalink / raw)
To: ruby-core
Issue #11737 has been updated by Daniel P. Clark.
Nobuyoshi Nakada wrote:
> It reminded me a rejected proposal:
>
> ~~~ruby
> case expr
> when matcher => result
> ...
> end
> ~~~
It's not too different from what already works if you create a variable beforehand.
~~~ruby
e = Enumerator.new do |y| y << 1; y << 2; y << 3; end
case e
when ->x{ 2.times{x.next}; true}
then e.peek
end == 3
# => true
~~~
I just found it odd that in the when clause I can use a proc to grab the current case item, but in the then block there is nothing to check unless a variable has already been assigned.
----------------------------------------
Feature #11737: Pass in expression to then block in `case expression`
https://bugs.ruby-lang.org/issues/11737#change-55125
* Author: Daniel P. Clark
* Status: Open
* Priority: Normal
* Assignee:
----------------------------------------
Ruby's `case <expression>` scenario allows the expression to be tested in the `when` test with `:===`, but in the then block the expression is not accessible. Only if the expression has been assigned to a variable beforehand can it be checked.
~~~ruby
case 4
when ->i{ puts :when; true}
->i{ puts i}
else
:foo
end
# when
# => #<Proc:0x00000000d91e58@(irb):16 (lambda)>
case 4
when ->i{ puts :when; true}
puts _
else
:foo
end
# when
# #<Proc:0x00000000d91e58@(irb):16 (lambda)>
# => nil
case 4
when 4
then _
end
# => nil
case 4
when 4
then ->i{puts i}
end
# => #<Proc:0x000000015f9be0@(irb):36 (lambda)>
~~~
If some one wanted to give an expression after case that wasn't assigned to a variable then there is no access to it in the then block.
I suggest assigning the expression to the `_` variable during a case/when/then scenario. Here's a rather contrived example use case.
~~~ruby
case Enumerator.new do |y| y << 1; y << 2; y << 3; end
when ->e{ 2.times e.next; true}
then _.peek
end == 3
~~~
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 9+ messages in thread
* [ruby-core:71810] [Ruby trunk - Feature #11737] Pass in expression to then block in `case expression`
[not found] <redmine.issue-11737.20151124205922@ruby-lang.org>
` (4 preceding siblings ...)
2015-11-28 8:56 ` [ruby-core:71719] " 6ftdan
@ 2015-12-03 4:07 ` s.wanabe
2015-12-04 23:43 ` [ruby-core:71839] " 6ftdan
` (2 subsequent siblings)
8 siblings, 0 replies; 9+ messages in thread
From: s.wanabe @ 2015-12-03 4:07 UTC (permalink / raw)
To: ruby-core
Issue #11737 has been updated by _ wanabe.
Nobuyoshi Nakada wrote:
> It reminded me a rejected proposal:
>
> ~~~ruby
> case expr
> when matcher => result
> ...
> end
> ~~~
Is the proposal [ruby-dev:17615]?
Or other?
----------------------------------------
Feature #11737: Pass in expression to then block in `case expression`
https://bugs.ruby-lang.org/issues/11737#change-55214
* Author: Daniel P. Clark
* Status: Open
* Priority: Normal
* Assignee:
----------------------------------------
Ruby's `case <expression>` scenario allows the expression to be tested in the `when` test with `:===`, but in the then block the expression is not accessible. Only if the expression has been assigned to a variable beforehand can it be checked.
~~~ruby
case 4
when ->i{ puts :when; true}
->i{ puts i}
else
:foo
end
# when
# => #<Proc:0x00000000d91e58@(irb):16 (lambda)>
case 4
when ->i{ puts :when; true}
puts _
else
:foo
end
# when
# #<Proc:0x00000000d91e58@(irb):16 (lambda)>
# => nil
case 4
when 4
then _
end
# => nil
case 4
when 4
then ->i{puts i}
end
# => #<Proc:0x000000015f9be0@(irb):36 (lambda)>
~~~
If some one wanted to give an expression after case that wasn't assigned to a variable then there is no access to it in the then block.
I suggest assigning the expression to the `_` variable during a case/when/then scenario. Here's a rather contrived example use case.
~~~ruby
case Enumerator.new do |y| y << 1; y << 2; y << 3; end
when ->e{ 2.times e.next; true}
then _.peek
end == 3
~~~
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 9+ messages in thread
* [ruby-core:71839] [Ruby trunk - Feature #11737] Pass in expression to then block in `case expression`
[not found] <redmine.issue-11737.20151124205922@ruby-lang.org>
` (5 preceding siblings ...)
2015-12-03 4:07 ` [ruby-core:71810] " s.wanabe
@ 2015-12-04 23:43 ` 6ftdan
2015-12-07 7:41 ` [ruby-core:71888] [Ruby trunk - Feature #11737] [Rejected] " matz
2015-12-07 11:22 ` [ruby-core:71902] [Ruby trunk - Feature #11737] " 6ftdan
8 siblings, 0 replies; 9+ messages in thread
From: 6ftdan @ 2015-12-04 23:43 UTC (permalink / raw)
To: ruby-core
Issue #11737 has been updated by Daniel P. Clark.
~~~ruby
case 4 # __case__ = 4
when 4 # 4 === __case__
puts "Success! #{__case__} is what we wanted!" # __case__ not defined! ... where did it go?
end
~~~
----------------------------------------
Feature #11737: Pass in expression to then block in `case expression`
https://bugs.ruby-lang.org/issues/11737#change-55243
* Author: Daniel P. Clark
* Status: Open
* Priority: Normal
* Assignee:
----------------------------------------
Ruby's `case <expression>` scenario allows the expression to be tested in the `when` test with `:===`, but in the then block the expression is not accessible. Only if the expression has been assigned to a variable beforehand can it be checked.
~~~ruby
case 4
when ->i{ puts :when; true}
->i{ puts i}
else
:foo
end
# when
# => #<Proc:0x00000000d91e58@(irb):16 (lambda)>
case 4
when ->i{ puts :when; true}
puts _
else
:foo
end
# when
# #<Proc:0x00000000d91e58@(irb):16 (lambda)>
# => nil
case 4
when 4
then _
end
# => nil
case 4
when 4
then ->i{puts i}
end
# => #<Proc:0x000000015f9be0@(irb):36 (lambda)>
~~~
If some one wanted to give an expression after case that wasn't assigned to a variable then there is no access to it in the then block.
I suggest assigning the expression to the `_` variable during a case/when/then scenario. Here's a rather contrived example use case.
~~~ruby
case Enumerator.new do |y| y << 1; y << 2; y << 3; end
when ->e{ 2.times e.next; true}
then _.peek
end == 3
~~~
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 9+ messages in thread
* [ruby-core:71888] [Ruby trunk - Feature #11737] [Rejected] Pass in expression to then block in `case expression`
[not found] <redmine.issue-11737.20151124205922@ruby-lang.org>
` (6 preceding siblings ...)
2015-12-04 23:43 ` [ruby-core:71839] " 6ftdan
@ 2015-12-07 7:41 ` matz
2015-12-07 11:22 ` [ruby-core:71902] [Ruby trunk - Feature #11737] " 6ftdan
8 siblings, 0 replies; 9+ messages in thread
From: matz @ 2015-12-07 7:41 UTC (permalink / raw)
To: ruby-core
Issue #11737 has been updated by Yukihiro Matsumoto.
Status changed from Open to Rejected
It's not worth adding special expression or variable for retrieving the when value.
Just use assignment.
Matz.
----------------------------------------
Feature #11737: Pass in expression to then block in `case expression`
https://bugs.ruby-lang.org/issues/11737#change-55294
* Author: Daniel P. Clark
* Status: Rejected
* Priority: Normal
* Assignee:
----------------------------------------
Ruby's `case <expression>` scenario allows the expression to be tested in the `when` test with `:===`, but in the then block the expression is not accessible. Only if the expression has been assigned to a variable beforehand can it be checked.
~~~ruby
case 4
when ->i{ puts :when; true}
->i{ puts i}
else
:foo
end
# when
# => #<Proc:0x00000000d91e58@(irb):16 (lambda)>
case 4
when ->i{ puts :when; true}
puts _
else
:foo
end
# when
# #<Proc:0x00000000d91e58@(irb):16 (lambda)>
# => nil
case 4
when 4
then _
end
# => nil
case 4
when 4
then ->i{puts i}
end
# => #<Proc:0x000000015f9be0@(irb):36 (lambda)>
~~~
If some one wanted to give an expression after case that wasn't assigned to a variable then there is no access to it in the then block.
I suggest assigning the expression to the `_` variable during a case/when/then scenario. Here's a rather contrived example use case.
~~~ruby
case Enumerator.new do |y| y << 1; y << 2; y << 3; end
when ->e{ 2.times e.next; true}
then _.peek
end == 3
~~~
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 9+ messages in thread
* [ruby-core:71902] [Ruby trunk - Feature #11737] Pass in expression to then block in `case expression`
[not found] <redmine.issue-11737.20151124205922@ruby-lang.org>
` (7 preceding siblings ...)
2015-12-07 7:41 ` [ruby-core:71888] [Ruby trunk - Feature #11737] [Rejected] " matz
@ 2015-12-07 11:22 ` 6ftdan
8 siblings, 0 replies; 9+ messages in thread
From: 6ftdan @ 2015-12-07 11:22 UTC (permalink / raw)
To: ruby-core
Issue #11737 has been updated by Daniel P. Clark.
Thank you. I appreciate your consideration.
----------------------------------------
Feature #11737: Pass in expression to then block in `case expression`
https://bugs.ruby-lang.org/issues/11737#change-55305
* Author: Daniel P. Clark
* Status: Rejected
* Priority: Normal
* Assignee:
----------------------------------------
Ruby's `case <expression>` scenario allows the expression to be tested in the `when` test with `:===`, but in the then block the expression is not accessible. Only if the expression has been assigned to a variable beforehand can it be checked.
~~~ruby
case 4
when ->i{ puts :when; true}
->i{ puts i}
else
:foo
end
# when
# => #<Proc:0x00000000d91e58@(irb):16 (lambda)>
case 4
when ->i{ puts :when; true}
puts _
else
:foo
end
# when
# #<Proc:0x00000000d91e58@(irb):16 (lambda)>
# => nil
case 4
when 4
then _
end
# => nil
case 4
when 4
then ->i{puts i}
end
# => #<Proc:0x000000015f9be0@(irb):36 (lambda)>
~~~
If some one wanted to give an expression after case that wasn't assigned to a variable then there is no access to it in the then block.
I suggest assigning the expression to the `_` variable during a case/when/then scenario. Here's a rather contrived example use case.
~~~ruby
case Enumerator.new do |y| y << 1; y << 2; y << 3; end
when ->e{ 2.times e.next; true}
then _.peek
end == 3
~~~
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2015-12-07 10:51 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <redmine.issue-11737.20151124205922@ruby-lang.org>
2015-11-24 20:59 ` [ruby-core:71664] [Ruby trunk - Feature #11737] [Open] Pass in expression to then block in `case expression` 6ftdan
2015-11-24 21:03 ` [ruby-core:71665] [Ruby trunk - Feature #11737] " 6ftdan
2015-11-25 18:56 ` [ruby-core:71686] " 6ftdan
2015-11-28 0:10 ` [ruby-core:71715] " nobu
2015-11-28 8:56 ` [ruby-core:71719] " 6ftdan
2015-12-03 4:07 ` [ruby-core:71810] " s.wanabe
2015-12-04 23:43 ` [ruby-core:71839] " 6ftdan
2015-12-07 7:41 ` [ruby-core:71888] [Ruby trunk - Feature #11737] [Rejected] " matz
2015-12-07 11:22 ` [ruby-core:71902] [Ruby trunk - Feature #11737] " 6ftdan
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 read-only IMAP folder(s) and NNTP newsgroup(s).