From: Frank Buss on
Christophe Rhodes wrote:

> That is not what multiple argument xor means.

yes, I know this and logxor works like the mathematical definition, but for
the logical counterpart I think the other definition is more useful. But
perhaps it should be renamed (something like "only-one"), to avoid
confusion.

>> I think this could be used more often as the other interpretation
>> with counting the number of nils and checking for odd.
>
> If you had any evidence for this, this might be a good reason, apart
> from the fact that this interpretation is counter to the mathematical
> definition.

You should ask the CLisp people :-) but a far-fetched example: You have 4
switches for controlling back/forward of 2 motors, but you are not allowed
to turn on back and forward of one motor at the same time, because it is a
push-pull circuit and this would result in a short circuit and you are not
allowed to turn on two motors at once, because this would cause too much
power consumption:

(defun control-motors (up down left right)
(when (xor up down left right)
(set-relay 1 up)
(set-relay 2 down)
(set-relay 3 left)
(set-relay 4 right)))

--
Frank BuĂ˝, fb(a)frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
From: Christophe Rhodes on
Frank Buss <fb(a)frank-buss.de> writes:

> Christophe Rhodes wrote:
>> [Frank Buss]
>>> I think this could be used more often as the other interpretation
>>> with counting the number of nils and checking for odd.
>>
>> If you had any evidence for this, this might be a good reason, apart
>> from the fact that this interpretation is counter to the mathematical
>> definition.
>
> You should ask the CLisp people :-) but a far-fetched example

I don't deny that exactly-one-true has a use; I want to know why you
think it is used more often than odd-number-true, and whether that has
any basis in reality.

Christophe
From: Michiel Borkent on
Hi,

#|
Frank Buss's wrote:

(defun xor (&rest list)
(when list
(loop for (first . rest) on list
for i = 0 then (1+ i) do
(if first
(when (every #'null rest) (return (values first i)))))))
|#

How is this XOR? I don't get this definition.

(xor t t .... t) returns t,i, where i is the index of the last
argument.

For clarity, I use the definition of XOR with 2 arguments: only one and
at least one of its arguments is t, then it returns t, else nil.

What definition of multiple argument XOR do you use?

Greetings,
Michiel

From: Paul F. Dietz on
Kent M Pitman wrote:

> One of the items on that list was the addition of xor. As I recall
> what made it controversial was precisely this question of whether it
> should be a macro or special form (for consistency with AND and OR) or
> a function (because it somewhat accidentally is able to be, as an
> accident of how it is computed). Of the pre-defined operators by
> CLTL, I believe PROG1 is the only one that could have been implemented
> as a normal function, but is defined not to be...
>
> Anyway, I just wanted to raise the issue that this is a well-known
> issue of somewhat historical nature.

Now that CLOS is integrated into the language definition,
is there a similar generic controversy about whether functions
added to the language should be generic?

By the way, it seems to me that an XOR function should be binary,
and should return the true argument in the case where exactly
one of the two arguments is true.

Paul
From: Ivan Boldyrev on
On 9170 day of my life Kent M. Pitman wrote:
> One of the items on that list was the addition of xor. As I recall
> what made it controversial was precisely this question of whether it
> should be a macro or special form (for consistency with AND and OR) or
> a function (because it somewhat accidentally is able to be, as an
> accident of how it is computed).

Why is it so important? What is wrong if XOR is function but OR and
AND macros? If macro/special form evaluates all their arguments
sequentially, why not implement it as a function?

Of course, you can perform more operations with a function than with a
special form (for example, MAPCAR and so on). But it is only an
advantage IMHO.

--
Ivan Boldyrev

Tragedy of programmers is that computer is wonderful toy
and programmers have to use it in their work.
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8 9
Prev: Lisp and Web Programming
Next: Koch figures