cgrand / enlivez

8 stars 0 forks source link

Recursive templates #35

Closed cgrand closed 4 years ago

cgrand commented 5 years ago

Let's imagine displaying a tree.

(ez/deftemplate node [self]
  (ez/for {:db/id self [name] :node/attrs}
    [:div name
       (ez/for [[self :node/children child]]
         (node child))]))

Currently it fails as the system tries to get a tree of queries out of this and this tree ends with an infinite depth.

Obviously recursive templates may be dangerous in the same way ... is dangerous in datomic's pull. A recursion limit option on the template may be good.

cgrand commented 5 years ago

The tree of queries is used to generate paths and paths lead to components.

For a fragment, its paths are the paths of its children prefixed by the child index

paths_some_fragment(p) :- paths_child_0(p'), append([0], p', p)
...
paths_some_fragment(p) :- paths_child_N(p'), append([N], p', p)
cgrand commented 5 years ago

For a for, its paths are the paths of its children prefixed by the child key

paths_some_for(p) :- query_of_this_for(a_0, ..., a_N), paths_this_body(p'), append([a_k_0, .. a_k_M], p', p) 

Ok this shows up deficiencies in my above notation: some arguments ahave to be passed to the body.

cgrand commented 5 years ago
paths_node(self, p) :- paths_node_for1(self, p)
paths_node_for1(self, p) :- datom(self, :node/name, _), path_node_for2(self, p'), append([true], p', p)
paths_node_for2(self, p) :- datom(self, :node/children, child), paths_node(child, p'), append([child], p', p)

Replacing query trees by rules sounds like an option; the sue of the impure append may cause trouble if there's a cycle in data.

cgrand commented 4 years ago

implemented