Janet 1.9.1-4ae3722 Documentation
(Other Versions: 1.8.1 1.7.0 1.6.0 1.5.1 1.5.0 1.4.0 1.3.1 )

Introduction

Installation

Install a stable version of Janet from the releases page. Janet is prebuilt for a few systems, but if you want to develop Janet, run Janet on a non-x86 system, or get the latest, you must build Janet from source.

Windows

The recommended way to install on Windows is just to run the installer from the releases page. A Scoop package was maintained previously, but ongoing support is being dropped.

If you want to use jpm to install native extensions, you will also need to install Visual Studio, ideally a recent release (2019 or 2017 should work well). Then, running jpm from the x64 Native Tools Command Prompt should work for a 64-bit build, and from the Developer Command Prompt should work for 32-bit builds. Using these specific command prompts for jpm simply lets jpm use the Microsoft compiler to compile native modules on install.

Linux

Arch Linux

You can install either the latest git verion or the latest stable version for Arch Linux from the Arch user repositories with janet-lang-git or janet-lang.

macOS

Janet is available for installation through the homebrew package manager as janet. The latest version from git can be installed by adding the --HEAD flag.

brew install janet

Compiling and running from source

If you would like the latest version of Janet, are trying to run Janet on a platform that is not macOS or Windows, or would like to help develop Janet, you can build Janet from source. Janet only uses Make and batch files to compile on POSIX and Windows respectively. To configure Janet, edit the header file src/conf/janetconf.h before compilation.

macOS and Unix-like

On most platforms, use Make to build Janet. The resulting files (including the janet binary) will be in the build/ directory.

cd somewhere/my/projects/janet
make
make test

After building, run make install to install the janet binary and libraries. This will install in /usr/local by default, see the Makefile to customize.

FreeBSD

FreeBSD build instructions are the same as the Unix-like build instuctions, but you need gmake and gcc to compile.

cd somewhere/my/projects/janet
gmake CC=gcc
gmake test CC=gcc

Windows

  1. Install Visual Studio or Visual Studio Build Tools
  2. Run a Visual Studio Command Prompt (cl.exe and link.exe need to be on the PATH)
  3. cd to the directory with Janet
  4. Run build_win to compile Janet.
  5. Run build_win test to make sure everything is working.

To install from source, first follow the steps above, then you will need to

  1. Install, or otherwise add to your PATH, the WiX 3.11 Toolset
  2. Run a Visual Studio Command Prompt (cl.exe and link.exe need to be on the PATH)
  3. cd to the directory with Janet
  4. Run build_win dist
  5. Then, lastly, execute the resulting .msi executable

Emscripten

To build Janet for the web via Emscripten, make sure you have emcc installed and on your path. On a Linux or macOS system, use make emscripten to build janet.js and janet.wasm - both are needed to run Janet in a browser or in Node.js. The JavaScript build is what runs the REPL on the main website, but really serves mainly as a proof of concept. Janet will run slower in a browser. Building with Emscripten on Windows is currently unsupported.

Meson

Janet also has a build file for Meson, a cross-platform build system. This is not currently the main supported build system, but should work on any system that supports Meson. Meson also provides much better IDE integration than Make or batch files.

Small builds

If you want to cut down on the size of the final Janet binary or library, you need to omit features and build with -Os. With Meson, this can look something like below:

git clone https://github.com/janet-lang/janet.git
cd janet
meson setup SmallBuild
cd SmallBuild
meson configure -Dsingle_threaded=true -Dassembler=false -Ddocstrings=false \
    -Dreduced_os=true -Dtyped_array=false -Dsourcemaps=false -Dpeg=false \
    -Dint_types=false --optimization=s -Ddebug=false
ninja
# ./janet should be about 40% smaller than the default build as of 2019-10-13

You can also do this with the Makefile by editing CFLAGS, and uncommenting some lines in src/conf/janetconf.h.

First program

Following tradition, a simple Janet program will print "Hello, world!".

(print "Hello, world!")

Put the following code in a file named hello.janet, and run janet hello.janet. The words "Hello, world!" should be printed to the console, and then the program should immediately exit. You now have a working Janet program!

Alternatively, run the program janet without any arguments to enter a REPL, or read-eval-print-loop. This is a mode where Janet works like a calculator, reading some input from the user, evaluating it, and printing out the result, all in an infinite loop. This is a useful mode for exploring or prototyping in Janet.

This hello world program is about the simplest program one can write, and consists of only a few pieces of syntax. The first element is the print symbol. This is a function that simply prints its arguments to the console. The second argument is the string literal "Hello, world!", which is the one and only argument to the print function. Lastly, the print symbol and the string literal are wrapped in parentheses, forming a tuple. In Janet, parentheses and brackets are interchangeable, brackets are used mostly when the resulting tuple is not a function call. The tuple above indicates that the function print is to be called with one argument, "Hello, world".

All operations in Janet are in prefix notation: the name of the operator is the first value in the tuple, and the arguments passed to it are in the rest of the tuple. While this may be familiar in function calls, in Janet this idea extends to arithmetic and all control forms.

The core library

Janet has a built in core library of over 300 functions and macros at the time of writing. For efficient programming in Janet, it is good to be able to make use of many of these functions.

If at any time you want to see short documentation on a binding, use the doc macro to view the documentation for it in the REPL.

(doc defn) # -> Prints the documentation for "defn"

To see a list of all global functions in the REPL, type the command

(all-bindings)

Which will print out every global binding in the Janet REPL. You can also browse the core library API on the website.