Skip to content

REPL

REPL stands for Read Eval Print Loop, which basically means it's an interface to try out code while we develop it.

The Clarive REPL is specially important in the development process as it will enable the developer to test the code and calls within the Clarive server environment. The server environment includes things as database connection, access to related servers, such as build servers and deployment nodes. That way you can test your code in a familiar environment with close to real tests.

REPL Components

The REPL has 3 main panels:

  • The code entry area, where the code should be entered
  • The left panel where her History and Saved trees are.
  • The bottom Output panel

AutoSave user preferences

REPL keep CLARIVE default values are the default for the following menus:

  • Language menu.
  • Output menu.
  • Theme menu.

The next time the user enters the REPL will start with the last values loaded.

Output panel

The output panel holds a representation of the data by evalling the last line of the REPL. In both Perl and JS, simply putting the variable or value in the last line is sufficient to produce an output.

This REPL code:

var xx = [1,2,3];
xx;

Results in the following representation:

---
- 1
- 2
- 3

Also, the REPL engine captures all the output to STDOUT and STDERR generated by the code, including thrown exceptions.

This code:

print( 123 );

Produces the following (YAML) output:

123

--- ~

Which basically translates as a 123 printed out and a undefined return value represented by YAML, which starts with ---.

History tree

The History tree shows the last 20 unique code executions for the current user session.

Everytime code is sent to the server, an entry is saved in the History tree for that user session.

If the user logs out and logs in again, the user's history is lost.

Saved tree

The Saved tree will hold all saved REPL items. The tree belongs to the user and will be attached to him for as long as the user is not deleted.

Deleting a user deletes all of her saved REPL entries.

Using the REPL

Enter some code in the main editor panel and hit Ctrl-Enter or Cmd-Enter (on Mac) to submit the code for execution.

Cancelling an execution

To cancel an execution does not actually kill the process on the server, just that it returns control to the user.

That means a server could be overloaded by requests if too many long-running REPL processes are executed.

Run

Runs the REPL. Equivalent to executing Ctrl-Enter or Cmd-Enter.

Language Menu

The REPL enables the execution of 4 types of code, controlled by the language menu drop-down:

  • Clarive JavaScript (Clarive JS)
  • Rulebook
  • Perl (requires special permissions)
  • CSS

This is controlled by the Lang drop-down menu.

Output Menu

Allows the user to select the format of the data shown on the bottom.

  • YAML - data structures are shown in YAML format
  • JSON - data structures are shown in JSON format
  • Table - will attempt to format an HTML table from an Array (or similar list type)
  • Data Editor - will attempt to show a data editor UI component with an Object (JS) or Hash/Dictionary data type.

Save Button

Will save the current REPL into the user saved REPL list.

Export all to file

Exports all saved REPL to files on the file system.

Delete

Deletes the current REPL in case it has been saved.

Tidy

Reformats (a.k.a. beautifies) the code so that it's neat and more readable.

Elapsed

This is the time, in seconds, the script took to compile (to bytecode) and execute.

This is important to gain insight on how fast and for how long a script can execute, so the developer can fine tune its execution.