develooper Front page | perl.perl5.porters | Postings from December 2021

Re: Pre-RFC: `unknown` versus `undef`

Thread Previous | Thread Next
From:
H.Merijn Brand
Date:
December 18, 2021 09:44
Subject:
Re: Pre-RFC: `unknown` versus `undef`
Message ID:
20211218104326.745705ad@pc09
On Sat, 18 Dec 2021 08:57:05 +0000 (UTC), Ovid via perl5-porters <perl5-porters@perl.org> wrote:

> Hi there,
> 
> As most of you know, "undef" values often cause all sorts of interesting bugs in Perl. I wrote https://metacpan.org/pod/Unknown::Values to address this. Instead of the 2VL that undef uses, it uses Kleene's traditional 3VL (three-value logic) akin to SQL's NULL.

 1. Known defined value
 2. Known undefined value
 3. Unknown value
 4. Unauthorized to get the value
 5. Value is defined but unauthorized to get it

When doing 3VL, number 4 is essential

> Basic usage looks like this:
> 
>     use Unknown::Values;
>  
>     my $value   = unknown;
>     my @array   = ( 1, 2, 3, $value, 4, 5 );
>     my @less    = grep { $_ < 4 } @array;   # (1,2,3)
>     my @greater = grep { $_ > 3 } @array;   # (4,5)
>  
>     my @underpaid;
>     foreach my $employee (@employees) {
>      
>         # this will never return true if salary is "unknown"
>         if ($employee->salary < $threshol ) {
>             push @underpaid => $employee;
>             }
>         }
> 
> I've also written about this here: http://blogs.perl.org/users/ovid/2013/02/three-value-logic-in-perl.html
> 
> I've always thought this belongs directly in a programming language, but never suggested this because I assumed there would be no interest
> 
> To my surprise, brian d foy suggested it be in the core (https://twitter.com/briandfoy_perl/status/1471684211602042880)
> 
> He wrote: "Unknown::Value from @OvidPerl looks very interesting. These objects can't compare, do math, or most of the other default behavior that undef allows. This would be awesome in core."
> 
> Would there be interest?

Yes, when 4VL (or 5VL)

Thinking about it, there might be a hook to add 5, 6, 7, 8, 9 etc :)

> Ovid

-- 
H.Merijn Brand  https://tux.nl   Perl Monger   http://amsterdam.pm.org/
using perl5.00307 .. 5.33        porting perl5 on HP-UX, AIX, and Linux
https://tux.nl/email.html http://qa.perl.org https://www.test-smoke.org
                           

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