Skip to content

Commit 7a4081f

Browse files
committed
Expand on the open issue about specifying alternate parameter naming
1 parent 08d3a32 commit 7a4081f

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

ppcs/ppcTODO-signature-named-parameters.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,29 @@ All of these use the leading-colon syntax in a signature declaration to provide
154154

155155
## Open Issues
156156

157-
* How to specify a named parameter whose name is anything other than the name of the lexical variable into which its value is assigned? This is more of note when considering that traditional argument handling techniques involving assignment into hashes can handle more styles of name that would be invalid for lexical variables - for example, names including hyphens.
157+
### Parameter Names
158+
159+
How to specify a named parameter whose name is anything other than the name of the lexical variable into which its value is assigned? This is more of note when considering that traditional argument handling techniques involving assignment into hashes can handle more styles of name that would be invalid for lexical variables - for example, names including hyphens.
160+
161+
Perhaps a solution would be to permit attributes on parameter variables, then define a `:name` attribute for this purpose.
162+
163+
```perl
164+
sub display ( $message, :$no_colour :name(no-colour) ) {
165+
...
166+
}
167+
```
168+
169+
Further thoughts in that direction suggested that this could also support multiple names with aliases:
170+
171+
```perl
172+
sub display ( $message, :$no_colour :name(no-colour no-color) ) {
173+
...
174+
}
175+
```
176+
177+
The attribute syntax starting with a leading colon does visiually look quite similar to the named parameter syntax which also uses. This is a little unfortunate, but perhaps an inevitable consequence of the limited set of characters available from ASCII. As attributes are already well-established as leading with a colon, the only other option would be to pick a different character for named attributes; but this would be contrary to the established convention of the existing modules listed above.
178+
179+
Perl does not currently support attributes being applied to parameters in signatures, named or otherwise, but this is the subject of a future PPC document I am currently drafting. I will add a reference here when it is published.
158180

159181
## Copyright
160182

0 commit comments

Comments
 (0)