Your First Program
Four steps, about five minutes. You will end with a program the compiler has proved correct, printing an exact fraction.
Get the toolchain
The whole toolchain is one package on the npm registry. Installing it once puts
an essence command on your path:
Installation covers adding it to a project instead, running it without installing it, and building it from a checkout.
essence --version should answer 0.1.0.
Write a program
Put this in hello.es, anywhere you like. A program needs no manifest and no
project around it — a file is enough.
Five things are worth naming before you run it:
implementation { … }wraps the file. It is the form a program takes; the standard library usesdeclarations { … }instead, which is what lets it declare methods the runtime implements.§starts a comment, and§§a documentation comment. There is no//.1/3is a literal, not a division that has already happened. It is aRational, kept exact and in lowest terms.::calls a method on a value.oneThird::add(twoThirds)is the same call asRational.add(oneThird, twoThirds).{sum}is an interpolation hole, and it takes an expression rather than only a name — whatever is inside it is stringified where it stands.
Check it
essence check runs the parser, enricher and validator and stops there. Nothing
is written to disk, so this is the fastest way to ask whether a program is valid.
$ essence check hello.es
✔ hello.es no errors
read 0.09 ms ░
parse 1.4 ms █
enrich 34 ms ████████████████████████
validate 0.04 ms ░
total 36 msTry breaking it — pass add a String, say — and check again. The compiler will
tell you exactly which types did not line up, where, and what it was expecting
instead. Every diagnostic carries a stable code, so the same error is looked up the
same way however you met it.
Run it
essence run compiles the file and executes it in one step, without leaving a
.js file behind.
$ essence run hello.es
✔ hello.es → /tmp/essence-6NZrhM/hello.js
output 7.6 kB · 1.8 kB gzipped
total 90 ms
─── program output ───────────────────────────────────────────────────────────
"1/3 + 2/3 = 1/1"
──────────────────────────────────────────────────────────────────────────────
✔ program exited with code 0 after 14 ms1/1, not 0.9999999999999998. Thirds are held as thirds and added as thirds;
nothing is rounded on the way, so the answer is exactly one.
What to read next
- Project layout — what a program is without a manifest, and what the compiler writes where.
- Installation — adding the toolchain to a project, and every command it carries.