Skip to content
Browse files

Implemented 3-47 through 3-49.

  • Loading branch information...
1 parent 635bd5c commit 60bba2cec29462064009285118bf1f8bce0ae511 @candera committed Jul 14, 2011
Showing with 26 additions and 0 deletions.
  1. +26 −0 src/reasoned_schemer/chapter3.clj
View
26 src/reasoned_schemer/chapter3.clj
@@ -199,4 +199,30 @@
(exist [w x y z]
(loto (llist (list :g :g) (list :e w) (list x y) z))
(== r (list w (list x y) z)))))))
+(deftest p47
+ (is (= ['((:g :g) (:e :e) (_.0 _.0))
+ '((:g :g) (:e :e) (_.0 _.0) (_.1 _.1))
+ '((:g :g) (:e :e) (_.0 _.0) (_.1 _.1) (_.2 _.2))]
+ (run 3 [out]
+ (exist [w x y z]
+ (== (llist (list :g :g) (list :e w) (list x y) z) out)
+ (loto out))))))
+
+(defn listofo [predo l]
+ (conde
+ ((emptyo l) s#)
+ ((exist [a]
+ (firsto l a)
+ (predo a))
+ (exist [d]
+ (resto l d)
+ (listofo predo d)))))
+(deftest p49
+ (is (= ['((:g :g) (:e :e) (_.0 _.0))
+ '((:g :g) (:e :e) (_.0 _.0) (_.1 _.1))
+ '((:g :g) (:e :e) (_.0 _.0) (_.1 _.1) (_.2 _.2))]
+ (run 3 [out]
+ (exist [w x y z]
+ (== out (llist (list :g :g) (list :e w) (list x y) z))
+ (listofo twinso out))))))

0 comments on commit 60bba2c

Please sign in to comment.
Something went wrong with that request. Please try again.