develooper Front page | perl.perl5.porters | Postings from March 2021

Re: Perl feature wish: quote-word array-ref operator

Thread Previous | Thread Next
Ricardo Signes
March 13, 2021 03:12
Re: Perl feature wish: quote-word array-ref operator
Message ID:
On Wed, Mar 10, 2021, at 2:35 AM, Smylers wrote:
> Eric Wong writes:
> > One thing that is AFAIK conflict-free could be using a suffix modifier
> > (similar to regexp modifiers):
> > 
> > qw[ a b c ]r
> That's true, but is way harder to read: the gap between the [ and ] can
> be massive; not knowing what you're assigning until you get to the end
> of it doesn't make it easy to glance at the code.

I think this is the most important part of this thread, for me, and for both Eric and Smylers' contributions.

I like qa[...] just fine, but I it's sort of a one trick pony.  That's okay, not every pony needs to be a polymath, but how many more ponies do we want in this here rodeo, anyway?

Sticking an "r" at the end lets you have modifiers that express what tricks are being performed… but you don't get to it until the end of reading, so you can't correctly parse the code (as a reader) until you finish reading it and go back.  Or you have to know that "qa" is code for "skip ahead to closing delimiter and then skip back", which is crap.  We're surrounded by the circumfix problem!

Raku attacked this by putting its modifiers in the beginning.  If we could prepare to do this extensibly, even if only with core-provided extensions, and even with very few to start, we'd be in a good place.

This example is meant to make the point, not to be exactly what we want:

qz:d[ ... ]      # :d means "delimiter determines type" so this gets an arrayref
qz:d{ ... }      #    ...same thing, but we get a hashref

qz:i{ a $b c }   # :i means interpolative

qz:x{ this #foo
      rules }    # :x is like /x on regex; allow comments

# ...all together now...
  $other # <- durians?

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About