Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Ovid,

    First of all, I don't understand how your example, perl -le 'print "yes" if (undef) < 4, is an example of three-value logic. The parentheses create a list, and a list in scalar context evaluates to the number of items it has, not the value of the first item.

    This works well because, unless I'm missing something, there is no three-value logic in Perl. Perl's undef is not the same as SQL's NULL; undef always evaluates to false! IOW, it is a value, just an undefined one.

    The easiest way for me to illustrate is to borrow Date's truth tables (T = TRUE, F = FALSE, U = UNKNOWN (NULL):

      p | NOT p     p q | p AND q     p q | p OR q
    ====+=======   =====+=========   =====+========
      T |   F       T T |    T        T T |    T
      U |   U       T U |    U        T U |    T
      F |   T       T F |    F        T F |    T
                    U T |    U        U T |    T
                    U U |    U        U U |    U
                    U F |    F        U F |    U
                    F T |    F        F T |    T
                    F U |    F        F U |    U
                    F F |    F        F F |    F

    Anyone who is familiar with SQL NULL will recognize this, as well as the headaches it causes—as demonstrated in the examples you cite. But Perl has no NULL. undef is not unknown, but undefined, and Perl's idea of truth mandates that undef always be false. Thus, Perl's truth tables look like this (T = TRUE, F = FALSE, U = UNDEF:

      p | NOT p     p q | p AND q     p q | p OR q
    ====+=======   =====+=========   =====+========
      T |   F       T T |    T        T T |    T
      U |   F       T U |    F        T U |    T
      F |   T       T F |    F        T F |    T
                    U T |    F        U T |    T
                    U U |    F        U U |    F
                    U F |    F        U F |    F
                    F T |    F        F T |    T
                    F U |    F        F U |    F
                    F F |    F        F F |    F

    And really, because undef is false, it's redundant to even have it on the chart. This is because Perl uses two-valued logic, like we tend to use in the real world:

      p | NOT p     p q | p AND q     p q | p OR q
    ====+=======   =====+=========   =====+========
      T |   F       T T |    T        T T |    T
      F |   T       T F |    F        T F |    T
                    F T |    F        F T |    T
                    F F |    F        F F |    F

    This greatly simplifies things. To get back to Date's example, if DBMSs used Perl's undef's notion of truth for NULLs, you would get the proper results back in your query.

    —Theory

    • A wise man (was it Perlis or Bentley or was he quoting?) once said the only sensible values for constants are 0 and 1, all else are parameters that may indeed change with requirements. (Two:=1+1 was allowed as a special case for buffer-swapping, one in use and one in prep. Perlis said something to the effect of any supposed constant is someone else's variable.)

      So Three-valued is probably a bad basis for a logic. Date's point about Nulls are there are many more one out-of-band value possible, and you rare

      --
      Bill
      # I had a sig when sigs were cool
      use Sig;