Giter Site home page Giter Site logo

Implementing rules about enlivez HOT 5 CLOSED

cgrand avatar cgrand commented on September 23, 2024
Implementing rules

from enlivez.

Comments (5)

cgrand avatar cgrand commented on September 23, 2024

Each template has its own rule (I abusely use rule for idb predicate) and this rule has as many arguments as there are lexical bindings.

A template rule must use its parent rule.

I feel there's a need for a path attribute (that would mean a constructor -- skolem predicate)

from enlivez.

cgrand avatar cgrand commented on September 23, 2024

Some things are counterintuitive at first: name and arguments of a deftemplate are an IDB predicate and each call site to a template is in fact a derivation rule for its predicate!

from enlivez.

cgrand avatar cgrand commented on September 23, 2024

Trying to recap: each "template" is associated to a rule whose last argument is a path.

Assuming only x is bound so far, (x/for (and (a x y) (b y z)) body) produces:

for_q_1234(x, y, z) :- a(x, y), b(y, z).
for_body_activation_1234(x, y, z, path) :- for_activation_1234(x, p), for_q_1234(x, y, z), vector(y, z, v), conj(p, v, path).
active_components(path) :- for_body_activation_1234(x, y, z, path).

A fragment (body) with N sub templates would produce:

subtemplate1_activation(bound-vars..., path) :- fragment_activation(bound-vars..., p), conj(p, 1, path).
...
subtemplateN_activation(bound-vars..., path) :- fragment_activation(bound-vars..., p), conj(p, N, path).
active_components(path) :- subtemplate1_activation(bound-vars..., path).
...
active_components(path) :- subtemplateN_activation(bound-vars..., path).

A terminal doesn't create rules on its own : its just a terminal, it consumes data from its activation.

Last but not least, a deftemplate creates a public activation rule and each "call" to a template is going to add rules to this activation.

from enlivez.

cgrand avatar cgrand commented on September 23, 2024

Addenda:

  1. it's easier to have the path as the first argument (and it doesn't matter as it's an implementation detail).
  2. terminals do emits rules:
active_components(path) :- terminal_activation(p, bound_vars...), vector(used_vars, v), conj(p, v, path)

from enlivez.

cgrand avatar cgrand commented on September 23, 2024

Things are starting to fall in place again. Phew.
Fragments and terminals are correctly emitting their rules. For example

  => (ez/deftemplate xoxo [] (for [(_ :user/name name)] [:h1 "hello" name]))
  => (`ez/component-path (impl/eval-rules {`xoxo #{[[] "You"]}} (ez/collect-rules xoxo)))
  #{([0 ["You"]])}

for is in progress (i.e. being actively debugged).

(Note to self: deps are not collected now, they should.)

To give some background: in the 1st prototype, components paths were computed by running many complex and wide queries and then mapping result sets to create paths.
Not only this was inefficient because these big queries were sharing a lot of subqueries (so duplicated execution) but it was also hacky (in the way queries were built) and, more concerning, it was hindering expressivity in two ways:

  1. no possibility to call rules (plus rules restrictions in datascript/datomic disallow one to use 2+ datasources which is a problem)
  2. no possibility to have recursive templates (that is to render trees) because the hack to generate queries would mean to produce an infinity of queries.... unless you can use rules (GOTO 1).

As of today I had the first components paths computed by rules (interpreted by the nascent EZ datalog impl). It means that soon I'll be able to plug back components instantiation on it.

from enlivez.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.