I was fooling around this morning and found out some interesting things.
1. The ^ operator, exclusive OR (XOR). Compares two values, and returns a value that has its bits set if one or the other value has its corresponding bits set, but not both.
Can be used as bitwise or logical, e.g. if(var1 ^ var2).
It can be useful for swapping two variables, other than a string, in COG.
2. The ! operator, logical NOT. This may not be new, but I can't remember seeing it in any LEC or custom COGs, but I haven't looked in a while. if(!(var1 == var2)) is the same as if(var1 != var2). It's not really useful in COG since there aren't any boolean data types (I tried bool and boolean with values of true/false and 0/1 to no avail), and I'm pretty sure COG doesn't think of 0 as false and 1 as true, so if(var1) won't work, neither will if(!(var1).
3. Crude return functions with the user messages. In real languages, you can make a function that will accept parameters, and return a new value, so you can go var1 = pow(5, 6); and var1 will become 5 to the 6th power, which was figured out in the pow function.
None of this is really useful, but I thought someone might find it interesting.
------------------
Bassoon, n. A brazen instrument into which a fool blows out his brains.
1. The ^ operator, exclusive OR (XOR). Compares two values, and returns a value that has its bits set if one or the other value has its corresponding bits set, but not both.
Code:
1 ^ 1 == 0 1 ^ 0 == 1 0 ^ 1 == 1 0 ^ 0 == 0
Can be used as bitwise or logical, e.g. if(var1 ^ var2).
It can be useful for swapping two variables, other than a string, in COG.
Code:
X = X ^ Y; Y = Y ^ X; X = X ^ Y;
2. The ! operator, logical NOT. This may not be new, but I can't remember seeing it in any LEC or custom COGs, but I haven't looked in a while. if(!(var1 == var2)) is the same as if(var1 != var2). It's not really useful in COG since there aren't any boolean data types (I tried bool and boolean with values of true/false and 0/1 to no avail), and I'm pretty sure COG doesn't think of 0 as false and 1 as true, so if(var1) won't work, neither will if(!(var1).
3. Crude return functions with the user messages. In real languages, you can make a function that will accept parameters, and return a new value, so you can go var1 = pow(5, 6); and var1 will become 5 to the 6th power, which was figured out in the pow function.
Code:
symbols ... message user0 // Power "return function", pass two numbers with SendMessageEx and receive the first parameter to the second. ... printInt(SendMessageEx(GetSelfCog(), user0, X, Y, 0, 0)); ... user0: // Power "return function". temp = GetParam(0); for(I = 0; I < GetParam(1) - 1; I = I + 1) temp = temp * GetParam(0); ReturnEx(temp);
None of this is really useful, but I thought someone might find it interesting.
------------------
Bassoon, n. A brazen instrument into which a fool blows out his brains.
Bassoon, n. A brazen instrument into which a fool blows out his brains.