Jump to content

Featured Replies

Posted

complementation to OR/AND/NOT! i hope everything is correct...

https://de.wikipedia.org/wiki/Logikgatter

 

(defun nand (&rest rest)
  (flet ((every-truep (x)
           (equal x t)))
    (not (every #'every-truep rest))))

(nand nil nil nil)
=> t
(nand t t t t t t)
=> nil
(nand nil t t t nil t)
=> t


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defun nor (&rest rest)
  (contain-itemp 'nil rest))

(nor t t t t)
=> nil
(nor nil t nil)
=> t
(nor t nil nil nil)
=> t


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun xor (&rest rest)
  (oddp (car (count-item t rest))))

(xor t nil t t nil nil nil) 
=> t
(xor t t nil)
=> nil 
(xor nil t)
=> t

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun xnor (&rest rest)
  (evenp (car (count-item t rest))))

(xnor t nil t t nil nil nil)
=> nil
(xnor t t nil)
=> t 
(xnor nil t)
=> nil
(xnor t nil t t nil nil t nil)
=> t

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 

Create an account or sign in to comment


Copyright © 2014-2025 Opusmodus™ Ltd. All rights reserved.
Product features, specifications, system requirements and availability are subject to change without notice.
Opusmodus, the Opusmodus logo, and other Opusmodus trademarks are either registered trademarks or trademarks of Opusmodus Ltd.
All other trademarks contained herein are the property of their respective owners.

Powered by Invision Community

Important Information

Terms of Use Privacy Policy