On Wed, 2025-10-15 at 09:14 +0100, Richard Shann wrote:
> On Tue, 2025-10-14 at 22:09 +0200, Andreas Schneider wrote:
> > Am 14.10.25 um 21:37 schrieb Richard Shann:
> > > On Tue, 2025-10-14 at 19:43 +0200, Andreas Schneider wrote:
> > > > Am 14.10.25 um 10:49 schrieb Richard Shann:
> > > > > On Mon, 2025-10-13 at 19:12 +0200, Andreas Schneider wrote:
> > > > > 
> > > > [...]
> > > > Unfortunately, I get a script error:
> > > 
> > > You have omitted the first line of the script
> > > 
> > > (use-modules (ice-9 string-fun))
> > > 
> > > that module provides the function needed.
> > 
> > I do have included this line, 
> 
> Oh, sorry, I missed it because it came at the end of the the line "A
> script error for file/script" and I started reading the script from
> there.
> 
> > see attached screenshot. Maybe, it does
> > not find the module. Although I have the packages guile-3.0-libs
> > and 
> > guile-2.2-libs (that both include ice-9/string-fun.scm) installed.
> 
> hmm, I didn't do anything special to get it included. If you get up
> guile in a terminal and try to include the module does it work?

In any case, this is the definition:

(define (string-replace-substring str substring replacement)
  "Return a new string where every instance of @var{substring} in
string
   @var{str} has been replaced by @var{replacement}. For example:

   @lisp
   (string-replace-substring \"a ring of strings\" \"ring\" \"rut\")
   @result{} \"a rut of struts\"
   @end lisp
   "
  (let ((sublen (string-length substring)))
    (with-output-to-string
      (lambda ()
        (let lp ((start 0))
          (cond
           ((string-contains str substring start)
            => (lambda (end)
                 (display (substring/shared str start end))
                 (display replacement)
                 (lp (+ end sublen))))
           (else
            (display (substring/shared str start)))))))))

Richard


Reply via email to