Make REPLACE/ALL Default Semantics of REPLACE?

Pretty much every time I use REPLACE, I mean REPLACE/ALL. But I get bitten because I forget the /ALL.

>> string: "I am pretty sure I feel like I usually want to REPLACE/ALL"

>> replace string "I" "You"
== "You am pretty sure I feel like I usually want to REPLACE/ALL"

Grammar aside, I don't feel like there's a natural boundedness on REPLACE. It seems to me the exception is replacing just one thing, e.g. REPLACE/ONE.

Does anyone have a good argument for why REPLACE shouldn't replace all by default?

It would also be nice to know if any replacements were done. A multi-return parameter which was the count of replacements--or null if no replacements made--would be very useful.

2 Likes

To me this sounds like the perfect place for a regular expression system. Of course, string-like regexps as implemented in other languages go against the Rebol philosophy… but perhaps there may be some way to extend UPARSE to cover this domain?

Feeding UPARSE alternative combinator sets for specific tasks is on the table. There's going to be a limit to how domain-specific and brief the default set can be.

Implicit Capture In PARSE - How To Get It?

We had an inkling of something called GREB, whose goal is to be a UPARSE-powered command line tool, but it's just a placeholder right now with... all of one lonely test:

greb/.github/workflows/test-greb.yml at 13ba75b937b29d3dc010c5b4ab38a32d6827aebc · hostilefork/greb · GitHub

Hm, I believe that PowerShell corruption issue is solved now...


Speaking of REPLACE with UPARSE, here's something interesting...

Skinning REPLACE with Red's String PARSE Hack