From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Arne Babenhauserheide Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] Add string-replace-substring to (ice-9 string-fun) Date: Sun, 05 Jan 2020 16:49:26 +0100 Message-ID: <871rsdgayh.fsf@web.de> References: <27656CBA-297B-4EE3-93D6-FD56BFBDDC44@sarc.name> <87imlqyw5x.fsf@pobox.com> <87k166ump3.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="155535"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: mu4e 1.2.0; emacs 26.1 To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sun Jan 05 16:50:46 2020 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1io8Av-000eIA-4a for guile-devel@m.gmane.org; Sun, 05 Jan 2020 16:50:45 +0100 Original-Received: from localhost ([::1]:43064 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1io8At-0006it-5S for guile-devel@m.gmane.org; Sun, 05 Jan 2020 10:50:43 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51611) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1io89i-0006im-Fu for guile-devel@gnu.org; Sun, 05 Jan 2020 10:49:31 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1io89h-0007EE-AX for guile-devel@gnu.org; Sun, 05 Jan 2020 10:49:30 -0500 Original-Received: from mout.web.de ([212.227.15.14]:37597) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1io89g-0007DZ-UI for guile-devel@gnu.org; Sun, 05 Jan 2020 10:49:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1578239367; bh=1YfhGgo9MpEuO/Dfo21U3J/XTi2oyCSeJphflZmYrmw=; h=X-UI-Sender-Class:References:From:To:Subject:In-reply-to:Date; b=HgK/y6HQGHOchNx7JBkj1sVj4QoV0e71R3mjHyou3WUzBlziJbemHWvOnWupXbY4H 6++qGpcYBRS5czgMs1pM6g+rRJGe6xfnfFnMFGVo8PxNDg6teY6hvlIpzFu7Xhm6D/ iDQPe5ZUlcRlWQ/iHvbFfZfs+jl6K3rdEeVbLxwo= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Original-Received: from fluss ([84.165.17.138]) by smtp.web.de (mrweb001 [213.165.67.108]) with ESMTPSA (Nemesis) id 0Lilcj-1jR2k73JxF-00czJU for ; Sun, 05 Jan 2020 16:49:26 +0100 In-reply-to: X-Provags-ID: V03:K1:x0J04y7V8EFSeBgy6wgjFBZwtG1gwpc8IqNP4h1a/As6LNE6TSS RojHITD6vJrsJaZ4jPpuPszN5xqa4ivYzD7BNAeLqevWyd5YZ1UhaO7HgIUayFL9J2kztGO +LsTSt2h/WIHY2/uSQn1vieBJjD/9Z35KRYkkrtdFlbFGLg6gb1YXhY6Szxwv7mLn1d0ebF 0u+7QqMDYOrRw5BgA4jKg== X-UI-Out-Filterresults: notjunk:1;V03:K0:u7Xz9gleADk=:kTiCrIjSpbmMey8sX/wciV ADSpkBE57PjyrMnFE57UMWENc1lBQhgqyP+JZTHay0WKSr437FdhKAatLpRg8On4Tjt3dC55r QaDH9iHBe6Oz5jlwyFxo69OLE1pfL/SdqKOPnHKmLgXkxPmWmoD7WiuvBImafH+nGnOXUUPER SIoA0EdxrKAxkENCZEvEeR+IKJBM7PQdnvzZEPV91fJlLk9pFv/Tc7lrfQrQKJAsFmZWagI3m X0iYnAphwPmeK+MIM/wXSB7SWK70j72sknuclmrijClvrSFD5VNXAFWC9gmNovTw2veAgCgwD rvqjP7+QItlFsyvJ7nhhbU8h1cuvujRx3NE6bloRQcqstrkCKIG1NmOjzTPX1Z6tsnpsQv5zj mmeiUSJ94x0ubcK7CX8tDinUr0dHrZ8wJ/3BG946NyAOY/104cVZak5QsT4fg37kc/vPkPj7T oNqGhii2abJ6NH20oKnqZciApRTosqv6Z6pRG17Jc1rTWCu9VPVzz69Zs8oT3PdnYQik1O59G MrIYOGjOTHxyfaopdxINlFOSmGcPi0+PQ+SCgQDSV+GFSjV/LXxVr8yPFnV8MPfj8XfcZ14Xf TpkZQ+OKAeodqZsGU3ot1bpuC5wNwPLhhihJYkuZRqqNe6N0OexdzcjoTGG63IEf0Aq+TBIcZ aNjdpufR+kJreP82myf/osojeQAM5ib5CmmQAozlw2gV5BIV3ZYf/N9hB7wILVsV3RTud72+s Oiv+mmPC8yvWc8nqqTEZagmLrjB/FWl9/DrWb7Xrn8tPNDitfy0dDuNw6ts5xJcAab6VZnWC X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.15.14 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.org gmane.lisp.guile.devel:20225 Archived-At: Christopher Lam 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=E2=80=99s 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=C3=9Ft politisch sein ohne es zu merken