There appears to be no way to escape whitespace in word lists, so sigil_w (and sigil_W) can only be used for lists of single words. Of course that is its main purpose, but to me it would be much more useful if it would allow something like:
I like to think of these sigils as a way to communicate intent to the reader (the list should only be made up of single string tokens) rather than a shorthand for the writer. I never use the a modifier for this reason, as well as others.
I just never use them. It doesn’t take much effort to write out a list, and it’s completely unambiguous when read - which is many more times than written.
My point is we are not always in control of the contents of these lists. Things like paths names or spreadsheet headers can easily contain spaces, and whenever this occurs the sigil needs to be replaced by traditional lists. I would love to avoid that by being able to escape whitespace.
That’s my point, though: if it’s only incidental that the entries are single words and could be more, I don’t bother using the sigil version. I understand the pain, though.
You’re still free to use a more appropriate tool to parse content you cannot make sure is going to be a list of words. These sigils really are conveniences for when you’re dealing with a list of words and you don’t want to type that much. You’re not dealing with a list of words as it seems, so you want to use something else.
I am dealing with lists. E.g. in the case of paths, the System.cmd() function accepts a list of arguments, often containing pathnames. I could give other examples, but trust me I have encountered it enough to warrant this post. Even using a variable doesn’t work:
Yes I am dealing with a list of strings, not just words. All I am saying is that not allowing any mechanism to escape whitespace limits its usability. Or maybe this requires a separate sigil. Final illustration:
args = ~w[import --debug true --path /path/with\ space/file.txt] #can't do this
This would allow me to just basically write out the command
So you’re aspiring a sigil, which can handle splitting a string into CLI arguments, which is fair. Afaik there are no univeral rules on how to escape characters in a terminal, so even if elixir decides for one it will only let people “copy paste” their cli command, which work on a system matching the chosen escape rules.
It also kinda did so already on OptionParser.split/1, which is afaik a way of parsing CLI args not trying to be universal, but if the people producing your input can apply its format it should work for you: