On Tue, Aug 10, 2004 at 06:10:17PM -0400, Uri Guttman wrote:
: can you have a 0- or 1-ary function? meaning like the many funcs that
: work on $_ with no args or the single arg you pass in. how do you
: declare it so it parses correctly?
: 
:       splurt          # should work on $_
:       splurt()        # should work on $_
:       splurt + 1      # same??
:       splurt +1       # work on +1??
:       splurt( +1 )    # definitely work on +1

Yes, functions declared with a single optional argument end up parsed
as named unaries, as in Perl 5 (though Perl 5 merely assumed that
a single argument was optional).  The "greedy function" rule still
applies in that it will try to look for an argument, and only default
to being 0-ary if it can't find an argument.

And functions declared 0-ary explicitly parse as terms, while all 2-ary
and higher functions parse as list operators unless you use parens.
(All functions are considered to be list ops before declaration,
and if the declaration subsequently changes that fact, it's an error.
So 0-ary and 1-ary functions have to be predeclared if you want them
to parse as unaries.)

I think this is all consistent and useful, but of course I could simply
be wrong, or more likely, wrongish.

Larry

Reply via email to