Sujet : Merging strings
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp comp.lang.schemeDate : 04. Jul 2025, 15:22:14
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <1048o2l$s1la$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
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")