• Stars
    star
    164
  • Rank 230,032 (Top 5 %)
  • Language
    Clojure
  • License
    Eclipse Public Li...
  • Created over 11 years ago
  • Updated over 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A propagator library for Clojure

propaganda

Punching values through the system

The propaganda library is a Clojure implementation of the propagator computational model described in The Art of the Propagator. The aim of the library is to be easy to use and reason about, yet extensible.

Two different strategies have been implemented: one using the Clojure STM for handling the propagation of values in the system; and one representing the system as an immutable value, without the aid of any underlying transactional model. The latter approach makes it possible to use propagators from javascript, and is the biggest contribution from this project.

There is a Clojars release containing an implementation that works in both Clojure and ClojureScript.

The leiningen dependency is

[propaganda "0.2.0"]

Tutorial

Here follows a short tutorial. For more in depth information, please consult the following sources:

To use the propaganda library, you need to define a merge, function, create cells and set up propagators. The merge function is invoked when a propagator attempts to store a new value in a cell. The merge function is invoked with the current value and the new value, and must return either a new value which will be stored in the cell, or a Conflict object.

In this short example we just use the default merger function, we define the square and square-root propagator and set up relations beween simple cells.

(use 'propaganda.stm)
(use 'propaganda.values)

default-merge will give us a merger that will merge nothing with anything, but will enforce that anything else that is attempted to be merged will return a contradiction

(def my-merge
  (default-merge))

nothing can be merged with nothing and will return nothing

(my-merge nothing nothing)
;; => :propaganda.values/nothing

Anything else will be the result of the merge

(my-merge nothing 1)
;; => 1
(my-merge 2 nothing)
;; => 2
(my-merge 1 1)
;; => 1

... unless it gives rise to a contradiction

(my-merge 1 2)
;; => #propaganda.core.Contradiction{:reason "1 != 2"}

The function->propagator-constructor can be used for setting up simple one way relations

(def squarer
  (function->propagator-constructor
   (fn [val] (* val val))))

(def sqrter
  (function->propagator-constructor
   (fn [val] (Math/sqrt val))))

... which can be extended to go both ways

(defn quadratic
  [x x-squared]
  (squarer x x-squared)
  (sqrter  x-squared x))

We can now construct cells and set up the quadratic relations to read the squared of a number in our system:

(let [x (make-cell)
      x-squared (make-cell)]
  (binding [*merge* my-merge]
    (quadratic x x-squared)
    (add-content x 10.0)
    (get-content x-squared)))
;; => 100.0

Or the square-root, depending on the input from the user

(let [y (make-cell)
      y-squared (make-cell)]
  (binding [*merge* my-merge]
    (quadratic y y-squared)
    (add-content y-squared 1764.0)
    (get-content y)))
;; => 42.0

We will be warned of any inconsistencies in our system when adding content

(let [z (make-cell)
      z-squared (make-cell)]
  (binding [*merge* my-merge]
    (quadratic z z-squared)
    (add-content z 10.0)
    (add-content z-squared 123.0)))
;; Exception: Inconsistency: 100.0 != 123.0

Motivation

The objective of this project is to create an extinsible propagator library for Clojure. Propagators define a declarative computational model. They are described in the article The Art of the Propagator.

Along with the library itself, the project should supply documentation of the API, good examples and tutorials.

I have not previously worked with propagtors, so this will also be an exploration for me.

Thanks to

Ragnar Dahlén and Kasper Langer for feedback on the library.

More Repositories

1

the-composing-schemer

The Composing Schemer
Clojure
23
star
2

clj-todo

A small lib for annotating Clojure code with todos
HTML
16
star
3

parsing-packet-with-logic

Parsing packets Erlang style using core.logic
Clojure
12
star
4

plait

Redeclareable let-style bindings for Clojure
Clojure
11
star
5

pet-shop-example

Pet shop example illustrating integration tests using clojure.spec
Clojure
8
star
6

edn-spike

Spike REST service using the content type "edn/application", backend in Clojure, frontend in ClojureScript
Clojure
7
star
7

kaleidoscope

Predicate dispatch for Clojure
Clojure
6
star
8

music-made-simple

Code for demo from the talk Music Made Simple
Clojure
6
star
9

propaganda-a-declarative-programming-model-in-clojure

Presentation: Propaganda! A declarative programming model in Clojure
Clojure
6
star
10

bron-kerbosch-in-clojure

A Clojure implementation of the Bron-Kerbosch algorithm for finding maximum cliques.
Clojure
5
star
11

composer

An experiment in creating an instrument for composing music
Clojure
4
star
12

roulette

A roulette for selecting students/topics/articles, written in ClojureScript
JavaScript
4
star
13

tex-service

A clojure web service for generating LaTeX formulas
Clojure
4
star
14

molecule-cut

A Clojure program for comparing molecules based on gradually removing bonds from molecules.
Clojure
3
star
15

observable-buffer-spike

Clojure
3
star
16

alijn

A program for extracting and aligning molecular pharmacophores
Clojure
3
star
17

RedBlackTreesUsingMatch

Clojure
2
star
18

getting-hot

An example of using propagators to represent temperature
Clojure
2
star
19

hands-on-core-logic

Notes and scripts for hands on core.logic session for FP Days 2013
Clojure
2
star
20

gcse-results

GCSE results visualisation
Clojure
2
star
21

lirror

Inkscape extension for creating generative art
Python
2
star
22

cljs-propaganda-example

Clojure
1
star
23

tgk.github.com

Clojure ramblings
CSS
1
star
24

retro-ring-roundtrip

A retro roundtrip of ring, the Clojure http library
Clojure
1
star
25

wadlviz

Clojure
1
star
26

kdgrid

A clojure implementation of the kD-grid datastructure
Clojure
1
star
27

rob

Robot game in Clojure and CoffeeScript
Clojure
1
star
28

pageler

A homepage for making small single page homepages.
Clojure
1
star
29

bibmarklet

Bookmarklet for finding books on bibliotek.dk
CoffeeScript
1
star
30

token_data_generation

Setup for generating tokens used in Tanimoto experiments
Java
1
star
31

riemann-http-proxy

Riemann HTTP Proxy
Clojure
1
star