Function Index

Janet 0.4.1 Documentation
Special Forms
String Library
Data Structures
Object Oriented Programming
Abstract Machine
Function Index

Special Forms

These forms are recoginized as special by the compiler and define the core Janet language. Most of the other functions in the core library are defined in terms of these forms, or are implemented in C for performance.

break def do fn if quasiquote quote set splice unquote var while

Defining Forms

These forms are shorthands for creating top level bindings. Note that the macro forms should only be used at the top level, otherwise they will be interpreted as normal functions.

def- defglobal defmacro defmacro- defn defn- varglobal


These core operators are some of the most primitive and mathematical operators, defining arithmetic and comparisons. There are also macros for C-style imperative manipulation of variables. Imperative programming should mostly be internal to functions or very simple.

% %= * *= + ++ += - -- -= / /= < <= = == > >= and dec deep-not= deep= inc not not= or order< order<= order> order>=

Flow Forms

Use these forms to add branching to your programming. The most primitive branching structure is the if special form.

case cond if-let if-not let match try unless when when-let


Arrays are mutable, order sequences of values. They are one of the core data types in Janet.

array array/concat array/ensure array/insert array/new array/peek array/pop array/push array/remove array/slice array?


Buffer represent a mutable sequence of bytes. They are much like strings but can be modified and appended to. Buffers also support other operations that treat them like generic blocks of memory.

buffer buffer/bit buffer/bit-clear buffer/bit-set buffer/bit-toggle buffer/blit buffer/clear buffer/format buffer/new buffer/new-filled buffer/popn buffer/push-byte buffer/push-string buffer/push-word buffer/slice buffer?


A predicate is a function of one argument that returns true or false. Predicates or most commonly used with combinators, like filter, keep, or find.

abstract? array? boolean? buffer? bytes? cfunction? dictionary? empty? even? every? false? fiber? function? idempotent? indexed? keyword? neg? nil? number? odd? one? pos? string? struct? symbol? table? true? tuple? zero?

Threading Macros

Threading macros are useful for creating pipelines. The Janet threading macros are borrowed from janet. They make deeply nested code more linear form, and usually easier to read.

-> ->> -?> -?>> as-> as?->

String Functions

Strings in Janet represent both text and arbitrary byte sequences. Strings are immutable, so most operations on them will create new strings.

string string/ascii-lower string/ascii-upper string/bytes string/check-set string/find string/find-all string/format string/from-bytes string/join string/repeat string/replace string/replace-all string/reverse string/slice string/split string?

Table Functions

The mutable hashtable type in Janet is very versatile and can be used for an associative array, prototype based OO, and execution environments.

table table/getproto table/new table/rawget table/setproto table/to-struct table?

Struct Functions

Structs are janet's immutable hashtable type. They are very similar to tables but do not offer prototypes, and support value equality. They make great keys for other structs or tables.

struct struct?

Tuple Functions

Tuples are immutable lists. They are also the data type used to represent function calls, macro invocations, and special forms in Janet. They come in two flavors, bracketed and unbracketed tuples.

tuple tuple/brackets tuple/slice tuple/type tuple?

Fiber Functions

Fibers represent a separate flow of execution in Janet, with it's own stack an execution context. Multiple fiber's can be run on the same OS thread, in this sense they are more fine grained than OS threads.

fiber/current fiber/maxstack fiber/new fiber/setmaxstack fiber/status fiber?

Typed Array Functions

Typed arrays are wrappers around C style arrays of integers, and are useful for interfacing with C libraries that contain such structures in a uniform way.

tarray/buffer tarray/copy-bytes tarray/length tarray/new tarray/properties tarray/slice tarray/swap-bytes

Peg Functions

Pegs, or Parsing Expression Grammars, are Janet's main pattern matching facility, replacing regular expressions in other languages.

peg/compile peg/match

OS Functions

Janet offers several functions for operating with the OS in both platform dependent and platform independent ways.

os/clock os/cwd os/date os/execute os/exit os/getenv os/setenv os/shell os/sleep os/time os/which

IO Functions

Janet offers basic file I/O for interacting with the file system. The file library is mostly a wrapper around the C stdio library.

file/close file/flush file/open file/popen file/read file/seek file/write slurp spit stderr stdin stdout

Module Functions

Interact with the Janet module system. Janet has a simple but not inflexible system for mapping module names to file paths, preventing modules from loading more than once, and import and exporting symbols from one module to another.

import import* load-image make-image module/*syspath* module/cache module/find module/loading module/paths require


Inspect or create functions from Janet bytecode

asm disasm

Macro Helpers

These functions and macros are useful for writing your own macros. Also checkout the quasiquote special form.

defmacro defmacro- gensym idempotent? macex macex1 with-syms


Besides the primitive while loop and tail recursion, Janet has a handful of macros for looping.

each for generate loop seq while


Combinators are what make up the bread and butter of the Janet core library. Combinators perform transformations on data structures or functions, resulting in code that is usually more succinct than imperative code. Use liberally.

all comp complement count distinct drop-until drop-while every? extreme filter find find-index first flatten flatten-into frequencies identity interleave interpose invert juxt juxt* keep keys kvs last map mapcat max max-order merge min min-order pairs partial partition postwalk prewalk product range reduce reverse some sort sorted sum take-until take-while update values walk zipcoll

Miscellaneous Forms

Grab bag of other forms in the core library.

*doc-width* all-bindings bad-compile bad-parse comment default doc doc* error eval eval-string get getline keyword make-env meta pp put repl resume run-context symbol yield