REBOL3 tracker
  0.9.12 beta
Ticket #0000931 User: anonymous

Project:



rss
TypeBug Statusproblem Date16-Jun-2009 14:56
Versionalpha 56 CategoryUnspecified Submitted bymeijeru
PlatformAll Severityminor Priorityhigh

Summary Spec of REMOVE-EACH says it returns remove count -- not so
Description In fact, remove-each returns the modified series at the argument position. This is the preferred behavior, and R2 compatible.

The doc string needs to be changed to: {Removes values for each block that returns true. (Modifies)}
Example code
>> source remove-each
remove-each: make native! [[
    {Removes values for each block that returns true. Returns remove count. (Modifies)}

Assigned ton/a Fixed in- Last Update18-Aug-2015 08:17


Comments
(0001016)
BrianH
22-Jun-2009 16:35

In alpha 58 the behavior was changed to match the doc string, rather than changing the doc string to match the R2-compatible, preferred behavior.

Bug description changed to be more specific, and upgraded the bug from text to minor.
(0003531)
rgchris
27-Feb-2013 22:46

The change appears to violate the rule of least surprise, though that could just be conditioning from having used it for many years. Is the new behaviour—returning the number of items removed—addressing a common problem? It'd also be straightforward to replicate and would seem (to me, at least) to be more deliberate:

length? block - length? remove-each item block [condition]

On the other hand, we now have to assign a word to a block for all remove-each operations for which the block was to be returned.
(0003533)
abolka
27-Feb-2013 23:46

I'd also prefer reverting this change back to R2's behaviour. I find the ability to chain remove-each calls far more important in practice than obtaining the number of removed elements.
(0004659)
abolka
18-Aug-2015 08:17

Having had quite a few years with the changed behaviour, the situations where the removal count is helpful do exist (such as checking if something was removed with `if positive? remove-each ...`), but are _vastly_ outnumbered by use cases where R2's behaviour of returning the modified series is more useful.

This sentiment is shared by quite a few of R3's users, who describe their pain with the bad "chainability" of current REMOVE-EACH.

We should therefore revert the default behaviour of REMOVE-EACH back to returning the modified argument series.

If the removal count functionality is so desirable as to keep, I suggest adding a REMOVE-EACH/count refinement, which toggles REMOVE-EACH to returning the removal count.

Date User Field Action Change
18-Aug-2015 08:17 abolka Comment : 0004659 Added -
18-Aug-2015 08:13 abolka Category Modified => Unspecified
18-Aug-2015 08:13 abolka Summary Modified spec of remove-each says it returns remove count -- not so => Spec of REMOVE-EACH says it returns remove count -- not so
27-Feb-2013 23:46 abolka Comment : 0003533 Added -
27-Feb-2013 22:46 rgchris Comment : 0003531 Added -
22-Jun-2009 17:22 BrianH Comment : 0001016 Modified -
22-Jun-2009 16:48 BrianH Comment : 0001016 Modified -
22-Jun-2009 16:45 BrianH Description Modified -
22-Jun-2009 16:45 BrianH Severity Modified text => minor
22-Jun-2009 16:45 BrianH Description Modified -
22-Jun-2009 16:41 BrianH Fixedin Modified alpha 58 => none
22-Jun-2009 16:35 BrianH Comment : 0001016 Added -
22-Jun-2009 16:30 BrianH Priority Modified normal => high
22-Jun-2009 16:30 BrianH Status Modified built => problem
20-Jun-2009 07:18 carl Status Modified reviewed => built
20-Jun-2009 07:18 carl Fixedin Modified => alpha 58
17-Jun-2009 01:43 BrianH Description Modified -
17-Jun-2009 01:42 BrianH Status Modified submitted => reviewed
17-Jun-2009 01:42 BrianH Code Modified -
16-Jun-2009 14:56 meijeru Ticket Added -