Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Coding puzzle
Message
De
06/06/2002 08:03:22
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
Divers
Thread ID:
00664411
Message ID:
00665351
Vues:
21
>Hi Hilmar,
>
>>#DEFINE XOR #
>
>I did not really think of using #DEFINE but your suggestion makes the XOR available as a command instead of a function.
>
>
>? A XOR B
>
>
>Ofcourse one could just add ?A # B and keep the reader guessing...
>
>Kamal

For purposes of the puzzle, A#B is the shortest version you can get.

In actual practice, I use the #DEFINE to make the statements more readable.

But please note that #DEFINE XOR # is not necessarily the same as using the (missing) built-in XOR operator. The difference is in the order of precedence:
if A=B and C=D
The "=" operators will be evaluated first, as expected - equality has a higher precedence than logical operators.
#DEFINE XOR #
if A=B XOR C=D
The equality and the inequality have the same order of precedence, so everything will be evaluated from left to right. Probably not what the programmer expected.

Corrected version:
#DEFINE XOR #
if (A=B) XOR (C=D)
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform