A general xor in Common Lisp

Just a quick CL function I found useful for a project.

Side thought: I’m simply counting parity, so maybe I just need a single helper variable, like counting cards in blackjack?

(defun xor (&rest objs)
	(labels ((count-objs (lst ts nils)
				(if (null lst)
					(= ts nils)
					(let ((new-ts (if (car lst) (+ ts 1) ts))
						  (new-nils (if (car lst) nils (+ nils 1))))
					     (count-objs (cdr lst) new-ts new-nils)))))
	  (count-objs objs 0 0)))

Leave a Reply

Your email address will not be published. Required fields are marked *