Getting Started
Last updated
Last updated
Jock programs are written in plain text and built using choo
, the NockApp compiler.
Download and build choo
.
In a separate location, download the JockApp basic repo.
Copy choo
from nockapp/target/build/release
to the root of jockapp-tutorial
.
Run the “Hello World” JockApp:
This should output the simple message, “Hello World” along with some logging details. (At the current time, choo
does not always exit after a successful poke, so you may have to press Ctrl+C to close the JockApp instance.)
Examine the source code /hoon/try/hello-world.jock
.
(You can skip this section and come back to it later if you are completing this tutorial for the first time.)
The following files are included in this tutorial repository:
/hoon/main.hoon
, the main entry point for a choo
application. (If you know Hoon, you can change this file to load or manipulate other Jock programs.)
/hoon/lib/jock.hoon
, the main Jock language definition. (You would only change this if you want to play with changing Jock.)
/hoon/lib/mini.txt
, the reference Hoon implementation which Jock utilizes. (You can change this to add functionality to the Hoon standard library if you like.)
/hoon/lib/wrapper.hoon
, the NockApp dispatcher. (You would not typically change this.)
/hoon/try/*
, the Jock tutorial files.
Other files in /hoon/lib
such as math.hoon
and sequent.hoon
are libraries for use in examples.
main.rs
is the Rust input/output wrapper which handles the command-line interface.
Follow steps 1–3 of the “Hello World” tutorial to make sure that your environment is set up correctly.
Run the “Fibonacci” JockApp:
This will calculate and display the first ten Fibonacci sequence numbers twice; once calculated recursively, once non-recursively.
Examine the source code /hoon/try/fibonacci.jock
.
You will notice that, in Jock, the recursion point for the function is indicated not by reusing the function's name but by the universal symbol $
buc.
Follow steps 1–3 of the “Hello World” tutorial to make sure that your environment is set up correctly.
Run the “Calculator” JockApp:
This will
Examine the source code /hoon/try/calculator.jock
.
You can modify the program using conventional arithmetic operators, with the caveat that ()
“pal”/“par” parentheses should be used to order expressions intuitively. (Jock currently evaluates operators from right to left, APL-style.) Furthermore, underflows (sub(3 4)
) will cause a crash.
A NockApp can build and run a program written in Jock. A NockApp is a kernel with a defined interface for interacting with its Rust I/O wrapper. At this point in the developer preview, we will have to modify the Jock program to accept a command-line argument before we build it.
We will use the fibonacci
program from above as the basis for this exercise.
We have already prepared main.hoon
and main.rs
to permit a demo with an optional argument. Examine the demo-arg
material in main.hoon
and the Command
and let poke
components in main.rs
if you are interested in implementation details.
If you modify main.rs
, you need to run cargo build
again.
Make a fresh copy of it as /try/fibapp.jock
.
Replace the tuple at the end with fib(#0)
, which we will use as a placeholder for command line arguments at the current time.
In /lib/demos.hoon
, we make the following changes (already made, but noted here):
Add /* fibapp %jock /try/fibapp/jock
after the other library imports at the top.
Add [%fibapp q.fibapp]
to ++demos
. By itself, this imports the text of the file, which would be parsed naturally by the other arms in this Hoon file. However, we need to modify the file with the received command-line argument that we will supply.
Because we need to interpolate the command-line argument into the text, we need to add a preprocessor gate in main.hoon
. Since the arms of the NockApp interface are fixed, we should add it to a |^
“barket” inside of %demo-arg
.
Add the preprocessor over the source text as (preprocess u.code ~[(scot %ud v.c)])
.
With those pieces in place, the NockApp framework can replace arbitrary command-line arguments in numerical order into the Jock code.
Rebuild the NockApp with the updated files using make release
, then run it using make demo fibapp 5
.
This NockApp still relies on a Hoon wrapper to dispatch data from the Rust I/O interface to the Jock code, rather like a script file or Urbit generator.
In this release, Jock preprocesses a file to supply command-line arguments; at a later date we intend to change this to an exposed
Map
namespace once language support becomes available.
Syntax is liable to change, although the target Nock instruction set architecture is fixed.
The Hoon standard library is available through the hoon
namespace. This is an extended version of /lib/tiny
and provides basic mathematics, container operations, and other simpler affordances. It does not include the Hoon parser, the compiler, etc.