• Merging strings

    From B. Pym@21:1/5 to All on Fri Jul 4 14:22:14 2025
    XPost: comp.lang.lisp

    You have a list contain both strings and numbers.
    Generate a new list in which the adjacent strings
    have been concatenated.

    Scheme

    (define (merge-strings List)
    (reverse
    (fold
    (lambda (e accum)
    (if (and (string? e) (pair? accum) (string? (car accum)))
    (cons (string-append (car accum) e) (cdr accum))
    (cons e accum)))
    '()
    List)))

    (merge-strings '("1" "2" 3 4 "5" "6" 7 8 "9"))
    ===>
    ("12" 3 4 "56" 7 8 "9")

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)