AM Posted June 2, 2018 Share Posted June 2, 2018 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) ... Quote Link to comment Share on other sites More sharing options...
opmo Posted June 3, 2018 Share Posted June 3, 2018 Look into &rests Quote Link to comment Share on other sites More sharing options...
opmo Posted June 4, 2018 Share Posted June 4, 2018 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 Quote Link to comment Share on other sites More sharing options...
AM Posted June 4, 2018 Author Share Posted June 4, 2018 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) Quote Link to comment Share on other sites More sharing options...
opmo Posted June 4, 2018 Share Posted June 4, 2018 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 loopyc 1 Quote Link to comment Share on other sites More sharing options...
AM Posted June 4, 2018 Author Share Posted June 4, 2018 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.