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

Pre-RFC: `unknown` versus `undef`

Thread Next
Ovid via perl5-porters
December 18, 2021 08:57
Pre-RFC: `unknown` versus `undef`
Message ID:
Hi there,

As most of you know, "undef" values often cause all sorts of interesting bugs in Perl. I wrote 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:

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 (

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?

IT consulting, training, specializing in Perl, databases, and agile development 

Buy my book! -

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About