Approximation Approximator::find(const UnaryRelation& pos, const UnaryRelation& neg, const Approximation& arg) { if (arg.ob and pos.find(arg.ob)) { return truthy(); } else if (arg.ob and neg.find(arg.ob)) { return falsey(); } else { return maybe(); } }
Approximation Approximator::find(const BinaryRelation& pos, const BinaryRelation& neg, const Approximation& lhs, const Approximation& rhs) { if (lhs.ob and rhs.ob and pos.find(lhs.ob, rhs.ob)) { return truthy(); } else if (lhs.ob and rhs.ob and neg.find(lhs.ob, rhs.ob)) { return falsey(); } else { return maybe(); } }
int main (int argc, char ** argv) { handle_arguments (argc, argv); mk::KnowledgeRecord truthy (mk::KnowledgeRecord::Integer (42)); mk::KnowledgeRecord falsey (mk::KnowledgeRecord::Integer (0)); mk::KnowledgeRecord struthy ("true"); mk::KnowledgeRecord sfalsey (""); if(truthy) { std::cout << "SUCCESS truthy is true" << std::endl; } else { std::cout << "ERROR truthy is false" << std::endl; } if(falsey) { std::cout << "ERROR falsey is true" << std::endl; } else { std::cout << "SUCCESS falsey is false" << std::endl; } if(truthy && struthy) { std::cout << "SUCCESS truthy && struthy is true" << std::endl; } else { std::cout << "ERROR truthy && struthy is false" << std::endl; } if(truthy && sfalsey) { std::cout << "ERROR truthy && sfalsey is true" << std::endl; } else { std::cout << "SUCCESS truthy && sfalsey is false" << std::endl; } if(truthy || struthy) { std::cout << "SUCCESS truthy || sfalsey is true" << std::endl; } else { std::cout << "ERROR truthy || sfalsey is false" << std::endl; } // These lines compile OK, and work as expected: bool bool_false = falsey; bool bool_true = truthy; if(bool_true) { std::cout << "SUCCESS bool_true is true" << std::endl; } else { std::cout << "ERROR bool_true is false" << std::endl; } if(bool_false) { std::cout << "ERROR bool_false is true" << std::endl; } else { std::cout << "SUCCESS bool_false is false" << std::endl; } // The following lines should cause compile errors if uncommented: // naive operator bool() would compile the following: //int bad_int = truthy; // bad_int would unexpectedly have 1, not 42 //int bad_shift = truthy << 3; // naive Safe Bool returning void* would compile the following: //delete truthy; return 0; }