Looking for a library, triple logic.



  • Hey, everybody. Did anyone accidentally get a library/class at least with basic terranic operations? I can do it myself, I wanted to make sure it wasn't a bicycle. Not a google.

    The aim is simply interest, practice, perhaps some use in projects, although it is difficult to imagine. Something tells me you can give up exceptions.

    Who doesn't know is a logic not a 1/0, but a 1/0/-1. Couple years ago, it was written, but the project went to hard drive paradise. The code was about:

    // true3=1="да", false3=-1="нет", null3=0="не знаю"
    $systemStatus = and3($s1->getstatus(), $s2->getstatus(), $s3->getstatus());
    if ($systemStatus === true3) {
      echo 'all systems: ready';
      } elseif ($systemStatus === false3) {
      echo 'all systems: idle';
      } else echo 'malfunction';
    

    PS: Nothing to do with the thermal operator.



  • Got it.

    http://tools.sh4dow.ru/l3/ (ibid. http://tools.sh4dow.ru/download/?file=class.l3.php and look at the truth sheets leaflets for future generations:

    define('TRUE3',   1);
    define('NULL3',   0);
    define('FALSE3', -1);
    

    function l3validate(&$arg) {
    if ($arg !== FALSE3 and $arg !== NULL3 and $arg !== TRUE3) {
    $arg = NULL3;
    return FALSE3;
    }
    return TRUE3;
    }

    function l3not($a) { // НЕ, инверсия
    l3validate($a);
    if ($a === TRUE3) return FALSE3;
    if ($a === FALSE3) return TRUE3;
    return NULL3;
    }
    function l3and($a, $b) { // И, конъюнкция
    l3validate($a);
    l3validate($b);
    if ($a === TRUE3 and $b === TRUE3) return TRUE3;
    if ($a === FALSE3 or $b === FALSE3) return FALSE3;
    return NULL3;
    }
    function l3andm() { // И, несколько аргументов
    $result = TRUE3;
    foreach (func_get_args() as $arg) {
    l3validate($arg);
    if ($arg === NULL3) $result = NULL3;
    if ($arg === FALSE3) return FALSE3;
    }
    return $result;
    }
    function l3or($a, $b) { // ИЛИ, дизъюнкция
    l3validate($a);
    l3validate($b);
    if ($a === $b and $a === FALSE3) return FALSE3;
    if ($a === TRUE3 or $b === TRUE3) return TRUE3;
    return NULL3;
    }
    function l3orm() { // ИЛИ, несколько аргументов
    $result = FALSE3;
    foreach (func_get_args() as $arg) {
    l3validate($arg);
    if ($arg === NULL3) $result = NULL3;
    if ($arg === TRUE3) return TRUE3;
    }
    return $result;
    }
    function l3xor($a, $b) { // ЛИБО ... ЛИБО ..., строгая дизъюнкция
    l3validate($a);
    l3validate($b);
    if ($a === $b and $a !== NULL3) return FALSE3;
    if (($a === TRUE3 and $b === FALSE3) or ($a === FALSE3 and $b === TRUE3)) return TRUE3;
    return NULL3;
    }
    function l3imp($a, $b) { // ->, импликация
    l3validate($a);
    l3validate($b);
    if ($a === FALSE3 or $b === TRUE3) return TRUE3;
    if ($a === TRUE3 and $b === FALSE3) return FALSE3;
    return NULL3;
    }
    function l3bimp($a, $b) { // <-, обратная импликация
    l3validate($a);
    l3validate($b);
    if ($a === TRUE3 or $b === FALSE3) return TRUE3;
    if ($a === FALSE3 and $b === TRUE3) return FALSE3;
    return NULL3;
    }
    function l3eq($a, $b) { // =, эквивалентность
    l3validate($a);
    l3validate($b);
    if ($a === NULL3 or $b === NULL3) return NULL3;
    if ($a === $b) return TRUE3;
    return FALSE3;
    }

    ALL: For @Dex: https://rus.stackexchange.com/questions/1032/%D0%BB%D0%BE%D0%B3%D0%B8%D0%BA%D0%B0-%D1%82%D1%80%D0%BE%D0%B8%D1%87%D0%BD%D0%B0%D1%8F-%D1%82%D0%B5%D1%80%D0%BD%D0%B0%D1%80%D0%BD%D0%B0%D1%8F-%D1%82%D1%80%D0%B5%D1%85%D0%B7%D0%BD%D0%B0%D1%87%D0%BD%D0%B0%D1%8F So you took it. But look at the discussion, it was complicated and purely aesthetic. Even the triple-valent option would be correct in lexo per cent.

    UPDATE: Fixed the ideano, any "unidentified" turns into NULL3. If you want to be more tolerant, there's a method in the class. castround to the nearest logical.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2