; File: logictables.scm ; Mihaela Malita ; Print all the loigc tabels for and, or ,not,imply, equivalence ; RUN: (IMPROVE has mistakes!) ; Definition of logical operators ; Choose an operator (not, and, or, imply, equivalence) : not ; p not P ; --------- ; #t #f ; #f #t ; Would you like to continue (y/n)?: y ; ; Definition of logical operators ; Choose an operator (not, and, or, imply, equivalence) : imply ; P Q P imply Q ; ----------------- ; #t #t #t ; #t #f #f ; #f #t #t ; #f #f #t ; ; Would you like to continue (y/n)?: n ; bye ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (start) (display "\nDefinition of logical operators\nChoose an operator (not, and, or, imply, equivalence) : ") (truthtable (read)) (display "\nWould you like to continue (y/n)?: ") (if (equal? 'y (read)) (start) (display 'bye)) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (truthtable opr) (cond ((eq? opr 'not) (nottable)) ( #t (display "P Q P ") (display opr) (display " Q\n") (display "-----------------\n") (table #t #t opr) (table #t #f opr) (table #f #t opr) (table #f #f opr) ))) (define (table p q opr) (display p)(display " ")(display q)(display " ") (display (eval (list opr p q ))) (newline) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (imply p q) (or (not p) q) ) (define (equivalence p q) (and (imply p q) (imply q p)) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (nottable) (display "p not P") (display "\n---------\n") (display #t) (display " ")(display (not #t)) (newline) (display #f) (display " ")(display (not #f)) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (start)