Skip to content

Instantly share code, notes, and snippets.

@crgimenes
Last active May 21, 2021 02:12
Show Gist options
  • Save crgimenes/17892160f04752d46d964695f81f0d48 to your computer and use it in GitHub Desktop.
Save crgimenes/17892160f04752d46d964695f81f0d48 to your computer and use it in GitHub Desktop.
Creates a fake NAND gate and then creates all gates from NAND.
;;;; Creates a fake NAND gate and then creates all gates from NAND.
;;;; This is just an exercise, obviously has no practical application.
;;; NAND
(defun !& (a b) (if (and (= a 1) (= b 1)) 0 1))
;;; NOT
(defun ! (a) (!& a 1))
;;; AND
(defun && (a b) (! (!& a b)))
;;; OR
(defun || (a b) (!& (! a) (! b)))
;;; NOR
(defun nor (a b) (! (|| a b)))
;;; XOR
(defun xor (a b) (&& (|| a b) (!& a b)))
;;; XNOR
(defun xnor (a b) (! (xor a b)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment