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

Pre-RFC: `unknown` versus `undef`

Thread Next
From:
Ovid via perl5-porters
Date:
December 18, 2021 08:57
Subject:
Pre-RFC: `unknown` versus `undef`
Message ID:
1186925032.1532221.1639817825704@mail.yahoo.com
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.

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 < $threshold ) {
            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?

Best,
Ovid
-- 
IT consulting, training, specializing in Perl, databases, and agile development
http://www.allaroundtheworld.fr/. 

Buy my book! - http://bit.ly/beginning_perl

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