beno

beno

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:

~w[foo\ bar baz] => [“foo bar”, “baz”]

Is there any reason it doesn’t work this way?

Showing Posts 1 to 10

fuelen

fuelen

~w because it is a list or words. "foo bar" is not a word :slight_smile: it doesn’t fit semantically

sodapopcan

sodapopcan

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.

adamu

adamu

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.

beno

beno OP

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.

sodapopcan

sodapopcan

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.

LostKobrakai

LostKobrakai

sigil_w and it’s uppercase counterpart are macros. Their values need to be compile time known.

This is not the tool to use for user input or anything you don’t know what it is.

beno

beno OP

No the contents are static, but out of our control.

LostKobrakai

LostKobrakai

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.

beno

beno OP

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:

foo_bar = "foo bar"
~w[#{foo_bar} baz]
=> ["foo", "bar", "baz"]
LostKobrakai

LostKobrakai

A list of words is a subset ot all list. You’re clearly not dealing with just that subset.

If you’re dealing with CLI arguments OptionParser might be the more appropriate tool to use.

Where Next? Top

Trending in Proposals: Ideas Top

woylie
We are seeing a lot of warning logs like this: navigate event to "https://someurl" failed because you are redirecting across live_sessio...
New

Other Trending Topics Top

whathappenedtoicabod
Looking for an elixir job. James Schiiller Detroit, Michigan Travel/relocate or work remotely Over 20 years of professional programming...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews