in reply to Re^3: Distinguish between missing and undefined arguments with subroutine signatures
in thread Distinguish between missing and undefined arguments with subroutine signatures

> And then slurping starts hurting :-)

++ for linguistic excellency but not for correctness. ;-)

Some remarks:

Anyway, you seem to be very convinced, so good luck and enjoy! :)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

°) maybe consider namespace::clean

  • Comment on Re^4: Distinguish between missing and undefined arguments with subroutine signatures
  • Download Code

Replies are listed 'Best First'.
Re^5: Distinguish between missing and undefined arguments with subroutine signatures
by jo37 (Curate) on Jan 08, 2021 at 22:58 UTC

    Trying to implement it according to your remarks leads me to something I don't like at all.

    EDIT: See comments in uglier_foo.

    my $missing = sub {...}; # private sub sub ugly_foo ($self, $foo=$missing->(), $bar=$missing->()) { say "foo is missing" if $missing->($foo); say "bar is missing" if $missing->($bar); } # compare with eq sub uglier_foo($self, $foo=MISSING, $bar=MISSING) { # This comes from posting insufficiently tested code at midnight # say "foo is missing" if !$foo || $foo eq MISSING; # say "bar is missing" if !$foo || $foo eq MISSING; say "foo is missing" if $foo && $foo eq MISSING; say "bar is missing" if $bar && $bar eq MISSING; } # slurping sub ugliest_foo ($self, @args) { my ($foo, $foo_missing); if (@args) { $foo = shift @args; } else { $foo_missing = 1; } my ($bar, $bar_missing); if (@args) { $bar = shift @args; } else { $bar_missing = 1; } if (@args) { croak "too many arguments"; } say "foo is missing" if $foo_missing; say "bar is missing" if $bar_missing; }

    So, yes, I stubbornly stick to my solution.

    Greetings,
    -jo

    $gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$
      >     say "foo is missing" if !$foo || $foo eq MISSING;

      hard to understand, if you wanna catch False you don't need missing at all. (tho I suppose you rather meant defined which is another beast )

      > So, yes, I stubbornly stick to my solution.

      I'm happy to agree, since I have unfortunately more urgent stuff to deal with now! :)

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery