Posted to tcl by aspect at Fri Sep 21 07:48:34 GMT 2012view raw

  1. proc unknown {var <- args} {
  2. foreach term $args {
  3. if {$term in [list & | ( )]} {
  4. lappend ex $term
  5. } elseif {$term == "~"} {
  6. lappend ex !
  7. } else {
  8. lappend ex "\${$term}"
  9. }
  10. }
  11. set ex [join $ex " "]
  12. uplevel 1 "set $var \[expr {$ex}\]"
  13. }
  14.  
  15. proc 3not2 {a b c} {
  16. proc 3not2 {a b c} {
  17. 111 <- a & b & c
  18. any <- a | b | c
  19.  
  20. # ~a <- ~ a
  21.  
  22. a+c <- a | c
  23. a&c <- a & c
  24.  
  25. a*b <- a & b
  26. a+b <- a | b
  27. ~a*b <- ~ a*b
  28. a^b <- a+b & ~a*b
  29. abodd <- a^b
  30.  
  31. b*c <- b & c
  32. b+c <- b | c
  33. ~b*c <- ~ b*c
  34. b^c <- b+c & ~b*c
  35. bcodd <- b^c
  36.  
  37. notall <- ~a*b | ~b*c
  38.  
  39. 101/010 <- abodd & bcodd
  40. 101 <- 101/010 & a+c
  41. 010 <- ~a*b & ~b*c & b
  42.  
  43. two <- ( abodd & c ) | ( bcodd & a ) | 101
  44.  
  45. 011 <- two & b & c
  46. 110 <- two & a & b
  47.  
  48. # these three are false
  49. 000 <- ~a*b & ~b*c
  50. 001 = ~a*b & c
  51. 100 = ~b*c & a
  52.  
  53. ~b <- 001 | 100 | 101
  54.  
  55. ~a <- 000 | 001 | 010 | 011
  56. ~c <- 000 | 010 | 100 | 110
  57. foreach var [info locals] {
  58. dict set res $var [set $var]
  59. }
  60. return $res
  61. }
  62.  
  63.  
  64. set cols [list a b c two 000 001 100]
  65. foreach v $cols {
  66. puts -nonewline $v\t
  67. }
  68. puts ""
  69. foreach a {0 1} {
  70. foreach b {0 1} {
  71. foreach c {0 1} {
  72. set d [3not2 $a $b $c]
  73. foreach v $cols {
  74. puts -nonewline [expr [dict get $d $v]?1:"."]\t
  75. }
  76. puts ""
  77. }
  78. }
  79. }
  80.