Join Nostr
2024-08-24 21:16:08 UTC
in reply to

kakafarm on Nostr: I'm trying to write a string-join as defined in: (string-join lst delimiter) such ...

I'm trying to write a string-join as defined in:

https://cookbook.scheme.org/join-list-of-strings-with-delimiter/

(string-join lst delimiter)

such that

(string-join '("aaa" "bbb" "ccc") "xxx")

returns

"aaaxxxbbbxxxccc"

What I've got:

```
(define (string-join lst delimiter)
(list-transduce
(compose
(tadd-between delimiter)
)
(lambda (. args)
(write args)
(newline)
(cond
((null? args) '())
((null? (cdr args))
(let ((acc (car args)))
(apply string-append acc)))
(else
(let ((acc (car args))
(arg (cadr args)))
(cons arg
acc)))))
lst))
```

But I am doing it all wrong using a regular cons there, right?

The transducers API is defined in:

https://srfi.schemers.org/srfi-171/srfi-171.html

and I'm using Guile:

https://www.gnu.org/software/guile/manual/html_node/SRFI_002d171.html

#clojure
#guile
#lisp
#programming
#scheme
#transducers

(maybe this discussion will be useful to someone out there? That's why I'm tagging……… ……… ………)