June 2, 20187 yr hi all i would like to code a NAND gate with more then two input-items (as extension to AND etc...). here is a simple version of the NAND function with two inputs, but i don't know how to exapnd it to n-inputs without putting the the inputs to in a list (like lisp-internal AND / OR)... https://en.wikipedia.org/wiki/NAND_gate i dont't want it: (nand '(t t t nil)) but like to have (nand t nil nil t t t) when i get a solution for that i will code an XOR, NOR etc.... so the "problem" is: how to manage in DEFUN more then two inputs (don't work with &optional, i think) i tried it and failed)... any ideas, lisp-nerds? 🙂 thanx! andré ;;; easy with a specific number of input-items - that works! (defun nand (a b) (not (and a b))) (nand t t) => nil (nand nil nil) => t (nand nil t) => t ;;; i like to have an input perhaps like that - with any number of input-items, like lisp's AND / OR (nand t t t t) (nand nil t t t nil t t t nil) ...
June 4, 20187 yr Is this what you are looking for: (defun nand (&rest rest) (flet ((every-truep (x) (equal x t))) (not (every #'every-truep rest)))) (nand t t) => nil (nand t t t t nil t) => t (nand nil t t t nil t) => t
June 4, 20187 yr Author exactly... thanks for the solution! i will try to CODE some XOR, NOR.... based on it! i was in trouble with the "input-format" (when it's not a list) 🤔
June 4, 20187 yr Few more function which could be useful for you (part of the system): (contain-itemp 'inv '(c 7b9s11 inv 1 chord)) => t (contain-itemp '= '(e f d s)) => nil (contain-itemsp '(9 8) '(0 1 11 8 10 9)) => t (contain-sequencep '(11 8) '(0 1 11 8 10 9)) => t JP
Create an account or sign in to comment