ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:99390] [Ruby master Bug#17058] Array#delete_if doesn't change array instantly
@ 2020-07-29 15:18 erik
  2020-07-29 15:33 ` [ruby-core:99392] " merch-redmine
  2020-07-29 15:37 ` [ruby-core:99394] " merch-redmine
  0 siblings, 2 replies; 3+ messages in thread
From: erik @ 2020-07-29 15:18 UTC (permalink / raw)
  To: ruby-core

Issue #17058 has been reported by erik_schlyter (Erik Schlyter).

----------------------------------------
Bug #17058: Array#delete_if doesn't change array instantly
https://bugs.ruby-lang.org/issues/17058

* Author: erik_schlyter (Erik Schlyter)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
According to the documentation: https://ruby-doc.org/core-2.7.1/Array.html#method-i-delete_if
"The array is changed instantly every time the block is called, not after the iteration is over."

I've tried printing the array while iterating it:
```
a = [1,2,3,4,5,6,7]
a.delete_if{|x|
  puts "During iteration: #{a}"
  x % 2 == 0
}
puts "After iteration: #{a}"
```

The output is as follows:
```
During iteration: [1, 2, 3, 4, 5, 6, 7]
During iteration: [1, 2, 3, 4, 5, 6, 7]
During iteration: [1, 2, 3, 4, 5, 6, 7]
During iteration: [1, 3, 3, 4, 5, 6, 7]
During iteration: [1, 3, 3, 4, 5, 6, 7]
During iteration: [1, 3, 5, 4, 5, 6, 7]
During iteration: [1, 3, 5, 4, 5, 6, 7]
After iteration: [1, 3, 5, 7]
```

This functionality has changed somewhere between 2.2.2 and 2.4.0. When I use "ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]", I get the following (correct) output:
```
During iteration: [1, 2, 3, 4, 5, 6, 7]
During iteration: [1, 2, 3, 4, 5, 6, 7]
During iteration: [1, 3, 4, 5, 6, 7]
During iteration: [1, 3, 4, 5, 6, 7]
During iteration: [1, 3, 5, 6, 7]
During iteration: [1, 3, 5, 6, 7]
During iteration: [1, 3, 5, 7]
After iteration: [1, 3, 5, 7]

```
When I use "ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]" or the latest (2.7.1), I get the wrong output.


The functionality doesn't seem crucial, but the documentation should be correct.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:99392] [Ruby master Bug#17058] Array#delete_if doesn't change array instantly
  2020-07-29 15:18 [ruby-core:99390] [Ruby master Bug#17058] Array#delete_if doesn't change array instantly erik
@ 2020-07-29 15:33 ` merch-redmine
  2020-07-29 15:37 ` [ruby-core:99394] " merch-redmine
  1 sibling, 0 replies; 3+ messages in thread
From: merch-redmine @ 2020-07-29 15:33 UTC (permalink / raw)
  To: ruby-core

Issue #17058 has been updated by jeremyevans0 (Jeremy Evans).


Looks like this changed between Ruby 2.2 and 2.3. I'll update the documentation to remove the line, as I think it's an implementation detail (that is now wrong).

----------------------------------------
Bug #17058: Array#delete_if doesn't change array instantly
https://bugs.ruby-lang.org/issues/17058#change-86796

* Author: erik_schlyter (Erik Schlyter)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
According to the documentation: https://ruby-doc.org/core-2.7.1/Array.html#method-i-delete_if
"The array is changed instantly every time the block is called, not after the iteration is over."

I've tried printing the array while iterating it:
```
a = [1,2,3,4,5,6,7]
a.delete_if{|x|
  puts "During iteration: #{a}"
  x % 2 == 0
}
puts "After iteration: #{a}"
```

The output is as follows:
```
During iteration: [1, 2, 3, 4, 5, 6, 7]
During iteration: [1, 2, 3, 4, 5, 6, 7]
During iteration: [1, 2, 3, 4, 5, 6, 7]
During iteration: [1, 3, 3, 4, 5, 6, 7]
During iteration: [1, 3, 3, 4, 5, 6, 7]
During iteration: [1, 3, 5, 4, 5, 6, 7]
During iteration: [1, 3, 5, 4, 5, 6, 7]
After iteration: [1, 3, 5, 7]
```

This functionality has changed somewhere between 2.2.2 and 2.4.0. When I use "ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]", I get the following (correct) output:
```
During iteration: [1, 2, 3, 4, 5, 6, 7]
During iteration: [1, 2, 3, 4, 5, 6, 7]
During iteration: [1, 3, 4, 5, 6, 7]
During iteration: [1, 3, 4, 5, 6, 7]
During iteration: [1, 3, 5, 6, 7]
During iteration: [1, 3, 5, 6, 7]
During iteration: [1, 3, 5, 7]
After iteration: [1, 3, 5, 7]

```
When I use "ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]" or the latest (2.7.1), I get the wrong output.


The functionality doesn't seem crucial, but the documentation should be correct.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:99394] [Ruby master Bug#17058] Array#delete_if doesn't change array instantly
  2020-07-29 15:18 [ruby-core:99390] [Ruby master Bug#17058] Array#delete_if doesn't change array instantly erik
  2020-07-29 15:33 ` [ruby-core:99392] " merch-redmine
@ 2020-07-29 15:37 ` merch-redmine
  1 sibling, 0 replies; 3+ messages in thread
From: merch-redmine @ 2020-07-29 15:37 UTC (permalink / raw)
  To: ruby-core

Issue #17058 has been updated by jeremyevans0 (Jeremy Evans).

Status changed from Open to Closed

Actually, this was already fixed in commit:9fc25811d59422355fc3a0ed0f28155e4e47267f.

----------------------------------------
Bug #17058: Array#delete_if doesn't change array instantly
https://bugs.ruby-lang.org/issues/17058#change-86798

* Author: erik_schlyter (Erik Schlyter)
* Status: Closed
* Priority: Normal
* ruby -v: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
According to the documentation: https://ruby-doc.org/core-2.7.1/Array.html#method-i-delete_if
"The array is changed instantly every time the block is called, not after the iteration is over."

I've tried printing the array while iterating it:
```
a = [1,2,3,4,5,6,7]
a.delete_if{|x|
  puts "During iteration: #{a}"
  x % 2 == 0
}
puts "After iteration: #{a}"
```

The output is as follows:
```
During iteration: [1, 2, 3, 4, 5, 6, 7]
During iteration: [1, 2, 3, 4, 5, 6, 7]
During iteration: [1, 2, 3, 4, 5, 6, 7]
During iteration: [1, 3, 3, 4, 5, 6, 7]
During iteration: [1, 3, 3, 4, 5, 6, 7]
During iteration: [1, 3, 5, 4, 5, 6, 7]
During iteration: [1, 3, 5, 4, 5, 6, 7]
After iteration: [1, 3, 5, 7]
```

This functionality has changed somewhere between 2.2.2 and 2.4.0. When I use "ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]", I get the following (correct) output:
```
During iteration: [1, 2, 3, 4, 5, 6, 7]
During iteration: [1, 2, 3, 4, 5, 6, 7]
During iteration: [1, 3, 4, 5, 6, 7]
During iteration: [1, 3, 4, 5, 6, 7]
During iteration: [1, 3, 5, 6, 7]
During iteration: [1, 3, 5, 6, 7]
During iteration: [1, 3, 5, 7]
After iteration: [1, 3, 5, 7]

```
When I use "ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]" or the latest (2.7.1), I get the wrong output.


The functionality doesn't seem crucial, but the documentation should be correct.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-07-29 15:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-29 15:18 [ruby-core:99390] [Ruby master Bug#17058] Array#delete_if doesn't change array instantly erik
2020-07-29 15:33 ` [ruby-core:99392] " merch-redmine
2020-07-29 15:37 ` [ruby-core:99394] " merch-redmine

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).