Convert a list of char into a single string

353 Views Asked by At

If I have a list of char like (cons #\C (cons #\O (cons #\M (cons #\P (cons #\U (cons #\T (cons #\E empty))))))), how can I convert it into a string? I'm not allowed to use string-append, substring, implode, and explode. I am also on Beginning Student so I can't use string-join. I've thought about using (string char) but I can't figure out how it'd work recursively.

Or, how would I be able to convert a list of strings into a single string, given the same restrictions above?

1

There are 1 best solutions below

1
On

It looks like list->string does what you want.

Edit to make the bot happy:

(define list-of-chars
   (cons #\C (cons #\O (cons #\M (cons #\P (cons #\U (cons #\T (cons #\E empty))))))))

(list->string list-of-chars)

The resulting string is "COMPUTE" as desired.