Lisp »Tips 'n Tricks
»NOT AND OR
NAO
;|
NAO.LSP (17 Luglio 2005)
Copyright (C) 2005 Claudio Piccini.
All rights reserved
www.cg-cad.com
Generatore di tabelle di verita'
|;
(defun xAf ( / x str )
(setq x (random 10))
(setq str (strcat "\n" (rtos x 2 2) " AND FALSE = "))
(princ str)
(princ (and x y))
)
(defun xAt ( / x y str )
(setq x (random 10))
(setq y T)
(setq str (strcat "\n" (rtos x 2 2) " AND TRUE = "))
(princ str)
(princ (and x y))
)
(defun xOf ( / x str )
(setq x (random 10))
(setq str (strcat "\n" (rtos x 2 2) " OR FALSE = "))
(princ str)
(princ (or x y))
)
(defun xOt ( / x y str )
(setq x (random 10))
(setq y T)
(setq str (strcat "\n" (rtos x 2 2) " OR TRUE = "))
(princ str)
(princ (or x y))
)
(defun xAx ( / x str )
(setq x (random 10))
(setq str (strcat "\n" (rtos x 2 2) " AND " (rtos x 2 2) " = "))
(princ str)
(princ (and x x))
)
(defun xOx ( / x str )
(setq x (random 10))
(setq str (strcat "\n" (rtos x 2 2) " OR " (rtos x 2 2) " = "))
(princ str)
(princ (or x x))
)
(defun xATx ( / x str )
(setq x (random 10))
(setq str (strcat "\n" (rtos x 2 2) " AND NOT " (rtos x 2 2) " = "))
(princ str)
(princ (and x (not x)))
)
(defun xOTx ( / x str )
(setq x (random 10))
(setq str (strcat "\n" (rtos x 2 2) " OR NOT " (rtos x 2 2) " = "))
(princ str)
(princ (or x (not x)))
)
(defun xNAOx ( / x str )
(setq x (random 10))
(setq str (strcat "\n" (rtos x 2 2) " NOT AND OR " (rtos x 2 2) " = "))
(princ str)
(princ (not (and x (or x))))
)
(defun xATy ( / x y )
; x=nil y=nil
(princ "\n")
(princ x)
(princ " AND NOT ")
(princ y)
(princ " = ")
(princ (and x (not y)))
; x=nil y=T
(setq y T)
(princ "\n")
(princ x)
(princ " AND NOT ")
(princ y)
(princ " = ")
(princ (and x (not y)))
; x=T y=nil
(setq x T)
(setq y nil)
(princ "\n")
(princ x)
(princ " AND NOT ")
(princ y)
(princ " = ")
(princ (and x (not y)))
; x=T y=T
(setq y T)
(princ "\n")
(princ x)
(princ " AND NOT ")
(princ y)
(princ " = ")
(princ (and x (not y)))
)
(defun xOTy ( / x y )
; x=nil y=nil
(princ "\n")
(princ x)
(princ " OR NOT ")
(princ y)
(princ " = ")
(princ (or x (not y)))
; x=nil y=T
(setq y T)
(princ "\n")
(princ x)
(princ " OR NOT ")
(princ y)
(princ " = ")
(princ (or x (not y)))
; x=T y=nil
(setq x T)
(setq y nil)
(princ "\n")
(princ x)
(princ " OR NOT ")
(princ y)
(princ " = ")
(princ (or x (not y)))
; x=T y=T
(setq y T)
(princ "\n")
(princ x)
(princ " OR NOT ")
(princ y)
(princ " = ")
(princ (or x (not y)))
)
(defun xNAOy ( / x y )
; x=nil y=nil
(princ "\n")
(princ x)
(princ " NOT AND OR ")
(princ y)
(princ " = ")
(princ (not (and x (or y))))
; x=nil y=T
(setq y T)
(princ "\n")
(princ x)
(princ " NOT AND OR ")
(princ y)
(princ " = ")
(princ (not (and x (or y))))
; x=T y=nil
(setq x T)
(setq y nil)
(princ "\n")
(princ x)
(princ " NOT AND OR ")
(princ y)
(princ " = ")
(princ (not (and x (or y))))
; x=T y=T
(setq y T)
(princ "\n")
(princ x)
(princ " NOT AND OR ")
(princ y)
(princ " = ")
(princ (not (and x (or y))))
)
;|
Estrae un numero casuale da 0 a x-1
|;
(defun random ( x / m b c)
(if (not sd) (setq sd (getvar "DATE")))
(setq m 65521 b 15937 c 33503)
(setq sd (rem (+ (* b sd) c) m))
(* (/ sd m) x)
)
(defun c:nao ( / tasto )
(setvar "cmdecho" 0)
(textscr)
(setq tasto "a")
(princ "* TABELLE DELLA VERITA' *")
(while tasto
(princ "\n-----------------------")
(princ "\n a. x AND FALSE")
(princ "\n b. x AND TRUE")
(princ "\n c. x OR FALSE")
(princ "\n d. x OR TRUE")
(princ "\n e. x AND x")
(princ "\n f. x OR x")
(princ "\n g. x AND NOT x")
(princ "\n h. x OR NOT x")
(princ "\n i. x NOT AND OR x")
(princ "\n l. x AND NOT y")
(princ "\n m. x OR NOT y")
(princ "\n n. x NOT AND OR y")
(princ "\n 0. Fine programma")
(princ "\n-----------------------")
(initget "a A b B c C d D e E f F g G h H i I l L m M n N 0")
(setq tasto (getkword "\nScelta: "))
(cond
((or (= tasto "a")(= tasto "A"))(xAf))
((or (= tasto "b")(= tasto "B"))(xAt))
((or (= tasto "c")(= tasto "C"))(xOf))
((or (= tasto "d")(= tasto "D"))(xOt))
((or (= tasto "e")(= tasto "E"))(xAx))
((or (= tasto "f")(= tasto "F"))(xOx))
((or (= tasto "g")(= tasto "G"))(xATx))
((or (= tasto "h")(= tasto "H"))(xOTx))
((or (= tasto "i")(= tasto "I"))(xNAOx))
((or (= tasto "l")(= tasto "L"))(xATy))
((or (= tasto "m")(= tasto "M"))(xOTy))
((or (= tasto "n")(= tasto "N"))(xNAOy))
((= tasto "0")(setq tasto nil))
)
)
(graphscr)
(setvar "cmdecho" 1)
(princ)
)
;;;eof
|
Test del Lisp
Command: nao
* TABELLE DELLA VERITA' *
-----------------------
a. x AND FALSE
b. x AND TRUE
c. x OR FALSE
d. x OR TRUE
e. x AND x
f. x OR x
g. x AND NOT x
h. x OR NOT x
i. x NOT AND OR x
l. x AND NOT y
m. x OR NOT y
n. x NOT AND OR y
0. Fine programma
-----------------------
Scelta: e
1.41 AND 1.41 = T
Scelta: l
nil AND NOT nil = nil
nil AND NOT T = nil
T AND NOT nil = T
T AND NOT T = nil
Scelta: n
nil NOT AND OR nil = T
nil NOT AND OR T = T
T NOT AND OR nil = T
T NOT AND OR T = nil
Lisp »Tips 'n Tricks
Ultimo Aggiornamento_Last Update: 17 Luglio 2005
|