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

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
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
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews