in reply to Re^2: Is silent use of $_ for empty argument lists reasonable for "shortcut" functions? (E2CUTE)
in thread Is silent use of $_ for empty argument lists reasonable for "shortcut" functions?

I wish / ... / that there was some other way to detect no arguments without forcing the 1st argument into a reference.

There is, kind of.

sub foo { (caller(0))[4] or return foo($_); ...; }
This will make $_[0] become aliased with $_ if foo was called with &foo and without the parenthesis. Personally I wouldn't use this. It will only lead to trouble.

lodin

  • Comment on Re^3: Is silent use of $_ for empty argument lists reasonable for "shortcut" functions? (E2CUTE) (&foo;)
  • Select or Download Code

Replies are listed 'Best First'.
Re^4: Is silent use of $_ for empty argument lists reasonable for "shortcut" functions? (E2CUTE) (&foo;)
by Wyrdweaver (Beadle) on Aug 26, 2007 at 18:00 UTC
    Yes, I looked into caller() and noted that caller()[4] is false if the function is called with the old function notation without ()'s, i.e. no new @_ is created when the function was called. But allowing users to use "&foo" as the function call when desiring "foo($_)" would seem to be a recipe for as much perlish surprise and sorrow as forcing the first argument into a reference.

    Sigh.

    Does Perl6 have the same limitations in determining argument construction for functions?

    - Wyrd