Makes a database, like this
(make-database
(relation :fred [:mary :sue])
(index :fred :mary)
(relation :sally [:jen :becky])
(index :sally :jen)
(index :sally :becky))
(defmacro make-database
"Makes a database, like this
(make-database
(relation :fred [:mary :sue])
(index :fred :mary)
(relation :sally [:jen :becky])
(index :sally :jen)
(index :sally :becky))"
[& commands]
(let [wrapper (fn [cur new]
(let [cmd (first new)
body (next new)]
(assert (= 2 (count body)))
(cond
(= cmd 'relation)
`(add-relation ~cur ~(first body) ~(fnext body))
(= cmd 'index)
`(add-index ~cur ~(first body) ~(fnext body))
:otherwise (throwf "%s not recognized" new))))]
(reduce wrapper `empty-database commands)))
Comments top
No comments for make-database. Log in to add a comment.