|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
XOR
ColdFusion comparison statements (CFIF, etc.) support the XOR joiner between clauses. This is used as such:Michael Dinowitz 11/03/05 04:48 P > clause1 XOR clause2Justin D. Scott 11/03/05 05:00 P I used it constantly back in the old days setting bit flags in registers.Jerry Johnson 11/03/05 05:17 P <cfif lessFilling XOR tastesGreat>Jerry Johnson 11/03/05 05:09 P >>real world example where you would need a statement like this?Claude Schneegans 11/03/05 05:31 P What about "no" XOR 0? That's a false statement, while "no" NEQ 0 isBarney Boisvert 11/03/05 05:44 P >>XOR coerces it's operands to boolean, while NEQ doesn't.Claude Schneegans 11/03/05 06:14 P One of those all in the coding style situations. After all there are like aAaron Rouse 11/04/05 12:22 A XOR is more succinct where there are more than 2 terms.Dave Francis 11/04/05 11:00 A This is not strictly true. 1 and 2, evaluated as booleans, are bothBen Doom 11/04/05 09:56 A >>However, they are not equal. So,Claude Schneegans 11/04/05 06:31 P But again, in CF the implicit coersion is VERY important. If thereBarney Boisvert 11/04/05 06:37 P > ColdFusion comparison statements (CFIF, etc.) support the XOR joinerTimothy Moody 02/09/12 03:53 P Maybe for data integrity checks? A record has to be dated in 2005 orMunson, Jacob 11/03/05 04:54 P > That is an odd one, it doesn't seem like it would be used a whole lot.Michael Dinowitz 11/03/05 05:38 P I now I'm real late on this one, but I used to teach people how to doJann E. VanOver 02/21/06 03:27 P XOR is great for adding things like "include / exclude" to an argument. Here's a real world example:K Hale 12/01/06 08:44 A The only widespread use I've seen for XOR is in basic encryption algorithms.Steve Brownlee 11/03/05 04:59 P That's a binary XOR, not a boolean XOR. I actually just wrote aBarney Boisvert 11/03/05 05:05 P <cfif InvadeAfghan XOR InvadeIraq>Raster, Tim 11/03/05 05:00 P I've never had a need for it, but I've found imp to be useful sometimes.Matthew Walker 11/03/05 05:20 P That will be the next question. :)Michael Dinowitz 11/03/05 05:34 P And here I was hoping MOD would be next on the list. I find that to beJustin D. Scott 11/03/05 06:04 P But in this example you couldn't tolerate somebody who had neither blueMatthew Walker 11/03/05 05:27 P > <cfif isSmoker XOR isBlueHair>C. Hatton Humphrey 11/03/05 06:51 P ColdFusion comparison statements (CFIF, etc.) support the XOR joiner between clauses. This is used as such: clause1 XOR clause2 This says that either clause1 or clause2 has to be true for the statement to be true. If both are true or both are false, then the entire statement is false. My question is: can anyone think of a real world example where you would need a statement like this? > clause1 XOR clause2 I suppose in dating there could only be so much tolerance. I could tolerate a smoker, or blue hair, but not both because that would be too much. <cfif isSmoker XOR isBlueHair> Winner! </cfif> Not practical really. I don't think I've ever actually seen anyone use XOR in my 6+ years of CF coding. I'm sure someone has, but nobody I've worked with. -Justin Scott I used it constantly back in the old days setting bit flags in registers. You can use it for setting parity bit for checksums. You can use it to swap the values of two variables without the need for a third temp variable. ----- Excess quoted text cut - see Original Post for more ----- <cfif lessFilling XOR tastesGreat> We've got an argument <cfelse> Everyone agrees </cfif> Remember that "true" is not just a boolean, it means zero or not zero Remember that you can group these together with NOT, AND, OR, etc. > ColdFusion comparison statements (CFIF, etc.) support the XOR joiner between clauses. This is used as such: > clause1 XOR clause2 > This says that either clause1 or clause2 has to be true for the statement to be true. If both are true or both are false, then the entire statement is false. My question is: can anyone think of a real world example where you would need a statement like this? >>real world example where you would need a statement like this? Not really, actually, because (a XOR b) is equivalent to (a NEQ b) which is much more intuitive. -- _______________________________________ REUSE CODE! Use custom tags; See http://www.contentbox.com/claude/customtags/tagstore.cfm (Please send any spam to this address: piegeacon@internetique.com) Thanks. What about "no" XOR 0? That's a false statement, while "no" NEQ 0 is true. If CF were a strongly typed language and you could enforce the "boolean-ness" of the operands, then it'd be true, but that's not the case. XOR coerces it's operands to boolean, while NEQ doesn't. cheers, barneyb > >>real world example where you would need a statement like this? > > Not really, actually, because (a XOR b) is equivalent to (a NEQ b) which > is much more intuitive. > -- Barney Boisvert bboisvert@gmail.com 360.319.6145 http://www.barneyb.com/ Got Gmail? I have 100 invites. >>XOR coerces it's operands to boolean, while NEQ doesn't. Exact. But what I mean is that if someone has to use an XOR operator, the situation is actually a NEQ issue, he will think of NEQ first, and do what must be done to make sure both operands are boolean. -- _______________________________________ REUSE CODE! Use custom tags; See http://www.contentbox.com/claude/customtags/tagstore.cfm (Please send any spam to this address: piegeacon@internetique.com) Thanks. One of those all in the coding style situations. After all there are like a million ways to skin a cat. I have always wondered about XOR or the idea behind it because I have wondered on it in other languages and when/if people ever use it. On 11/3/05, Claude Schneegans <schneegans@internetique.com > wrote: ----- Excess quoted text cut - see Original Post for more ----- XOR is more succinct where there are more than 2 terms. >>XOR coerces it's operands to boolean, while NEQ doesn't. Exact. But what I mean is that if someone has to use an XOR operator, the situation is actually a NEQ issue, he will think of NEQ first, and do what must be done to make sure both operands are boolean. -- _______________________________________ REUSE CODE! Use custom tags; See http://www.contentbox.com/claude/customtags/tagstore.cfm (Please send any spam to this address: piegeacon@internetique.com) Thanks. This is not strictly true. 1 and 2, evaluated as booleans, are both true. However, they are not equal. So, (1 XOR 2) != (1 neq 2) --Ben "the nitpicker" Doom Claude Schneegans wrote: > >>real world example where you would need a statement like this? > > Not really, actually, because (a XOR b) is equivalent to (a NEQ b) which > is much more intuitive. > >>However, they are not equal. So, (1 XOR 2) != (1 neq 2) Exact again, but XOR is rarely used, and even more rarely used on non boolean, actually, 1 XOR 2 just does not make sense if 1 and 2 are not booleans. Normally, one would use boolean1 XOR boolean2, and in THIS situation (only), boolean1 XOR boolean2 is equivalent to boolean1 NEQ boolean2 -- _______________________________________ REUSE CODE! Use custom tags; See http://www.contentbox.com/claude/customtags/tagstore.cfm (Please send any spam to this address: piegeacon@internetique.com) Thanks. But again, in CF the implicit coersion is VERY important. If there weren't implicit coersion (or CF was strongly typed, depending on how you want to say it), then there would be no need for an boolean XOR operator, as NEQ would suffice. But that's not the situation we're in with CF, so XOR is needed. cheers, barneyb ----- Excess quoted text cut - see Original Post for more ----- -- Barney Boisvert bboisvert@gmail.com 360.319.6145 http://www.barneyb.com/ Got Gmail? I have 100 invites. ----- Excess quoted text cut - see Original Post for more ----- We use XOR in a statement where both a date and a date selection type is required. If one is entered and not the other, then the user is prompted to enter both. If both or neither are entered, then the search proceeds with whatever criteria it has. <cfif b_date_entered XOR b_date_sel_entered> <script language="javascript"> window.alert('You must enter a date restriction and date(s).'); history.back(); </script> <cfabort> </cfif> Tim Maybe for data integrity checks? A record has to be dated in 2005 or 2004, but not both, and not before 2004? Of course then a data range would work just as well... That is an odd one, it doesn't seem like it would be used a whole lot. ----- Excess quoted text cut - see Original Post for more ----- [INFO] -- Access Manager: This transmission may contain information that is privileged, confidential and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. A2 > That is an odd one, it doesn't seem like it would be used a whole lot. I'm doing a complete review of comparisons statements in CF and it's one of the joiners allowed. Even if they're never used, I have to cover them. :) As for the bitwise xor, I'll deal with that later. I now I'm real late on this one, but I used to teach people how to do text searching with boolean logic in the pre-web days. When I showed them the XOR command (nearly every computer/query language has one), I told them they would NEVER use it. It's just not a "real world" operator. Jevo Michael Dinowitz wrote: ----- Excess quoted text cut - see Original Post for more ----- XOR is great for adding things like "include / exclude" to an argument. Here's a real world example: I have a function that strips out non-numeric data from numeric only form inputs. I use it on a bunch of pages. Some of these pages are basically *all* numeric data. Some pages only have a little bit of numeric data. Instead of stripping them out one by one, I just do a call to my function: stripForm('var1, var2', skip = 1) then in stripForm, you just do a check: foreach form element if arg1 contains elementName XOR skip strip characters So basically, if skip is set to 1, it only strips characters on things not listed in the first argument - that is, it "skips" the ones in the argument. If Skip is set to 0, it only strips characters on elements in the first argument. There are a lot of variations on this, but XOR's power is primarily in simplifying a two-pronged test into one statement. ----- Excess quoted text cut - see Original Post for more ----- The only widespread use I've seen for XOR is in basic encryption algorithms. Never seen it used outside that. ----- Excess quoted text cut - see Original Post for more ----- \ That's a binary XOR, not a boolean XOR. I actually just wrote a binaryXOR function last week (it's on my blog: barneyb.com) while I was .... bum-ba-da-bum ... doing some encryption stuff. Specifically reverse engineering cfusion_encrypt and cfusion_decrypt into CFML UDFs (also available on my blog). cheers, barneyb ----- Excess quoted text cut - see Original Post for more ----- -- Barney Boisvert bboisvert@gmail.com 360.319.6145 http://www.barneyb.com/ Got Gmail? I have 100 invites. <cfif InvadeAfghan XOR InvadeIraq> Elect Kerry <cfelseif InvadeAfghan OR InvadeIraq> Re-elect Bush <cfelse> Move to France </cfif> ColdFusion comparison statements (CFIF, etc.) support the XOR joiner between clauses. This is used as such: clause1 XOR clause2 This says that either clause1 or clause2 has to be true for the statement to be true. If both are true or both are false, then the entire statement is false. My question is: can anyone think of a real world example where you would need a statement like this? I've never had a need for it, but I've found imp to be useful sometimes. ColdFusion comparison statements (CFIF, etc.) support the XOR joiner between clauses. This is used as such: clause1 XOR clause2 This says that either clause1 or clause2 has to be true for the statement to be true. If both are true or both are false, then the entire statement is false. My question is: can anyone think of a real world example where you would need a statement like this? That will be the next question. :) ----- Excess quoted text cut - see Original Post for more ----- And here I was hoping MOD would be next on the list. I find that to be fairly useful in regular coding for all sorts of things. -Justin ----- Excess quoted text cut - see Original Post for more ----- I already have examples of MOD in use. It's some of the rairer ones that I'd like different examples of and if they happen to be real examples, all the better. Anyone can make up an example such as the smoker/blue hair but showing a code snippet where it's actually in use brings the concept home a lot better. ----- Excess quoted text cut - see Original Post for more ----- But in this example you couldn't tolerate somebody who had neither blue hair nor smoke. You just killed off your ideal matches ;-) Perhaps: <cfif not (isSmoker and isBlueHair)> Winner! </cfif> ---- I suppose in dating there could only be so much tolerance. I could tolerate a smoker, or blue hair, but not both because that would be too much. <cfif isSmoker XOR isBlueHair> Winner! </cfif> > <cfif isSmoker XOR isBlueHair> ----- Excess quoted text cut - see Original Post for more ----- These two are not logically eqivalent. An Exclusive OR (XOR) follows a logic pattern like this: A | B | A XOR B 0 | 0 | 0 1 | 0 | 1 0 | 1 | 1 1 | 1 | 0 Hatton
|
June 19, 2013
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||