Clarive SE 7.0.8 has a new exciting feature, a Read-Eval-Print-Loop, also known as a REPL.

The Clarive REPL now supports rulebook code. In fact that’s the only language available in Clarive SE. Clarive EE also has server-side JavaScript, which is useful if you develop plugins.

Having a rulebook REPL means you can try out your rulebooks in your browser environment.

clarive rulebook repl golang

This is a great tool for learning how to write rules and pick up a few rulebook chops.

No Events

The rulebook REPL will only run a do: section, since in the REPL environment there are no when events set up like there usually is in a pipeline or event trigger.

Say you want to try a simple hello world example:

do:
   - friends_name =: Mary
   - echo: "hello world, ${friends_name}"

Write the rule into the REPL and hit the Run button.

In the Output tab there the execution standard output will be shown:

clarive rulebook repl

Appended underneath to the output is the stash, which holds a set of global variables and the variables created by your rule.

Ace Editor

The REPL interface is a an Ace Editor web component, which is a very powerful editor, at least for a web code editor anyway. So you have plenty of keyboard shortcuts to help your edit and navigate. For a list of available Ace Editor shortcuts, check this link out:

https://github.com/ajaxorg/ace/wiki/Default-Keyboard-Shortcuts

You can also use the multi-cursor feature, which makes editing large files fun.

Benchmarking

One of the great uses of the REPL is to benchmark your rule. You can monitor how long it takes to execute a instruction by observing the Elapsed: field on the upper right corner:

clarive repl elapsed

Workspace

If you want to test your rulebooks with files, you can create temporary workspaces by instructing clarive to clone your Git repo right in the rulebook.

workspace:
   - MyProject/MyRepo:master
do:
   - ls /clarive/MyProject/MyRepo
   - ship:
       host: myremoteserver     # you'll need to create your credentials first
       from: MyProject/MyRepo/file.txt
       to: /opt/remotepath/

The above example will run make the contents of the repository MyRepo available to your rulebook. The repository MyRepo belongs to the project MyProject in this example, so you also need to include the project in the path.

History and saving

The REPL snippets are automatically saved into the history list on the left. That way you can rollback to a previous version of your rulebook in case you something goes wrong.

clarive repl history rulebook

REPL snippets can also be saved. Saved snippets are automatically shared with all users in your Clarive instance.

DevOps in a REPL

You can install and try out Docker images directly from the REPL using the image: op.

do:
   - image: python
   - python --version

But note: the first time you use it, Clarive will download and configure your Docker container from the hub and set it up for first use. The output will have the following log:

[running] $ python --version
Python 3.6.3
[done] $ python --version

In the above case the elapsed time will be approximately 1m30s the first time you run in our free clarive cloud instance. But the second time around and after that it should only take ~0.5s.

To learn how to write rulebooks, take a look at our documentation.


Visit our documentation to learn more about the features of Clarive.