 ;(defn ^{:source "(+ 1 a)"} aaa [a] (+ 1 a))
 ;(defmacro getsrc [func] `(:source (meta (var ~func))))
 
-(defn- create-iyye-builtin-relation [name types func pred-func]
+(defn create-iyye-builtin-verb [name types result func]
+  (words/create-iyye-verb
+    name
+    types result func true))
+
+(defn create-iyye-builtin-query [name types func]
+  (words/create-iyye-verb
+    name
+    types "predicate" func true))
+
+(defn create-iyye-builtin-relation [name types func pred-func]
   (words/create-iyye-relation
     name
     (words/->Iyye_ModalPredicate :IYE :AXIOM (persistence/local-time-to-string) :ALWAYS)
     types func pred-func true))
 
-(defn- create-entry [entry] {(:Uname (:atom entry)) entry})
+;(defn create-entry [entry] {(:Uname (:name entry)) entry})
 
 (defn- init-builtin-words []
   (let [type (words/create-iyye-type "type" true)

(defn- init-db-kb []
  (let [types-loaded (persistence/read-knowledge-from-db "types" {})
        types (map words/create-iyye-type-from-db types-loaded)
        a-f (fn [col el] (conj col (create-entry el)))]
    (dosync (alter words/action-words #(apply conj %1 %2) (persistence/read-knowledge-from-db "relations" {}))) ; {:When :ALWAYS}
    (dosync (alter words/noun-words #(apply a-f %1  %2) types)) ; {:When :ALWAYS}
    ; others
    ))


(def iyye_human (ref 0))
(def iyye_yumzya (ref 0))

; Builtin verbs and relations
(def iyye_is_type (ref 0))
(def iyye_is?_type (ref 0))
(def iyye_is_type_rel (ref 0))
(def iyye_consists_type (ref 0))
(def iyye_create_instance (ref 0))

(defn iyye_is_type_predicate_function [params]
  (if (= 2 (count params))
    (let [[p1-type p2-type] params
          p2-name (:Name (:name (first p2-type)))
          rels1 (:Relations (first p1-type))
          rels2 (for [rel rels1]
                  [rel (and p2-name (= (:super (:Data rel)) p2-name))])
          rels3 (filter #(second %) rels2)]
      (if (> (count rels3) 0)
        (:Predicate (first (first rels3)))
        (words/->Iyye_ModalPredicate :IYE :AXIOM "now" :NEVER)
        ))
    (words/->Iyye_Error (pr-str "No relation, unrelated: " params) pr-str)
    )
  ) ; FIXME Yumzia modal logic, FIXME 0 recursive

(defn iyye_is_predicate_function [params]
    (let [[relations & rest] params
          rel (first (filter #(= "relation" (:Type (:name %))) relations))]
      (if rel
        ((:PredicateFunction rel) rest)
        (words/->Iyye_Error (pr-str "No relation: " relations) pr-str))))

(defn iyye_add_relation [p1-type p2-type relation]
  (let [is_type relation]
    (let [p1-supertype (assoc is_type :Data {:super (:Name (:name p2-type))})
          p2-subtype (assoc is_type :Data {:sub (:Name (:name p1-type))})
          new-p1-type (assoc p1-type :Relations
                                     (conj (:Relations p1-type) p1-supertype))
          new-p2-type (assoc p2-type :Relations
