xor (leftOperand rightOperand -- combinedValue)
Inputs
leftOperand: Left operand of the logical or bitwise operation.rightOperand: Right operand of the logical or bitwise operation.
Outputs
combinedValue: XOR result in the operand schema.
xor accepts same-schema Cond, Nat, and Int objects. Both inputs are dereferenced and must be non-NIL. The result keeps that schema.
This is not short-circuit control flow. By the time xor runs, both operands are already on the data stack.
Behavior
- For Cond, the operation is logical exclusive OR. The identity value is
FALSEand the toggling value isTRUE. - For Nat and Int, the operation is bitwise XOR. The identity value is zero and the toggling value is the all-bits-set value of that schema.
- For Int schemas, the bitwise result is computed on the schema's fixed-width bit pattern and then interpreted again as the same Int schema.
- The identity value preserves the other operand.
- The toggling value flips the other operand, but an unknown operand still yields an unknown result.
- If both operands are known at compile time, the result is computed at compile time. Otherwise, the builtin produces an unknown result of the same schema.
Example
{} () {} [
"-- no short-circuit cond --" printCompilerMessage
"-- left operand --" printCompilerMessage TRUE
"-- right operand --" printCompilerMessage FALSE
xor printStack _:;
"-- cond --" printCompilerMessage
FALSE TRUE xor printStack _:;
TRUE TRUE xor printStack _:;
unknownCond: FALSE dynamic;
FALSE unknownCond xor printStack _:;
TRUE unknownCond xor printStack _:;
"-- nat32 masks --" printCompilerMessage
0xF0n32 0x0Cn32 xor printStack _:;
0n32 0xCCn32 xor printStack _:;
0xFFFFFFFFn32 0x0Cn32 xor printStack _:;
unknownNat: 0n32 dynamic;
0n32 unknownNat xor printStack _:;
0xFFFFFFFFn32 unknownNat xor printStack _:;
"-- int32 bitwise --" printCompilerMessage
-1 6 xor printStack _:;
6 3 xor printStack _:;
unknownInt: 0 dynamic;
0 unknownInt xor printStack _:;
-1 unknownInt xor printStack _:;
] "main" exportFunction
Expected Output During Compilation
-- no short-circuit cond --
-- left operand --
-- right operand --
TRUE
-- cond --
TRUE
FALSE
Cond
Cond
-- nat32 masks --
252n32
204n32
4294967283n32
Nat32
Nat32
-- int32 bitwise --
-7
5
Int32
Int32
See also
andbuiltin(leftOperand rightOperand -- combinedValue)Combines two Cond or Whole objects with bitwise or logical AND semantics.lshiftbuiltin(object shiftCount -- shiftedValue)Performs a bitwise left shift on a Whole object and keeps the same schema.orbuiltin(leftOperand rightOperand -- combinedValue)Combines two Cond or Whole objects with bitwise or logical OR semantics.rshiftbuiltin(object shiftCount -- shiftedValue)Performs a bitwise right shift on a Whole object and keeps the same schema.~builtin(object -- invertedValue)Performs logical NOT for Cond or bitwise complement for a Whole object.