Often that may be OK, but not always. For removeSuffix() I have used strutils.replace() sometimes as a substitute, but that is not always the best solution.
So I was just thinking about other solutions. An apply template seems to work:
import strutils
template apply(x: typed; f: typed; par: typed): untyped =
var h = x
f(h, par)
h
const
Name = "manual.txt"
Doc = Name.replace(".txt") & ".html"
#Doc2 = Name.removeSuffix(".txt")
Doc3 = apply(Name, removeSuffix, ".txt")
Doc4 = Name.apply(removeSuffix, ".txt")
echo Doc
echo Doc3
echo Doc4
manual.html
manual
manual
Maybe there are even better solutions?
(Of course I understand why removeSuffix() works in place, while replace not: The code of replace needs a temporary string as buffer, as the replacement can be larger, so it makes sense to return that buffer. removeSuffix() can work in place, so it does this. But sometimes a proc with result like suffixRemoved() is what one wants.)
is what you want?
Obviously not really -- strutils.removeSuffix() was only an example for some Nim procs which works only in place, while user may need a proc that returns a modified value. (English is not my native language, but after rereading my initial post, I think that my description was not too bad. But maybe I can write my next post more clearly :-)
But I think Araq has understood the core of my concern.
That is something quite general and a decision in the end of library authors (including standard library).
In my case, I try to design a "low-level" API that works completely in-place, this has the side-benefits of allowing the return value to be an error code, nd also a high-level API that returns a new value (and uses exception).
The low-level is important because in scientific computing, allocating is often a bottleneck and you want to avoid it if you can. The high-level is because let c = a + b is much nicer than any in-place alternative that would require pre-allocation.
One approach that was really nice was Lua's which allow chaining of methods that had in-place results: http://lua-users.org/wiki/MethodChainingWrapper