3 ms·
This is consistent with Ruby. It often includes both in the core. There's .gsub() and .gsub!() for text substitution in the String class, for example, or .selec
by cestith 7y ago
This is consistent with Ruby. It often includes both in the core. There's .gsub() and .gsub!() for text substitution in the String class, for example, or .select() and .select!() for the Hash class.
- kwertzzz 7y agoThis is interesting to know, because Julia uses exactly the same approach[1] (now I know where it comes from). To me it seems to be the ideal solution: use the in-place normalize!(X) where performance is important, otherwise use the more convenient allocating variant normalize(X). The exclamation mark makes it clear that the array is modified. [1] https://docs.julialang.org/en/v1/base/collections/#Base.sum https://docs.julialang.org/en/v1/base/collections/#Base.sum!
- fasquoika 7y ago>(now I know where it comes from) Both Julia and Ruby got this from Scheme and it might be even older than that.
- anamexis 7y agoUnfortunately it isn't completely consistent, for example Array#delete and String#concat
- cestith 7y agoWell, yes. Julia here is consistent with something in Ruby. In my experience it's one of the three major complaints about Ruby is how inconsistent it can be within itself. The other two major ones are the number of core ways to the the same thing and the slowness of the interpreter. The first is a matter of taste. The second is a technical issue with the interpreter mostly independent of the language and/or a question of fitness for specific projects.