develooper Front page | perl.perl5.porters | Postings from January 2022

Re: Things you can't do in a signatured sub

Thread Previous | Thread Next
From:
Paul "LeoNerd" Evans
Date:
January 21, 2022 17:11
Subject:
Re: Things you can't do in a signatured sub
Message ID:
20220121171121.3874ff82@shy.leonerd.org.uk
On Fri, 21 Jan 2022 16:49:22 +0000 (UTC)
Ovid <curtis_ovid_poe@yahoo.com> wrote:

> I knew my 3VL discussion went over like a lead balloon, but I
> couldn't resist being cheeky ...
> 
>     use Unknown::Values;
> 
>     sub foo ($bar = unknown) {
>         say is_unknown $bar ? "unknown" : "known";
>     }
> 
>     foo();
> 
> That prints "unknown", so if someone passed in `undef`, it will print
> "known" because someone explicitly assigned to it.

Wellsure but now you've just moved the goalpost - how to distinguish

  foo(unknown);
  foo();

Ultimately, this comes down to the fact that since it is trivially easy
in perl to distinguish the values left in the @x array in:

  my @x = (undef);   # or (unknown);
  my @x = ();

The same easy distinction ought to be possible with subroutine
arguments. It always has been so far.

-- 
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk      |  https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About