I want to generate output that looks like this:
foo: 1 2 3
My na?ve attempt would be something like puts "foo: [join {1 2 3} { }]" but of course that doesn't work because { } isn't unescaped and it produces this instead:
puts "foo: [join {1 2 3} { }]"
{ }
I can't seem to find the right sequence of escapes to nest a string within a string such that join sees the spaces and unescapes the to a newline. Is there a way to do what I want?
Use double quotes instead of braces:
% puts [join {foo: 1 2 3} " "] foo: 1 2 3
Or instead of trying to build up a single string, use a loop:
puts "foo:" foreach i {1 2 3} { puts " $i" }
2.1m questions
2.1m answers
60 comments
57.0k users