Christopher Lam <christopher....@gmail.com> writes:
> This function has an interesting history. > > Someone or something in #guile had clued me there was a magic > string-replace-substring somewhere in guile-user archives. With some luck I > found it, and had bookmarked it, and kept it at the back of my mind for a > good number of months. To take the history further: I had initially started a very slow version of string-replace-substring for wisp (because in the original wisp parser which re-implemented something like read I needed string-replacing all the time): https://lists.gnu.org/archive/html/guile-devel/2013-09/msg00028.html The original version looked like this (written on the Friday 13th in September 2013): define : string-replace-substring s substring replacement . "Replace every instance of substring in s by replacement." let : : sublen : string-length substring let replacer : newstring s index : string-contains s substring if : not : equal? index #f let : : replaced : string-replace s replacement index : + index sublen replacer replaced : string-contains replaced substring . newstring ;; ^ ;; | ;; +---- horribly slow code! Do not copy! It was afterwards improved with help by ijp to be 2x faster, and then by Mark Weaver to be 80x faster (that’s not a typo: 80x faster!). Half a year later Andy Wingo improved it further, replacing define* by define, but I did not use it back then, because I needed full utf8 at all times, regardless of the port encoding. So the current version is at least 160x faster than my initial naive implementation. Thank you very much for picking it up and getting it into Guile! Best wishes, Arne -- Unpolitisch sein heißt politisch sein ohne es zu merken