House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

XOR

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
> clause1 XOR clause2
Justin D. Scott
11/03/05 05:00 P
<cfif lessFilling XOR tastesGreat>
Jerry Johnson
11/03/05 05:09 P
>>However, they are not equal. So,
Claude Schneegans
11/04/05 06:31 P
<cfif InvadeAfghan XOR InvadeIraq>
Raster, Tim
11/03/05 05:00 P
That will be the next question. :)
Michael Dinowitz
11/03/05 05:34 P
> <cfif isSmoker XOR isBlueHair>
C. Hatton Humphrey
11/03/05 06:51 P
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Michael Dinowitz
11/03/2005 04:48 PM

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?

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Justin D. Scott
11/03/2005 05:00 PM

> 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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Jerry Johnson
11/03/2005 05:17 PM

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 -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Jerry Johnson
11/03/2005 05:09 PM

<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?

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Claude Schneegans
11/03/2005 05:31 PM

>>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.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Barney Boisvert
11/03/2005 05:44 PM

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.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Claude Schneegans
11/03/2005 06:14 PM

>>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.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Aaron Rouse
11/04/2005 12:22 AM

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 -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dave Francis
11/04/2005 11:00 AM

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.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Ben Doom
11/04/2005 09:56 AM

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. >

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Claude Schneegans
11/04/2005 06:31 PM

>>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.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Barney Boisvert
11/04/2005 06:37 PM

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.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Timothy Moody
02/09/2012 03:53 PM

----- 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

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Munson, Jacob
11/03/2005 04:54 PM

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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Michael Dinowitz
11/03/2005 05:38 PM

> 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.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Jann E. VanOver
02/21/2006 03:27 PM

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 -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
K Hale
12/01/2006 08:44 AM

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 -----

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Steve Brownlee
11/03/2005 04:59 PM

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 ----- \

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Barney Boisvert
11/03/2005 05:05 PM

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.

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Raster, Tim
11/03/2005 05:00 PM

<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?

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Matthew Walker
11/03/2005 05:20 PM

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?

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Justin D. Scott
11/03/2005 06:04 PM

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 -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Michael Dinowitz
11/03/2005 07:22 PM

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 -----

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Matthew Walker
11/03/2005 05:27 PM

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>

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
C. Hatton Humphrey
11/03/2005 06:51 PM

> <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


<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

June 19, 2013

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
             1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30             

Designer, Developer and mobile workflow conference