-
Notifications
You must be signed in to change notification settings - Fork 108
REPL
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
- Read incoming source code, turning text into expressions
- Evaluate new expressions, producing values, creating new functions, or effecting the state of the application
- Print the results back to the programmer
- 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.
There are (at least) three routes to Emacs integration.
Arcadia's nREPL implementation usable from cider, though many of the more advanced IDE-like features are not yet supported.
- Start a Unity project that contains Arcadia (see Getting Started).
- Install cider normally.
- Follow the instruction to connect to a running nREPL server, providing
localhost
as the host and 3722 as the port.
By using Miracle you gain access to jump to definition and describe var, and more!
- Start a Unity project that contains Arcadia (see Getting Started).
- Install the miracle package, making sure to follow all the installation steps.
- Use
M-x miracle
and connect tolocalhost:3722
.
An example project to get started, if anyone has any feedback for improvements please create an issue!
- Start a Unity project that contains Arcadia (see Getting Started).
- Install the inf-clojure package, and follow the instructions on its repo for activating it for Clojure files.
- 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)
- With this in place, type
M-x arcadia-repl
to connect via aninf-clojure
REPL once Arcadia is running in Unity. Mostinf-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)
Arcadia's nREPL implementation is usable from vim-fireplace
- Start a Unity project that contains Arcadia (see Getting Started).
- Install vim-fireplace, skipping the setup of cider-nrepl
- Start editing a Clojure file
- Use the
:Connect
command and providelocalhost
as the host and 3722 as the port
Arcadia's nREPL implementation is usable from proto-repl.
- Start a Unity project that contains Arcadia (see Getting Started).
- Install the
proto-repl
andink
packages. - In the
proto-repl
settings, uncheck Enable Completions and Refresh On Repl Start. These do not work with Arcadia yet. - Restart Atom for the changes to take effect
- Connect to Arcadia with the
Proto Repl: Remote Nrepl Connection
command, using 3722 as the port and leaving the host aslocalhost
(the default)
Arcadia's nREPL implementation is usable with the https://notabug.org/selfsame/arcadia-repl package:
- Start a Unity project that contains Arcadia (see Getting Started).
- Open Sublime's Packages directory (Preferences -> Browse Packages...), clone the
arcadia-repl
package. - Right Click and select
Start Arcadia NREPL
from context menu. -
Alt+Enter
to evaluate top level forms, full key list here.
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=>