Janet 1.3.1 Documentation

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

On Windows, the easiest way to install is via the scoop package manager. You will first need to add the janet-lang bucket, and then you can install janet normally.

scoop bucket add janet-lang https://github.com/janet-lang/scoop
scoop install janet

AUR

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 binary will be in build/janet.

cd somewhere/my/projects/janet
make
make test

After building, run make install to install the janet binary and libs. 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) and cd to the directory with janet.
  3. Run build_win to compile janet.
  4. Run build_win test to make sure everything is working.

To install from source, the best way to is use NSIS to generate an installer and run that. You will need NSVC (or the Microsoft Build Tools) to build everything, and NSIS to build the installer. From a Developer Command Prompt, run `build_win all` to build, test, and install Janet on your local machine.

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. 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.

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. This 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".

Like all lisps, 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.

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.