:-)
Agreed!
I agree it’s better to do it in the primitive. (Also better than a new asSomething approach, we’ve got so many of those now…)
I’m happy to do that if we can agree on what it should accept. Once that’s done we should make sure to clearly document it. The very vague documentation of things often makes it very hard to tell what things are accidents and what are intentional.
S.
sorry, that would be:
n = nil; "magniloquent".replace(n, "OUCH");
"magOUCHoquent"
So we could just add this:
replace { arg find, replace; find = find.asString; ^super.replace(find, replace).join }
that would be messy:
n = nil; "blarg".replace("la", n);
"bnilrg"
Context:
This happened as I found some silent failures, which led to a review of all primitives to identify ones which did not check for bad types and swallowed errors. There were a number where this was incorrectly done and stuff would just quietly not work.
The String ones perhaps need more nuanced handling, although FWIW I did check with the original author of the relevant code to see if the previous implementation of those was intentional or just an oversight. It wasn’t intentional.
Yes, this is a consequence of that change. We should keep considering the way it behaves, however.
I can adjust these to accept other types. What would be helpful would be if we could first come up with a specification for what such methods should accept. Certainly Chars seem reasonable in this case.
|