Next: Emacs integration, Up: Development [Contents][Index]
To use a local REPL within NodeJS, simply run hoot repl and
evaluate some code:
$ hoot repl (hoot user)> (+ 1 2 3) => 6
To load a module, use the ,use meta-command:
(hoot user)> ,use (srfi srfi-1)
Importing a module may or may not result in loading Scheme source code from the file system. If the module was a dependency of the compiled program that is running the REPL then the module is already baked into the Wasm binary. Otherwise, the Hoot load path is searched for a file corresponding to the given module name.
Modules loaded from the file system at runtime have a limitation: they
must be pure Scheme files that do not include raw Wasm fragments,
either directly or indirectly through macro expansion. Notably, this
means that any module that uses define-foreign from the
(hoot ffi) module cannot be loaded from the file system at
runtime and instead must be compiled into the Wasm binary
(see REPL limitations).
To switch modules, use the ,module meta-command and the
prompt will change to reflect the new top-level environment:
(hoot user)> ,module (srfi srfi-1) (srfi srfi-1)> ,module (hoot user) (hoot user)>
When evaluated code throws an exception, a new debugging sub-REPL is opened:
(hoot user)> (+ 1 "two")
Scheme error:
1. #<&failed-type-check predicate: "number">
2. #<&message message: "type check failed">
3. #<&origin origin: "+">
4. #<&irritants irritants: ("two")>
5. #<&source file: "hoot/numbers.scm" line: 130 column: 2>
Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
(hoot user) [1]>
Note the [1] in the prompt showing the current sub-REPL depth.
To exit a sub-REPL, use the ,quit meta-command:
(hoot user) [1]> ,q (hoot user)>
When in the top REPL, ,quit will exit the REPL entirely and
return control back to the shell:
(hoot user)> ,q $
Running a REPL within NodeJS is cool, but it would be even better to
connect to a REPL running withing a web browser. This can be done
using Hoot’s development web server and the (hoot web-repl)
module!
First, setup a web page to run a Hoot program (see Tutorial for instructions).
Below is a minimal program that runs a REPL and does nothing else:
(use-modules (hoot web-repl)) (run-web-repl)
In order for this program to be usable it needs to be compiled with
the -g1 (debugging level 1) flag to create a development build
that includes the runtime module system:
guild compile-wasm -g1 -o web-repl.wasm web-repl.scm
To connect to the REPL running in the web browser, we require the assistance of the Hoot development web server:
hoot server
Browse to http://localhost:8080 to start the REPL.
Finally, connect to the REPL:
hoot repl --connect
If all went well, the REPL prompt should now be waiting for a Scheme expression to evaluate. Happy live hacking!
Next: Emacs integration, Up: Development [Contents][Index]