Skip to content

Chain definition language

Giovanni Petrantoni edited this page Apr 4, 2021 · 9 revisions

Chainblocks wants to be a meta language or a visual language rather then a pure programming language, but to nicely describe chains and the data they contain we adopt and write a simple language based on EDN and Clojure. Notice that in theory any language can be used, this was just a pragmatic choice. In fact you will also find chains written in C++ digging the Chainblocks codebase.

You can basically think of it as a comprehensible JSON on steroids that can be evaluated or the Ansible of general programming.

The execution of Chainblocks scripts is meant to be fast, the script language is just a description of the computational graph. The runtime itself is completely detached.

Basically load, define the chain/s, attach them to a node and kick off the runtime.

Some examples

Super simple example

Code

; define a node
(defnode main)
; define a simple hello world looped chain
(defloop hello-world
  (Msg "Hello world"))
; schedule the chain for exection
(schedule main hello-world)
; run the node at 1 second intervals
(run main 1.0) ; <-- execution will block here

Output

[info] [2021-04-04 16:43:22.290] [T-148944] [logging.cpp::94] [hello-world] Hello world
[info] [2021-04-04 16:43:23.299] [T-148944] [logging.cpp::94] [hello-world] Hello world
[info] [2021-04-04 16:43:24.291] [T-148944] [logging.cpp::94] [hello-world] Hello world
[info] [2021-04-04 16:43:25.289] [T-148944] [logging.cpp::94] [hello-world] Hello world
[info] [2021-04-04 16:43:26.291] [T-148944] [logging.cpp::94] [hello-world] Hello world
[info] [2021-04-04 16:43:27.299] [T-148944] [logging.cpp::94] [hello-world] Hello world
[info] [2021-04-04 16:43:28.296] [T-148944] [logging.cpp::94] [hello-world] Hello world
[info] [2021-04-04 16:43:29.292] [T-148944] [logging.cpp::94] [hello-world] Hello world
[info] [2021-04-04 16:43:30.295] [T-148944] [logging.cpp::94] [hello-world] Hello world
[info] [2021-04-04 16:43:31.298] [T-148944] [logging.cpp::94] [hello-world] Hello world
[info] [2021-04-04 16:43:32.298] [T-148944] [logging.cpp::94] [hello-world] Hello world
Clone this wiki locally