develooper Front page | perl.perl5.porters | Postings from December 2019

Re: Query Parameters

Dave Mitchell
December 3, 2019 13:33
Re: Query Parameters
Message ID:
On Mon, Dec 02, 2019 at 02:08:59PM +0000, Zefram via perl5-porters wrote:
> Dave Mitchell wrote:
> >    ?$x       peek ahead to the next arg
> >    ??$x      peek ahead and see if there is a next arg
> Poor Huffman coding: the latter will be used more often.  I think the
> peek-ahead cases should (all, consistently) have a second character after
> the "?" and before the sigil, and the predicate case should only have one
> "?".

This came about because originally I had just ?$x, ?@a, ?%h with ?$x being
the predicate, Someone pointed out that by analogy with ?@a and ?%h, ?$x
might be expected to peek and copy the next arg - hence the predicate was
re-invented as ??$x.

I'm happy for it to become the other way round:

    ?$x       peek ahead and see if there is a next arg
    ??$x      peek ahead to the next arg
    ??@a      peek ahead and copy all remaining args
    ??%h      peek ahead and copy all remaining key/val arg pairs
    ?{ code } execute some code without consuming any args

or am open to other syntax suggestions.

Although in a way I quite like ??$x for the predicate - it makes it stand
out more from the plain parameters which it is likely to be interspersed
with. Which do people prefer:

    (?$has_x, $x, ?$has_y, $x, ?$has_z, $z) 

    (??$has_x, $x, ??$has_y, $x, ??$has_z, $z) 

> >They cannot be a placeholder: i.e. these aren't legal: ??$, ?$, ?@, ?%.
> Seems to me that those should be legal no-ops.  Except for the hash one,
> which isn't even a no-op, because it would enforce even parity of the
> remaining argument list.

Parity is already enforced if there are any named parameters. If not,
then whether ?% should/would enforce and/or be useful is tied up in the
separate subthread started by Hugo about ?%foo in the absence of named

But personally I don't like the idea of quietly ignoring noops - I can't
see any good reason not to croak. Maybe it indicates a typo or thinko?

"Strange women lying in ponds distributing swords is no basis for a system
of government. Supreme executive power derives from a mandate from the
masses, not from some farcical aquatic ceremony."
    -- Dennis, "Monty Python and the Holy Grail" Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About