sicp-ex-4.63



<< Previous exercise (4.62) | Index | Next exercise (4.64) >>


meteorgan

  
  
 rules: 
 (assert! (rule (father ?s ?f) 
                (or (son ?f ?s) 
                    (and (son ?w ?s) 
                         (wife ?f ?w))))) 
  
 (assert! (rule (grandson ?g ?s) 
                (and (father ?s ?f) 
                     (father ?f ?g)))) 
  
 ;;; Query input: 
 (grandson Cain ?s) 
  
 ;;; Query output: 
 (grandson Cain Irad) 
 ;;; Query input: 
 (father ?s Lamech) 
  
 ;;; Query output: 
 (father Jubal Lamech) 
 (father Jabal Lamech) 
 ;;; Query input: 
 (grandson Methushael ?s) 
  
 ;;; Query output: 
 (grandson Methushael Jubal) 
 (grandson Methushael Jabal) 
  

woofy

  
  
  
 (rule (step-son ?m ?s) 
     (and (son ?w ?s) 
          (wife ?m ?w))) 
  
 (rule (has-son ?x ?y) 
     (or (son ?x ?y) 
         (step-son ?x ?y))) 
  
 (rule (grandson ?g ?s) 
     (and (has-son ?g ?f) 
          (has-son ?f ?s))) 
  
 ; the grandson of Cain 
 (grandson Cain ?x) 
  
 ; the sons of Lamech 
 (has-son Lamech ?x) 
  
 ; the grandsons of Methushael 
 (grandson Methushael ?x)