Permalink
Browse files

appendo examples

  • Loading branch information...
1 parent 78b4c7f commit a5148fb6882bfcde9a32129fb5e7736fa7ae6c4d @senior committed Oct 4, 2011
Showing with 37 additions and 8 deletions.
  1. +37 −8 src/logic_examples/seq.clj
View
@@ -1,22 +1,51 @@
(ns logic-examples.seq
(:refer-clojure :exclude [inc reify ==])
- (:use [clojure.core.logic minikanren prelude nonrel match disequality]))
+ (:use [clojure.core.logic minikanren prelude nonrel match disequality]
+ [logic-examples.arithmetic]))
(defne prefixo [x y]
([[?a . ?xs] [?a . ?ys]] (prefixo ?xs ?ys))
([[] ?ys]))
+(defn prefixo2 [x y]
+ (fresh [a]
+ (appendo x a y)))
+
(defne suffixo [x y]
([_ [?b . x]])
([_ [?b . ?ys]] (suffixo x ?ys))
([[] ?ys]))
-(defne sublisto [x y]
- ([_ [?y . ?ys]]
- (sublisto x ?ys))
- ([_ [?y . ?ys]]
+(defn suffixo2 [x y]
+ (fresh [a]
+ (appendo a x y)))
+
+(defn sublisto [x y]
+ (fresh [a]
+ (prefixo a y)
+ (suffixo x a)))
+
+(defn sublisto2 [x y]
+ (fresh [a b c]
+ (appendo a b y)
+ (appendo x c b)))
+
+(defn my-membero [x y]
+ (fresh [a b]
+ (appendo a (llist x b) y)))
+
+(defn lasto [x y]
+ (fresh [a]
+ (appendo a [x] y)))
+
+(defn adjacent [x y z]
+ (fresh [a b]
+ (appendo a (llist x y b) z)))
+
+(defne reverseo [xs ys]
+ ([[] _] (== ys []))
+ ([[?x . ?xs] _]
(fresh [a]
- (== (prefixo x ?ys) ())
- (appendo x a ?ys)))
- ([?xs ?ys] (prefixo ?xs ?ys)))
+ (reverseo ?xs a)
+ (appendo a [?x] ys))))

0 comments on commit a5148fb

Please sign in to comment.