As an operator on booleans exclusively, or as a more general control-flow thing? Can you use it in an example?
-
-
-
Code I just wrote if xor(eye == "left", blinking(2)) then "blinking(2)" is a helper function that returns true if the current time in seconds divided by 2 is even. in other words, this does flow control for left-eye vs right-eye rendering paths, but every 2 seconds they switch
-
in general, what i want is something that has semantics as reasonably close to "or" and "and" as possible, providing exclusive-or, which i don't have to toss in as a helper function in random projects
-
i want it to either typecheck-require its inputs be of type bool, or coerce its inputs to bool, depending on whatever "and" and "or" do in the host language
-
i implemented this as local function xor(a, b) return (a and not b) or (b and not a) end but i could have done so as return toboolean(a) != toboolean(b)
End of conversation
New conversation -
-
-
Ok like im sure this is a stupid question but I've only used like 3 programming languages ever, is there a difference between "regular xor" and "logical xor"?
-
"logical xor" is what i would refer to as "regular xor" There are only two xors, "logical xor" and "bitwise xor" Most languages offer either only bitwise xor, or neither form of xor
-
isn't logical xor just !=
-
logical xor is equivalent to toboolean(x) != toboolean(y) but is not equivalent to !=
-
ah okay. If you have bool types tho it should be okay to do that.
-
however, i would prefer an operator for readability, given "xor" communicates something specific and "toboolean(x) != toboolean(y)" might require a moment' sthought
End of conversation
New conversation -
-
-
is this something that comes up a lot in the year of our lord 2018
-
WELL IT DOES A LOT FOR ME BUT APPARENTLY I AM THE ONLY PERSON ON EARTH WHO COMPUTES EXPRESSIONS USING LOGICAL XOR
-
to level the playing field, implement all of your logic out of NOTs and ORs
-
NAND should be enough for anybody
End of conversation
New conversation -
-
-
Normally, you can use the bitwise xor operator ^ in C and
@rustlang -
It does not coerce to bool, so if you want logical XOR and you say 3 ^ 8 It will not do what you expected
-
For C, that's certainly true. However, your example won't work in Rust, as it will result in a numerical type such as i32 (and not in a bool).
-
Okay. So what you are saying is that Rust has the Java behavior and ^ will perform bitwise XOR when its arguments are integers and logical XOR when its arguments are booleans?
-
Yes :-) You can quickly check this yourself on https://play.rust-lang.org/
-
That's useful to know, thanks very much.
-
Always glad to help!
End of conversation
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.