IRC channel logs

2018-05-27.log

back to list of logs

***Raimondii is now known as Raimondi
<janneke>do we have a function to replace a string in a string?
<janneke>it seems i'm always struggling with this
<janneke>thank you for listening
<janneke>ACTION writes a string-substitute using string-contains and string-replace
<rain1>we dont have it, guix does and I was thinking about moving it into guile stdlib
<rain1>and possibly renaming it
<janneke>that is so weird?
<janneke>i just wrote
<janneke>(define (string-substitute string find replace)
<janneke> (let ((index (string-contains string find)))
<janneke> (if (not index) string
<janneke> (string-append
<janneke> (string-take string index)
<janneke> replace
<janneke> (string-substitute
<janneke> (string-drop string (+ index (string-length find)))
<janneke> find replace)))))
<chrislck>janneke: someone will come along and rewrite it using named let
<chrislck>I have in mind, an inkling that repeated string-append isn't terribly memory efficient, but this may come from python.... a named let could iterate a result starting from '() accumulating substrings, and a final (string-append result) to create 1 long string.
<chrislck>otherwise it looks good
<janneke>chrislck: thanks, named let is also fine
<janneke>it would be nice to have something like that in srfi-1
<janneke>eh srfi-13
<rain1>yeah its a shame it isn't in there
<chrislck>srfi-13?
<chrislck>yeah everyone writes it... but it's excellent fodder for newbies
<rain1> http://git.savannah.gnu.org/cgit/guix.git/tree/guix/utils.scm#n570
<janneke>isn't that the string library?
<janneke>rain1: yes, we really need some of those in guile or another library
<rain1>i agree
<janneke>i was hoping gash would catalize that