因此,它返回OR和(NOT)AND的AND。一、 e.仅当或返回True时为True,但和返回FALSE-否则返回FALSE/Nil。
大多数其他语言都有内置的异或函数/运算符,但通常它们的实现方式都是类似的——只是已经为您完成了。 不像你尝试使用正则表达式时那么令人困惑。。。但是是的,你需要你的智慧来理解发生了什么。 有趣的是,还有三种可能的异或函数变体:
5
很好的解释Irne
http://cplus.about.com/od/glossar1/g/xor.htm
Basically XOR returns T if 1 and only 1 test of 2 operands returns T
The AND test is normally used for 2 unique DXF group values,
(-4 ".
Thanks David... It's very understandable link... M.R. The usual difficulty when working with and/or/xor is that most people (or rather most languages including English) doesn't define those words exactly as logical comparison defines them. Usually when people say "OR" what they mean is XOR (or Exclusive Or) - i.e. it's either the one or the other - not both. Logic Comp defines OR as "Any of the operands - even just one, but also more than one".
Then you get to the AND ... which also sometimes gets confusing. Since people sometimes misuse the word in conversation - you end up with situations like these. In Logic Comp AND means "All the operands - not just some".
The way lisp (and most other programming languages) work on these is the following:
AND:
[*]Check if next operand returns True (or not nil in the case of Lisp).
[*]If the test is positive, continue. Else return False/Nil.
[*]If there's any more operands repeat from 1, else return True.
OR:
[*]Check if next operand returns True (or not nil in the case of Lisp).
[*]If the test is positive, return True. Else continue.
[*]If there's any more operands, repeat from 1. Else return False/Nil.
NOT: Basically an invert toggle. If the operand (only one - doesn'twork on more) is False/Nil return True. If the operand is True/NotNilreturn False/Nil.
XOR: This is how most people understand the word OR when spoken - i.e. as in "Either OR".
Though Lisp doesn't have a XOR function, you can make one quite easily. The principle behind it would be to combine OR, NOT & AND. E.g.:
(defun XOR (v1 v2 /) (and (or v1 v2) (not (and v1 v2))))Thus it returns an AND of an OR & (NOT) AND. I.e. True only if OR returns true, but AND returns FALSE - otherwise return False/Nil.
Most other languages have built-in XOR functions/operators, but usually they'd be implemented similarly - just already done for you. Not as confusing as when you try to use Regular Expressions... but yes, you need your wits about you to understand what's going on. Three more variations of a possible XOR function, for fun:
(defun XOR ( a b ) (or (and a (not b)) (and b (not a))))(defun XOR ( a b ) (and (or (not a) (not b)) (or a b)))(defun XOR ( a b ) (or (not (or (not a) b)) (not (or a (not b)))))
Nice explanation Irne
页:
1
[2]