☰

Using the Ciao Prolog Playground

Getting started

  • The Ciao Prolog Playground can be easily accessed from the Ciao main site: https://ciao-lang.org/playground. This will open by default the last program or notebook being edited, or a small example.

  • You can also start the playground by opening in your browser a URL obtained with the Share! button (see below) containing a program or notebook.

  • You can also open the playground and load at the same time a file from a URL by appending to https://ciao-lang.org/playground/ a # symbol and the URL of the code or document to be loaded. E.g., the following notebook: https://ciao-lang.org/playground/#https://github.com/ciao-lang/lpdoc/blob/master/examples/factorial_peano_iso.md: the notebook is opened in presentation mode and can be edited with the edit button on the top right).

  • To open the playground with the LPTP theorem prover incorporated use: https://ciao-lang.org/playground/lptp.html (subject to change). This also allows developing notebooks, slides, etc. with LPTP runnable cells (do New document for an example).

  • There are other Ciao-based playgrounds available, such as the s(CASP) playground; and new ones can be easily created.

Areas

The Ciao Prolog Playground includes a number of areas, most of which are editable (note that the arrangement of the areas is configurable):

  • The editor area (left area, or top if the window is narrow) is an editor for the program or notebook-style document. Users can add their code into this editor and modify it there. Programs can be loaded into the system's top level (see below), where they can be run by entering queries at the prompt. Documents are processed in the top level and rendered in the preview area (see below). If the document contains runnable examples these can be executed there.

  • The top-level area (on the right, or bottom if the window is narrow) is where most communication with the system takes place. The top-level first shows Loading Ciao... while the system is loading its dependencies. When the top-level is completely ready to use, it will show the prompt ?- . Now programs can be loaded and queries issued. This area is also an editor that allows, e.g., editing the query, recalling previous queries, etc.

  • The preview area is where documents or program documentation are rendered. This preview area (and other areas) can be also used for other graphical program output.

    The preview area can also be shown as a single window in presentation mode (⛶ button, see below).

Buttons and functionality

Area selector
Allows selecting which areas are visible.

New
Erases all previous content from the editor and allows loading a small sample program or document. This also switches the new content in the editor area to be treated as a program (New code, .pl) or as a document (New code, .md / .lpdoc).

File

Open local file
Lets you upload Prolog code (.pl file) or a document (.md or .lpdoc file) from your local file system. This action also erases all previous content present in the editor. The playground will switch to program mode or document mode depending on the type of file uploaded.

Open from URL
Same as above but allows loading from a URL.

Save locally (download) (Ctrl-x + Ctrl-s)
Allows downloading the code or document written in the playground directly to your file system.

Examples
Allows loading a number of examples of programs and notebooks (active logic documents) to get started.

.pl / .md (Playground mode)
Indicates if the playground is in code (.pl) or document (.md) development mode. It also allows toggling between these two modes.

Load (Ctrl-c + l)
In code mode, loads the program in the editor area into the top level. It compiles it and, in case there are any errors, they are printed in top-level area and highlighted in the editor. Once you click this button, you can ask queries about your code in the top-level.

🐞 (Debug, Ctrl-c + d)
In code mode, load code source in debug mode and enable tracing the control flow of the program for subsequent queries. Clicking again turns debug mode off. See the debugger documentation for more information.

📖 (Preview documentation, Ctrl-c + D)

  • In code mode (.pl) generate and preview the documentation for the code in the editor area using LPdoc.

  • In document mode (.md) process the document source in the editor it in the top level and render it in the preview area using LPdoc. If the document contains runnable examples these can be executed there.

⛶ (Toggle presentation mode)
Switches to a full window view of the document or any other content of the preview area. In this view:

  • The small tab at the top center allows returning to the editor mode (it also shows the header and the menus again when they have been hidden).

  • The rectangular ▭ icon switches to slides presentation mode, where each document section is presented as a separate slide.

  • In slides presentation mode, Right arrow, Space or N go forward (to the next step of the slide, or to the next slide), Left arrow or P go back; , and . go to the first and the last slide; finally, ESC exits slides mode. Note that while the cursor is in an editor or a toplevel the key strokes go there. To issue the commands to move through slides click first any part of the slide outside an editor or toplevel.

⚡ (Toggle on-the-fly mode)
If turned on, documents are rendered interactively, as they are edited, and programs are also processed in this way. Program errors and warnings are then shown on the code as it is being modified, or the results of editing a document source are shown progressively as the document is edited. This button is highlighted when on-the-fly mode is on.

👥 (Collaboration mode)
This button allows establishing collaborative editing sessions.

  • Pressing the button opens a dialog in which a session ID can be input (a default value is proposed, but can be changed).

  • The user initiating the collaboration can input a new ID (e.g., the name of the course, the classroom, etc.) and this ID can be given to the recipients which can then enter it also using the collaboration button, to join the session.

  • When connected to a session the ID is shown next to the 👥 symbol. This ID shows in green if the connection is up and red otherwise.

  • Pressing the collaboration button again disconnects from the collaboration session.

Collaboration sessions can be very useful for example in education environments. For example, students can be asked to write some code or write some document and can then show it to the class from their computer. Students can have, e.g., two playgrounds open, one in which they are doing their work, and another which is in a collaborative session with the instructor's computer, which is being shown on the projector (o shared online). A given student can paste his or her solution in the collaborative session and both the instructor and the student can make changes.

Share!
Is an alternative form of save, very useful for sharing!:

  • In code mode (.pl) it copies into the clipboard a shareable link which, when clicked, will open a playground with the current state of the program loaded in the editor area.

  • In document mode (.md) it copies into the clipboard a shareable link which, when clicked, will open directly the rendered document, which can then also be edited.

These links can be sent by email, embedded in other documents, etc. See also adding links to runnable examples and notebooks to arbitrary documents.

Abort query
This button will appear below the top-level when running a query that is taking too long. It terminates the query currently running.

This button fully terminates the Ciao worker executing the Ciao process, so it may take a some time to reload dependencies after aborting. The code in the editor area will be reloaded into the top-level.

Additionally

In addition, in the ... pull-down the following can be selected (in document mode, only the query time limit):

Run tests (Ctrl-c + u)
Loads the unit test library (unittest) into the top-level and runs any unit tests (test assertions) that may appear in the code.

Analyze and check assertions (Ctrl-c + V)
Analyze the program and perform compile-time checking of the assertions (types, modes, determinacy, ...) in the current module (using CiaoPP).

Analyze and check assertions (w/output)
Same as above, but also show in a separate area the results of analysis, i.e., the program annotated with the analysis results.

Specialize code (Ctrl-c + O)
Run the CiaoPP specializer (partial evaluator) on the code in the editor area.

Browse analysis/checking/optimizing options
Open the CiaoPP graphical menu for selecting different options for analysis, assertion checking, and optimization.

Query time limit
Provides choices for how long a query may run before it is aborted. The choice is remembered, for all the pages of the site. When a query is aborted the top level is restarted, so that the code has to be loaded again. A runnable cell in a document can give its queries a time limit of their own (with timeout=, see the LPdoc manual).

Also, in modes that include the LPTP theorem prover:

LPTP
Open the LPTP menu for processing files, selecting tactics, debugging, listing facts and definitions, etc.

Key bindings

The playground has two sets of key bindings, which can be chosen at the bottom of the Edit menu: Emacs key bindings, and the OS key bindings. The latter are those of the system the playground is running on, shown in the menu as macOS, Windows, or GNU/Linux key bindings (e.g., Cmd-c and Cmd-v on a Mac, or Ctrl-c and Ctrl-v on Windows or GNU/Linux, to copy and paste). The Emacs ones are used by default on a Mac, where they do not get in the way of the OS ones, which use Cmd, and the OS ones elsewhere. The choice is kept by the browser, and also applies to the runnable code of the documents of the same site.

The Edit menu has the most used editing commands, and the menus and buttons show the keys of their commands in the set in use. The rest are listed below, classified by functionality.

On Windows or GNU/Linux, the Emacs key bindings use Ctrl for their Ctrl keys, so that the OS ones that use it (to copy, paste, etc.) are not available; and some of them, such as Ctrl-n or Ctrl-w, are kept by the browser for itself.

Editing key bindings

These commands and bindings, those of the Emacs set, are useful for editing and moving around in the editor area, top levels, etc. (with the OS key bindings, those of the system are used). Meta is Alt (Option on a Mac).

Moving around:

  • Ctrl-a, Ctrl-e - beginning, end of the line.
  • Ctrl-f, Ctrl-b - forward, backward a character.
  • Ctrl-n, Ctrl-p - next, previous line.
  • Meta-f, Meta-b - forward, backward a word.
  • Meta-<, Meta-> - beginning, end of the text.
  • Ctrl-v, Meta-v - next, previous page.
  • Ctrl-l - show the line of the cursor in the middle; again, at the top; again, at the bottom.
  • Meta-g + g - go to a line.
  • Ctrl-s, Ctrl-r - search.
  • Meta-% - search and replace.

The region:

  • Ctrl-Space (or Ctrl-@) - set the mark: the keys above that move the cursor (and the arrows) then select from it, until Ctrl-g, an edit, a click, or the region is killed or copied. (On a Mac, Ctrl-Space may be the shortcut for changing the input source, in the keyboard settings.)
  • Ctrl-g - deactivate the mark.
  • Ctrl-x + Ctrl-x - exchange the cursor and the mark.
  • Ctrl-x + h (or Ctrl-x + Ctrl-p) - select all.

Killing and yanking (as cut and paste):

  • Ctrl-w - kill the region (or the selected text).
  • Meta-w - copy the region.
  • Ctrl-k - kill the rest of the line, or the end of the line if there is nothing left but blanks. Several in a row make one kill.
  • Meta-d, Meta-Backspace - kill the word after, before the cursor.
  • Ctrl-y - yank (paste) the last kill, or what was copied elsewhere (e.g., in another window) after it.
  • Meta-y - right after Ctrl-y, replace what was yanked by the kill before, and so on.

Kills are also copied to the clipboard, to paste them elsewhere. Text copied elsewhere is added to the kill ring by Ctrl-y, as in Emacs, if the browser lets the clipboard be read (it may ask for permission first, or show a Paste button to click; this is done only when something may have been copied since the last time, e.g., after going to another window); it can also be pasted as usual (e.g., Cmd-v on a Mac). With a region, each of the Meta keys can also be typed as Esc followed by the key, as in Esc + w.

Other editing:

  • Ctrl-d - delete the character to the right (Ctrl-h begins the help commands, see below).
  • Ctrl-t - transpose the characters around the cursor.
  • Ctrl-o - insert a line after the current position.
  • Ctrl-m - insert a line below.
  • Ctrl-x + Ctrl-u, Ctrl-x + Ctrl-l - selected text to upper, lower case.
  • Meta-; - comment/uncomment the current line or the selected lines.
  • Ctrl-/, Ctrl-_, Ctrl-x + u, Ctrl-z - undo.

Help from the manuals

The elements that the manuals define (predicates, properties, regular types, declarations, libraries) are completed, and described, in the editor (when editing a document, in its blocks of Ciao code) and in the top level:

  • Resting the mouse on a name shows its usage and a short description, with a link to its manual page. For a call, the definition with its number of arguments is chosen.
  • Ctrl-h + Ctrl-i (Ctrl-c + Ctrl-i in the top level), or Ctrl-Space with the OS key bindings, completes the name being written. Choosing a predicate writes it with its arguments, to be filled in (with Tab to go from one to the next).
  • Ctrl-h + S, or Shift-F1 with the OS key bindings, shows in the preview the manual entry for the name at the cursor, with links to the other definitions of the same name. What the preview showed before comes back with the Back link at the top, Esc, or the close button of the pane.

The last two are also in the Edit menu. The manuals are those of the site from which the playground is served.

Code processing key bindings

These commands perform Ciao or filesystem-related actions, with the keys of the Emacs set and those of the OS set (with Cmd on a Mac, Ctrl elsewhere):

  • Ctrl-x + Ctrl-s, or Cmd-s - save file (same as menu).
  • Ctrl-c + l, or Cmd-Enter - load code into top-level (same as button).
  • Ctrl-x + o - move to another playground area (Emacs set only).

These commands perform actions on the source code:

  • Ctrl-c + d, or Shift-Cmd-d - (un)debug source code (same as button).
  • Ctrl-c + D, or Shift-Cmd-Enter - preview documentation (same as button).
  • Ctrl-c + u, or Shift-Cmd-e - run any tests in the source code (same as menu).
  • Ctrl-c + V, or Shift-Cmd-a - analyze and check assertions in source code (same as menu).
  • Ctrl-c + O, or Shift-Cmd-o - run specializer on source code (same as menu).

Specific key bindings for the top-level

The top-level area includes some key bindings of its own:

  • Meta-p, Meta-n - previous, next query in history (with the Emacs key bindings, also Esc + p, Esc + n, as in Emacs).
  • Up arrow, Down arrow - previous, next query in history, with the OS key bindings. With the Emacs ones they move the cursor, as Ctrl-p and Ctrl-n do, as in Emacs. In the query cells of documents they also move the cursor, and go on to the cells above and below.
  • Ctrl-c + Ctrl-c, or Esc - abort the current query, if there is any running.

Aborting a query fully terminates the Ciao worker executing the Ciao process in the browser, so it may take some time to reload dependencies after aborting. The code present in the left (or top) window will be reloaded to the top-level.

Specific key bindings for LPTP

These are in the Emacs set only (with the OS key bindings, the commands are in the LPTP menu).

  • Ctrl-c + i + s - Send buffer.
  • Ctrl-c + i + g - Get buffer.
  • Ctrl-c + i + G - Send and get buffer.
  • Ctrl-c + i + a - Tactic: auto.
  • Ctrl-c + i + c - Tactic: case.
  • Ctrl-c + i + o - Tactic: comp.
  • Ctrl-c + i + e - Tactic: elim.
  • Ctrl-c + i + x - Tactic: ex.
  • Ctrl-c + i + f - Tactic: fact.
  • Ctrl-c + i + i - Tactic: ind.
  • Ctrl-c + i + q - Tactic: indqf.
  • Ctrl-c + i + t - Tactic: tot.
  • Ctrl-c + i + u - Tactic: unfold.
  • Ctrl-c + i + b - Debug.
  • Ctrl-c + i + l - List facts.
  • Ctrl-c + i + d - Print definition.
  • Ctrl-c + i + m - Mark formula.

Some playground characteristics and current limitations

In this platform the Ciao system code (binaries) and libraries are downloaded into your browser and all code is executed locally. This has the advantage that no connection is required other than this initial download, no server is necessary, etc. Also note that with this approach no information about your code or document will be uploaded or gathered.

Please also be aware of some current limitations of the playground with respect to a full, native installation of the Ciao system:

  • To reduce download times, only a subset of the libraries are loaded by default.

  • The playground runs around 2-3x slower than native binaries, and offers a subset of POSIX features. Also, some Prolog libraries that depend on 3rd-party binaries (via the foreign interface) may not be currently available.

  • The top level currently has some limitations regarding the loading of some packages, portraying answers, and others. We are actively working on all of these and are adding functionality continuously.

  • To save space, only a subset of the analyses (abstract domains) and the capabilities of CiaoPP for program verification (assertion checking, etc.) and optimization are currently available.

Please ask us if some useful library or feature is missing; if technically possible, we will add it. In any case, for intensive use we recommend installing Ciao Prolog natively, for improved performance and full features.