The term REPL stands for Read-Eval-Print Loop. Even the C language has REPL implementations these days, but the first REPL was a Lisp invention. Jwno inherited the tradition of providing this great  toy  tool.

Jwno's REPL have a coding environment that's almost identical to the one you get in the config file, so you can run your experiments in the REPL, then incorporate them into your config file, and your code would have pretty much the same behavior.

The REPL Server

Jwno's REPL works in a client-server style, communicating via a TCP socket bound on localhost. A server has to be started before the REPL client can connect to it. You can tell Jwno to automatically start a server in some situations, and the server would bind to 127.0.0.1:9999 by default. If the server failed to start automatically, check whether that address is occupied by other programs.

Launching the REPL

There are multiple ways to launch the REPL:

  • Right-click on the notification area icon Jwno Logo shown on the taskbar, then select Launch REPL. This command will try to connect to an existing REPL server, and automatically start one if none is running.
  • Bind a key to call the :repl command. You can specify in the command's arguments whether a server should be automatically started or not:
     # The `true` argument tells the command to
     # automatically start an REPL server
    (:define-key keymap "Win + Enter" [:repl true])
  • Pass the --client and --repl options when starting Jwno from the command line. This will not start an REPL server automatically, and Jwno will show a network error when no server is running:
    jwno.exe --client --repl 127.0.0.1:9999

When the REPL connected successfully, a console window will pop up, showing a simple prompt:

Welcome to Jwno REPL!
[127.0.0.1:9999]:1: _

Keyboard Shortcuts

The REPL console provides some of the keyboard shortcuts often seen in programs using the Readline library:

  • Tab: Auto-complete current word.
  • (Up arrow key): Previous line in history.
  • (Down arrow key): Next line in history.
  • Ctrl + G: Show documentation for the identifier before the cursor.
  • Ctrl + A: Move the cursor to the beginning of current line.
  • Ctrl + E: Move the cursor to the end of current line.
  • Ctrl + F: Move the cursor one character forward.
  • Ctrl + B: Move the cursor one character backward.
  • Alt + F: Move the cursor one word forward.
  • Alt + B: Move the cursor one word backward.
  • Ctrl + D: Delete one character at the cursor, or send EOF (exit the REPL) when current line is empty.
  • Ctrl + H: Delete one character before the cursor.
  • Ctrl + L: Clear screen.

The Environment

The REPL environment provides the usual APIs from Janet's core library, plus some global variables exported by Jwno (they all have the jwno/ prefix):

  • jwno/context: The context object containing all the states tracked/used by Jwno's main thread. REPL connections also run in the main thread (but in different fibers), so you can access most parts of this object in the REPL directly and safely, without triggering race conditions and the like.
  • jwno/repl-server: The REPL server we connected to.
  • jwno/client-name: The name for the current REPL client, as shown in the REPL prompt.
  • jwno/client-stream: The socket stream for the current REPL client.

Every REPL connection has its own environment. Everything referenced in an REPL session will be cleared when it's closed. And if you defined a variable in one REPL session, it will not be accessible in other REPL sessions. To make something persist, and be accessible to all REPL sessions, you can export it:

(import jwno/util)
(def the-answer 42)
(util/export-to-repl jwno/repl-server the-answer)

And of course you can remove exported names:

(util/unset-from-repl jwno/repl-server the-answer)

Next Step

See Also