develooper Front page | perl.perl5.porters | Postings from January 2022

Re: Named argument syntax (was Re: PSC #049 2022-01-07)

Thread Previous | Thread Next
Juerd Waalboer
January 23, 2022 20:56
Re: Named argument syntax (was Re: PSC #049 2022-01-07)
Message ID:
TL;DR: the case for naming arguments with "=".

Darren Duncan skribis 2022-01-21 21:38 (-0800):
>But I want to argue that when/if Perl does add native 
>support for named parameters/arguments, which I hope it 
>does, I feel that we must use a NEW syntax to indicate it, 
>and NOT use "=>".

I like the suggestion of leaving "=>" alone (in Raku I find it really annoying that it's used both for creating Pairs and for named arguments, which makes passing a Pair rather cumbersome), but,

>I propose following an example which is very common in 
>other languages and data formats, and is also better 
>Huffman coded, which is to use the colon ":" to indicate 
>named parameters or arguments.

As someone who uses lots of ternaries, I'm not so sure about this specific character. ":" is also involved in decorating sort in another proposal, and is already used for attributes and labels. Larry Wall's "first rule of language redesign", which asserts that "everyone wants the colon", is very true. Because so many people want the colon, it might make sense to pick something else whenever feasible.

>This shouldn't conflict with any other use of the colon that I'm aware of.

Maybe not technically, but visually it's really the same colon as every other colon.

As a counter proposal I suggest "=", because it's nicely consistent with aesthetics of signatures. If named arguments have no sigil and I don't think anyone is currently suggesting giving them any, the distinction between assignment to a variable and to a named parameter should be easy enough. If computed argument names are required, those could be simply quoted, because assignment to a literal string is currently not a thing you can do.


     # not: f(name => "value");
     # not: f(name: "value");

     # but:

     f(name = "value");
     f("positional value", name = "value");
     f name = "value";
     f "name" = "value";

     Run-time computed named argument:
     f("$name" = "value");

     # unchanged:
     f $variable = "positional";

Other languages that use "=" for named arguments include Python, R, Fortran, Julia, Kotlin, Maple, and OpenSCAD.

For the common case of f(arg = $arg, foo = $foo, bar = $bar) where the argument and variable have the same name, I suggest adding prefix "=":  f(=$arg, =$foo, =$bar). And, for symmetry, a prefix "=>" for the fat comma equivalent, because that would also be useful when populating hashes and using legacy pseudo-named arguments.
Met vriendelijke groet, // Kind regards, // Korajn salutojn,

Juerd Waalboer  <>

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