# New Ticket Created by  Zefram 
# Please include the string:  [perl #126909]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=126909 >


Normally a sub that accepts an empty argument list can be called with
or without parens:

> sub hat () { say "You can keep your hat on" }
sub hat () { #`(Sub|95476664) ... }
> hat()
You can keep your hat on
> hat
You can keep your hat on

But this doesn't work if the sub has one of 35 magic names:

> sub bag () { say "Papa's got a brand new bag" }
sub bag () { #`(Sub|95476816) ... }
> bag()
Papa's got a brand new bag
> bag
===SORRY!===
Argument to "bag" seems to be malformed
at <unknown file>:1
------> bag^<EOL>
Other potential difficulties:
    Function "bag" may not be called without arguments (please use () or 
whitespace to denote arguments, or &bag to refer to the function as a noun)
    at <unknown file>:1
    ------> bag^<EOL>

This is not an intrinsic feature of the sub; it's tied to the name used
at the call site:

> my &WBAG := &bag
sub bag () { #`(Sub|101248400) ... }
> &WBAG
sub bag () { #`(Sub|101248400) ... }
> WBAG()
Papa's got a brand new bag
> WBAG
Papa's got a brand new bag
> my &WHAT := &hat
sub hat () { #`(Sub|101248552) ... }
> &WHAT
sub hat () { #`(Sub|101248552) ... }
> WHAT()
You can keep your hat on
> WHAT
===SORRY!===
Argument to "WHAT" seems to be malformed
at <unknown file>:1
------> WHAT^<EOL>
Other potential difficulties:
    Function "WHAT" may not be called without arguments (please use () or 
whitespace to denote arguments, or &WHAT to refer to the function as a noun)
    at <unknown file>:1
    ------> WHAT^<EOL>

The cause of this behaviour is some magic in Perl6/Grammar.nqp that
specially recognises certain names at parse time.  It's intended to
affect calls to certain built-in subs, and I'm not objecting to such
magic being applied to calls to those subs.  The bug is that the magic
gets applied to calls to unrelated user-defined subs, based purely on a
coincidence of names.  Conversely, the intended magic is not applied to
calls to subs that should get it, if the call happens to be made through
a non-magical name:

> my &disjunction := &any
sub any (+ is raw) { #`(Sub+{<anon|77550672>}|76300224) ... }
> disjunction()
any()
> disjunction
any()
> any()
any()
> any
===SORRY!===
Argument to "any" seems to be malformed
at <unknown file>:1
------> any^<EOL>
Other potential difficulties:
    Function "any" may not be called without arguments (please use () or 
whitespace to denote arguments, or &any to refer to the function as a noun)
    at <unknown file>:1
    ------> any^<EOL>

This magic should not be triggered by the name.  It should be triggered
by a flag attached to the Sub object.  Ideally the flag should be a
trait that anyone can set on their own subs.  And the magic should
be documented.

-zefram

Reply via email to