ID:195037
 
//Title: Logical operations
//Contributed By: Popisfizzy

/*
These are preprocessor definitions of fourteen different, and
commonly-used, logical operations. A few are basically
redefinitions of stuff on BYOND, but most are things BYOND
doesn't provide automatically.
*/


//Match BYOND's built-in operators.
#define NOT(p) !(p) // !
#define AND(p, q) ((p) && (q)) // &&
#define OR(p, q) ((p) || (q)) // ||

#define PROP(p) (p) //Not terribly useful, yea.
#define NAND(p, q) !((p) && (q))
#define NOR(p, q) !((p) || (q))

#define XOR(p, q) (!(p) != !(q))
#define MATIMP(p, q) !((p) && !(q))
#define CONIMP(p, q) ((p) || !(q))

#define XNOR(p, q) (!(p) == !(q))
#define MATNIMP(p, q) ((p) && !(q))
#define CONNIMP(p, q) !(p) || !(q))

//Mostly useless, really. These are just here
//to round out everything.
#define CONTRA(p) ((p) && !(p))
#define TAUT(p) ((p) || !(p))

//Note that everything here can be formed so
//long as one has access to NOT and one of
//either AND, OR, or MATIMP. This is the smallest
//combination needed to produce all these logical
//operators.

//Testing Code/Sample Implementation:

mob/verb
Not(p as num)
world << "NOT [p] --> [NOT(p)]"
And(p as num, q as num)
world << "[p] AND [q] --> [AND(p, q)]"
Or(p as num, q as num)
world << "[p] OR [q] --> [OR(p, q)]"
Prop(p as num)
world << "PROP [p] --> [PROP(p)]"
Nand(p as num, q as num)
world << "[p] NAND [q] --> [NAND(p, q)]"
Nor(p as num, q as num)
world << "[p] NOR [q] --> [NOR(p, q)]"
Xor(p as num, q as num)
world << "[p] XOR [q] --> [XOR(p, q)]"
MatImp(p as num, q as num)
world << "[p] MATIMP [q] --> [MATIMP(p, q)]"
ConImp(p as num, q as num)
world << "[p] CONIMP [q] --> [CONIMP(p, q)]"
Xnor(p as num, q as num)
world << "[p] XNOR [q] --> [XNOR(p, q)]"
MatNimp(p as num, q as num)
world << "[p] MATNIMP [q] --> [MATNIMP(p, q)]"
ConNimp(p as num, q as num)
world << "[p] CONNIMP [q] --> [CONNIMP(p, q)]"
Contra(p as num)
world << "CONTRA [p] --> [CONTRA(p)]"
Taut(p as num)
world << "TAUT [p] --> [TAUT(p)]"