Skip to content
Folcon edited this page Sep 27, 2021 · 20 revisions

One of Arcadia's most exciting features is its ability to livecode Unity. This is enabled by Clojure which, as a member of the Lisp family of programming languages, is designed with a Read Evaluate Print Loop (or REPL) in mind. The function of a REPL is to

  1. Read incoming source code, turning text into expressions
  2. Evaluate new expressions, producing values, creating new functions, or effecting the state of the application
  3. Print the results back to the programmer
  4. Loop back to the first step, waiting for more code

The evaluated code can be as large as a whole file, or as small as an individual expression. The REPL is used to incrementally sculpt your game while developing it, to query the state of things while debugging, to put on livecoding performances, and much more.

Arcadia includes two REPL servers: Clojure's standard socket server provided by the clojure.core.server namespace listening on port 37220, and a basic implementation of an nREPL server listening on port 3722. The socket server is simple and easy to integrate into new environments while nREPL is somewhat more involved but has more tooling built for it in the Clojure ecosystem.

The nREPL current implementation is very basic and only supports evaluation, so the IDE-like features of e.g. cider will not work. Furthermore, Arcadia's breakpoint system currently only works with the socket server REPL and not nREPL.

Editor Integration

Emacs

There are (at least) three routes to Emacs integration.

cider via nREPL

Arcadia's nREPL implementation usable from cider, though many of the more advanced IDE-like features are not yet supported.

  1. Start a Unity project that contains Arcadia (see Getting Started).
  2. Install cider normally.
  3. Follow the instruction to connect to a running nREPL server, providing localhost as the host and 3722 as the port.
Miracle via nREPL

By using Miracle you gain access to jump to definition and describe var, and more!

  1. Start a Unity project that contains Arcadia (see Getting Started).
  2. Install the miracle package, making sure to follow all the installation steps.
  3. Use M-x miracle and connect to localhost:3722.
Cursive via nREPL

An example project to get started, if anyone has any feedback for improvements please create an issue!

inf-clojure via socket-repl
  1. Start a Unity project that contains Arcadia (see Getting Started).
  2. Install the inf-clojure package, and follow the instructions on its repo for activating it for Clojure files.
  3. Place the following snippet in your .emacs file, .init file, or wherever else it's likely to be evaluated on Emacs startup.
(require 'inf-clojure)

(defcustom arcadia-repl-port 37220
  "Port to connect to Arcadia repl.")

(defun arcadia-repl ()
  "Attempts to connect to a running Arcadia instance over the Arcadia socket-repl."
  (interactive)
  (inf-clojure-connect "localhost" arcadia-repl-port))


;; inf-clojure's argslists eldoc support spams the Arcadia repl
;; and slows down Emacs. This (removable) empty wrapper function is a
;; quick kludge to disable it.
(defun arcadia-inf-clojure-eldoc-setup-wrapper (orig-fun &rest args)
  )

;; hack that disables eldoc for inf-clojure.
(advice-add 'inf-clojure-eldoc-setup :around #'arcadia-inf-clojure-eldoc-setup-wrapper)
  1. With this in place, type M-x arcadia-repl to connect via an inf-clojure REPL once Arcadia is running in Unity. Most inf-clojure commands should work as normal.

If you don't use inf-clojure for anything other than Arcadia, the following might also be desirable for less spurious error output related to automatic repl detection. See the docstring for inf-clojure-repl-type for details and another possible approach.

(defun arcadia-set-repl-type ()
  (setq-local inf-clojure-repl-type 'clojure))

(add-hook 'inf-clojure-mode-hook #'arcadia-set-repl-type)

Vim

Arcadia's nREPL implementation is usable from vim-fireplace

  1. Start a Unity project that contains Arcadia (see Getting Started).
  2. Install vim-fireplace, skipping the setup of cider-nrepl
  3. Start editing a Clojure file
  4. Use the :Connect command and provide localhost as the host and 3722 as the port

Atom

Arcadia's nREPL implementation is usable from proto-repl.

  1. Start a Unity project that contains Arcadia (see Getting Started).
  2. Install the proto-repl and ink packages.
  3. In the proto-repl settings, uncheck Enable Completions and Refresh On Repl Start. These do not work with Arcadia yet.
  4. Restart Atom for the changes to take effect
  5. Connect to Arcadia with the Proto Repl: Remote Nrepl Connection command, using 3722 as the port and leaving the host as localhost (the default)

SublimeText

Arcadia's nREPL implementation is usable with the https://notabug.org/selfsame/arcadia-repl package:

  1. Start a Unity project that contains Arcadia (see Getting Started).
  2. Open Sublime's Packages directory (Preferences -> Browse Packages...), clone the arcadia-repl package.
  3. Right Click and select Start Arcadia NREPL from context menu.
  4. Alt+Enter to evaluate top level forms, full key list here.

Command Line

In the absence of an editor the socket server REPL is usable from the command line via telnet

$ telnet localhost 37220
Trying ::1...
Connected to localhost.
Escape character is '^]'.
user=>