Introduction to Zeder - a production rules toolkit for Clojure

Post on 12-Jul-2015

4.213 views 8 download

Tags:

Transcript of Introduction to Zeder - a production rules toolkit for Clojure

Agenda

● Perspective● Preliminaries● On complecting● Overview of Zeder● Out of the Tar Pit● A Little Further out of the tar pit● Demo● Future

Preliminaries

Lens

Fogus' 1st Law

In the same way that an apple tree “apples” – so too should your systems “tuple”

[Entity Attribute Value]

Decomplecting

Take transients...

...please

Transients

● Limited mutability● Thread isolated change● Not persistent● Not references● Speed boosts

Transients

● Limited mutability● Thread isolated change● Not persistent● Not references● Speed boosts

Change policy

Transients

● Limited mutability● Thread isolated change● Not persistent● Not references● Speed boosts

Change policy

Sharing policy

Transients

● Limited mutability● Thread isolated change● Not persistent● Not references● Speed boosts

Change policy

Sharing policy

Transients

● Limited mutability● Thread isolated change● Not persistent● Not references● Speed boosts

Change policy

Sharing policy

Reference policy

Transients

● Limited mutability● Thread isolated change● Not persistent● Not references● Speed boosts

Change policy

Sharing policy

Reference policy

This is what you wanted.

RAWG!?

Pods decomplect

● Reference policy● Change policy

Zeder pods decomplect

● Reference policy● Change policy● Sharing policy (Zeder version anyway)

Zeder pods decomplect

● Reference policy– There are themselves references

● Change policy– Transients internally

– Mutable objects

● Sharing policy (Zeder version anyway)

– Single-thread– Multiple threads

value

writer

shareable?

transi ent -of

reader

val u

e- of

A pod++

Fogus' 10th Rule

Any sufficiently complicated Clojure program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of OPS5.

OPS5

● Invented in the late 1970s● Charles Forgy● Rete algorithm● Incredibly efficient● Used to develop expert systems (XCON)

OPS5

OPS5

{:db/ident :user/username … }{:db/ident :user/salt … }

(defn store-user-info [uname] @(transact connection [{:user/username uname :user/salt (gen-salt)}]))

;; something triggers a call;; to store-user-info

OPS5

(literalize user username salt)

(p new-user (user ^username <name> ^salt nil))--> (modify 1 ^salt “Bad salt”))

(make user ^username fogus ^salt nil)

{:db/ident :user/username … }{:db/ident :user/salt … }

(defn store-user-info [uname] @(transact connection [{:user/username uname :user/salt (gen-salt)}]))

;; something triggers a call;; to store-user-info

OPS5

(literalize user username salt)

(p new-user (user ^username <name> ^salt nil))--> (modify 1 ^salt “Bad salt”))

(make user ^username fogus ^salt nil)

{:db/ident :user/username … }{:db/ident :user/salt … }

(defn store-user-info [uname] @(transact connection [{:user/username uname :user/salt (gen-salt)}]))

;; something triggers a call;; to store-user-info

OPS5

(literalize user username salt)

(p new-user (user ^username <name> ^salt nil))--> (modify 1 ^salt “Bad salt”))

(make user ^username fogus ^salt nil)

{:db/ident :user/username … }{:db/ident :user/salt … }

(defn store-user-info [uname] @(transact connection [{:user/username uname :user/salt (gen-salt)}]))

;; something triggers a call;; to store-user-info

OPS5

(literalize user username salt)

(p new-user (user ^username <name> ^salt nil))--> (modify 1 ^salt “Bad salt”))

(make user ^username fogus ^salt nil)

{:db/ident :user/username … }{:db/ident :user/salt … }

(defn store-user-info [uname] @(transact connection [{:user/username uname :user/salt (gen-salt)}]))

;; something triggers a call;; to store-user-info

??

Out of the Tarpit

2006 by Ben Moseley and Peter Marks

Decomplecting

DecomplectingRe

Function Data Behavior

Function Data Behavior

tactical tacticalstrategic

Driving principles

● Get stuff done● Data rocks● Don't invent anything● Protocols (swappable engines)● Pattern matching● Immutability (or the appearance thereof)● Fast would be nice

Things not shown

● Snapshots● Rete implementation details● Pod details● Engine swaps● RHS Actions● LHS (match) predicates