Skip to content

Commit 5888878

Browse files
committed
Add a Future Scope idea to suggest that $_ could be a readonly copy, not an alias
1 parent 5f959cd commit 5888878

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

ppcs/ppc0027-any-and-all.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ These lexicals are useful when nesting multiple calls to list-processing operato
8989

9090
If this feature is to be considered, it will require careful thought on how it might interact with the so-far-unspecified idea of accepting `any EXPR, LIST` as `grep` currently does. I would recommend not allowing that variant, to allow for easier implementation of these named lexicals in future as they provide advantages that outweigh the minor inconvenience of having to wrap the expression in brace characters.
9191

92+
### Read-only Copy Rather Than Alias
93+
94+
A little-used behaviour of `grep` and `map` is that the `$_` variable does not merely store a copy of each original list element but actually aliases it. This is almost never used intentionally and can often lead to accidentally modifying the original list values, leading to subtle data corruption bugs.
95+
96+
A possible future idea is a named feature that alters this behaviour of `grep` and `map`, as well as these new operators, into using read-only copies of the original data, rather than aliases.
97+
9298
### Other Operators
9399

94100
* The other two variant behaviours of `none` and `notall`. These simply invert the sense of the filter block.

0 commit comments

Comments
 (0)