How do I convert a list into a string in DrRacket? For example, how do I convert '(red yellow blue green) into "red yellow blue green"? I tried using list->string but that seems to work only for characters.
相关问题
- how to split a list into a given number of sub-lis
- how to split a list into a given number of sub-lis
- C#: How do i get 2 lists into one 2-tuple list in
- Generate string from integer with arbitrary base i
- F#: Storing and mapping a list of functions
Racket supports a number of utility functions that make this easy. If all you want is to see what's in the list, you might be happy with just "display". If you care about not having the parens, you can use string-join.
The trick here is mapping over the list of symbols received as input, converting each one in turn to a string, taking care of adding a white space in-between each one except the last. Something like this:
Or even simpler, using higher-order procedures:
Either way, it works as expected:
And just to be thorough, if the input list were a list of strings (not symbols as in the question), the answer would be: