{"id":13439089,"url":"https://github.com/janet-lang/janet","last_synced_at":"2025-05-13T20:09:51.957Z","repository":{"id":38361555,"uuid":"84521458","full_name":"janet-lang/janet","owner":"janet-lang","description":"A dynamic language and bytecode vm","archived":false,"fork":false,"pushed_at":"2025-05-08T22:00:32.000Z","size":14801,"stargazers_count":3793,"open_issues_count":44,"forks_count":238,"subscribers_count":63,"default_branch":"master","last_synced_at":"2025-05-08T23:18:49.837Z","etag":null,"topics":["c","functional-language","imperative-language","interpreter","language","lisp","macros","repl","vm"],"latest_commit_sha":null,"homepage":"https://janet-lang.org","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/janet-lang.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-03-10T05:08:35.000Z","updated_at":"2025-05-08T22:00:36.000Z","dependencies_parsed_at":"2022-07-12T17:27:45.523Z","dependency_job_id":"2abf5852-f789-444b-b2ad-fde27055d96f","html_url":"https://github.com/janet-lang/janet","commit_stats":{"total_commits":3611,"total_committers":110,"mean_commits":32.82727272727273,"dds":"0.22182220991415125","last_synced_commit":"7bae7d9efddce8ff0718234f79f3a9200f342690"},"previous_names":[],"tags_count":79,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janet-lang%2Fjanet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janet-lang%2Fjanet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janet-lang%2Fjanet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janet-lang%2Fjanet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/janet-lang","download_url":"https://codeload.github.com/janet-lang/janet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254020606,"owners_count":22000753,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","functional-language","imperative-language","interpreter","language","lisp","macros","repl","vm"],"created_at":"2024-07-31T03:01:11.045Z","updated_at":"2025-05-13T20:09:51.895Z","avatar_url":"https://github.com/janet-lang.png","language":"C","readme":"[![Join the chat](https://img.shields.io/badge/zulip-join_chat-brightgreen.svg)](https://janet.zulipchat.com)\n\u0026nbsp;\n[![builds.sr.ht status](https://builds.sr.ht/~bakpakin/janet/commits/master/freebsd.yml.svg)](https://builds.sr.ht/~bakpakin/janet/commits/master/freebsd.yml?)\n[![builds.sr.ht status](https://builds.sr.ht/~bakpakin/janet/commits/master/openbsd.yml.svg)](https://builds.sr.ht/~bakpakin/janet/commits/master/openbsd.yml?)\n[![Actions Status](https://github.com/janet-lang/janet/actions/workflows/test.yml/badge.svg)](https://github.com/janet-lang/janet/actions/workflows/test.yml)\n\n\u003cimg src=\"https://raw.githubusercontent.com/janet-lang/janet/master/assets/janet-w200.png\" alt=\"Janet logo\" width=200 align=\"left\"\u003e\n\n**Janet** is a programming language for system scripting, expressive automation, and\nextending programs written in C or C++ with user scripting capabilities.\n\nJanet makes a good system scripting language, or a language to embed in other programs.\nIt's like Lua and GNU Guile in that regard. It has more built-in functionality and a richer core language than\nLua, but smaller than GNU Guile or Python. However, it is much easier to embed and port than Python or Guile.\n\nThere is a REPL for trying out the language, as well as the ability\nto run script files. This client program is separate from the core runtime, so\nJanet can be embedded in other programs. Try Janet in your browser at\n\u003chttps://janet-lang.org\u003e.\n\n\u003cbr\u003e\n\n## Examples\n\nSee the examples directory for all provided example programs.\n\n### Game of Life\n\n```janet\n# John Conway's Game of Life\n\n(def- window\n  (seq [x :range [-1 2]\n         y :range [-1 2]\n         :when (not (and (zero? x) (zero? y)))]\n       [x y]))\n\n(defn- neighbors\n  [[x y]]\n  (map (fn [[x1 y1]] [(+ x x1) (+ y y1)]) window))\n\n(defn tick\n  \"Get the next state in the Game Of Life.\"\n  [state]\n  (def cell-set (frequencies state))\n  (def neighbor-set (frequencies (mapcat neighbors state)))\n  (seq [coord :keys neighbor-set\n         :let [count (get neighbor-set coord)]\n         :when (or (= count 3) (and (get cell-set coord) (= count 2)))]\n      coord))\n\n(defn draw\n  \"Draw cells in the game of life from (x1, y1) to (x2, y2)\"\n  [state x1 y1 x2 y2]\n  (def cellset @{})\n  (each cell state (put cellset cell true))\n  (loop [x :range [x1 (+ 1 x2)]\n         :after (print)\n         y :range [y1 (+ 1 y2)]]\n    (file/write stdout (if (get cellset [x y]) \"X \" \". \")))\n  (print))\n\n# Print the first 20 generations of a glider\n(var *state* '[(0 0) (-1 0) (1 0) (1 1) (0 2)])\n(for i 0 20\n  (print \"generation \" i)\n  (draw *state* -7 -7 7 7)\n  (set *state* (tick *state*)))\n```\n\n### TCP Echo Server\n\n```janet\n# A simple TCP echo server using the built-in socket networking and event loop.\n\n(defn handler\n  \"Simple handler for connections.\"\n  [stream]\n  (defer (:close stream)\n    (def id (gensym))\n    (def b @\"\")\n    (print \"Connection \" id \"!\")\n    (while (:read stream 1024 b)\n      (printf \" %v -\u003e %v\" id b)\n      (:write stream b)\n      (buffer/clear b))\n    (printf \"Done %v!\" id)\n    (ev/sleep 0.5)))\n\n(net/server \"127.0.0.1\" \"8000\" handler)\n```\n\n### Windows FFI Hello, World!\n\n```janet\n# Use the FFI to popup a Windows message box - no C required\n\n(ffi/context \"user32.dll\")\n\n(ffi/defbind MessageBoxA :int\n  [w :ptr text :string cap :string typ :int])\n\n(MessageBoxA nil \"Hello, World!\" \"Test\" 0)\n```\n\n## Language Features\n\n* 600+ functions and macros in the core library\n* Built-in socket networking, threading, subprocesses, and file system functions.\n* Parsing Expression Grammars (PEG) engine as a more robust Regex alternative\n* Macros and compile-time computation\n* Per-thread event loop for efficient IO (epoll/IOCP/kqueue)\n* First-class green threads (continuations) as well as OS threads\n* Erlang-style supervision trees that integrate with the event loop\n* First-class closures\n* Garbage collection\n* Distributed as janet.c and janet.h for embedding into a larger program.\n* Python-style generators (implemented as a plain macro)\n* Mutable and immutable arrays (array/tuple)\n* Mutable and immutable hashtables (table/struct)\n* Mutable and immutable strings (buffer/string)\n* Tail recursion\n* Interface with C functions and dynamically load plugins (\"natives\").\n* Built-in C FFI for when the native bindings are too much work\n* REPL development with debugger and inspectable runtime\n\n## Documentation\n\n* For a quick tutorial, see [the introduction](https://janet-lang.org/docs/index.html) for more details.\n* For the full API for all functions in the core library, see [the core API doc](https://janet-lang.org/api/index.html).\n\nDocumentation is also available locally in the REPL.\nUse the `(doc symbol-name)` macro to get API\ndocumentation for symbols in the core library. For example,\n```\n(doc apply)\n```\nshows documentation for the `apply` function.\n\nTo get a list of all bindings in the default\nenvironment, use the `(all-bindings)` function. You\ncan also use the `(doc)` macro with no arguments if you are in the REPL\nto show bound symbols.\n\n## Source\n\nYou can get the source on [GitHub](https://github.com/janet-lang/janet) or\n[SourceHut](https://git.sr.ht/~bakpakin/janet). While the GitHub repo is the official repo,\nthe SourceHut mirror is actively maintained.\n\n## Building\n\n### macOS and Unix-like\n\nThe Makefile is non-portable and requires GNU-flavored make.\n\n```sh\ncd somewhere/my/projects/janet\nmake\nmake test\nmake repl\nmake install\nmake install-jpm-git\n```\n\nFind out more about the available make targets by running `make help`.\n\n### Alpine Linux\n\nTo build a statically-linked build of Janet, Alpine Linux + MUSL is a good combination. Janet can also\nbe built inside a docker container or similar in this manner.\n\n```sh\ndocker run -it --rm alpine /bin/ash\n$ apk add make gcc musl-dev git\n$ git clone https://github.com/janet-lang/janet.git\n$ cd janet\n$ make -j10\n$ make test\n$ make install\n```\n\n### 32-bit Haiku\n\n32-bit Haiku build instructions are the same as the UNIX-like build instructions,\nbut you need to specify an alternative compiler, such as `gcc-x86`.\n\n```sh\ncd somewhere/my/projects/janet\nmake CC=gcc-x86\nmake test\nmake repl\nmake install\nmake install-jpm-git\n```\n\n### FreeBSD\n\nFreeBSD build instructions are the same as the UNIX-like build instructions,\nbut you need `gmake` to compile. Alternatively, install the package directly with `pkg install lang/janet`.\n\n```sh\ncd somewhere/my/projects/janet\ngmake\ngmake test\ngmake repl\ngmake install\ngmake install-jpm-git\n```\n\n### NetBSD\n\nNetBSD build instructions are the same as the FreeBSD build instructions.\nAlternatively, install the package directly with `pkgin install janet`.\n\n### Windows\n\n1. Install [Visual Studio](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community\u0026rel=15#) or [Visual Studio Build Tools](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=BuildTools\u0026rel=15#).\n2. Run a Visual Studio Command Prompt (`cl.exe` and `link.exe` need to be on your PATH) and `cd` to the directory with Janet.\n3. Run `build_win` to compile Janet.\n4. Run `build_win test` to make sure everything is working.\n\nTo build an `.msi` installer executable, in addition to the above steps, you will have to:\n\n5. Install, or otherwise add to your PATH the [WiX 3.14 Toolset](https://github.com/wixtoolset/wix3/releases).\n6. Run `build_win dist`.\n\nNow you should have an `.msi`. You can run `build_win install` to install the `.msi`, or execute the file itself.\n\n### Meson\n\nJanet also has a build file for [Meson](https://mesonbuild.com/), a cross-platform build\nsystem. Although Meson has a Python dependency, Meson is a very complete build system that\nis maybe more convenient and flexible for integrating into existing pipelines.\nMeson also provides much better IDE integration than Make or batch files, as well as support\nfor cross-compilation.\n\nFor the impatient, building with Meson is as follows. The options provided to\n`meson setup` below emulate Janet's Makefile.\n\n```sh\ngit clone https://github.com/janet-lang/janet.git\ncd janet\nmeson setup build \\\n          --buildtype release \\\n          --optimization 2 \\\n          --libdir /usr/local/lib \\\n          -Dgit_hash=$(git log --pretty=format:'%h' -n 1)\nninja -C build\n\n# Run the binary\nbuild/janet\n\n# Installation\nninja -C build install\n```\n\n## Development\n\nJanet can be hacked on with pretty much any environment you like, but for IDE\nlovers, [Gnome Builder](https://wiki.gnome.org/Apps/Builder) is probably the\nbest option, as it has excellent Meson integration. It also offers code completion\nfor Janet's C API right out of the box, which is very useful for exploring. VSCode, Vim,\nEmacs, and Atom each have syntax packages for the Janet language, though.\n\n## Installation\n\nIf you just want to try out the language, you don't need to install anything.\nIn this case you can also move the `janet` executable wherever you want on\nyour system and run it.  However, for a fuller setup, please see the\n[Introduction](https://janet-lang.org/docs/index.html) for more details.\n\n## Usage\n\nA REPL is launched when the binary is invoked with no arguments. Pass the `-h` flag\nto display the usage information. Individual scripts can be run with `./janet myscript.janet`.\n\nIf you are looking to explore, you can print a list of all available macros, functions, and constants\nby entering the command `(all-bindings)` into the REPL.\n\n```\n$ janet\nJanet 1.7.1-dev-951e10f  Copyright (C) 2017-2020 Calvin Rose\njanet:1:\u003e (+ 1 2 3)\n6\njanet:2:\u003e (print \"Hello, World!\")\nHello, World!\nnil\njanet:3:\u003e (os/exit)\n$ janet -h\nusage: janet [options] script args...\nOptions are:\n  -h : Show this help\n  -v : Print the version string\n  -s : Use raw stdin instead of getline like functionality\n  -e code : Execute a string of janet\n  -E code arguments... : Evaluate an expression as a short-fn with arguments\n  -d : Set the debug flag in the REPL\n  -r : Enter the REPL after running all scripts\n  -R : Disables loading profile.janet when JANET_PROFILE is present\n  -p : Keep on executing if there is a top-level error (persistent)\n  -q : Hide logo (quiet)\n  -k : Compile scripts but do not execute (flycheck)\n  -m syspath : Set system path for loading global modules\n  -c source output : Compile janet source code into an image\n  -i : Load the script argument as an image file instead of source code\n  -n : Disable ANSI color output in the REPL\n  -l lib : Use a module before processing more arguments\n  -w level : Set the lint warning level - default is \"normal\"\n  -x level : Set the lint error level - default is \"none\"\n  -- : Stop handling options\n```\n\nIf installed, you can also run `man janet` to get usage information.\n\n## Embedding\n\nJanet can be embedded in a host program very easily. The normal build\nwill create a file `build/janet.c`, which is a single C file\nthat contains all the source to Janet. This file, along with\n`src/include/janet.h` and `src/conf/janetconf.h`, can be dragged into any C\nproject and compiled into it. Janet should be compiled with `-std=c99`\non most compilers, and will need to be linked to the math library, `-lm`, and\nthe dynamic linker, `-ldl`, if one wants to be able to load dynamic modules. If\nthere is no need for dynamic modules, add the define\n`-DJANET_NO_DYNAMIC_MODULES` to the compiler options.\n\nSee the [Embedding Section](https://janet-lang.org/capi/embedding.html) on the website for more information.\n\n## Discussion\n\nFeel free to ask questions and join the discussion on the [Janet Zulip Instance](https://janet.zulipchat.com/)\n\n## FAQ\n\n### How fast is it?\n\nIt is about the same speed as most interpreted languages without a JIT compiler. Tight, critical\nloops should probably be written in C or C++ . Programs tend to be a bit faster than\nthey would be in a language like Python due to the discouragement of slow Object-Oriented abstraction\nwith lots of hash-table lookups, and making late-binding explicit. All values are boxed in an 8-byte\nrepresentation by default and allocated on the heap, with the exception of numbers, nils and booleans. The\nPEG engine is a specialized interpreter that can efficiently process string and buffer data.\n\nThe GC is simple and stop-the-world, but GC knobs are exposed in the core library and separate threads\nhave isolated heaps and garbage collectors. Data that is shared between threads is reference counted.\n\nYMMV.\n\n### Where is (favorite feature from other language)?\n\nIt may exist, it may not. If you want to propose a major language feature, go ahead and open an issue, but\nit will likely be closed as \"will not implement\". Often, such features make one usecase simpler at the expense\nof 5 others by making the language more complicated.\n\n### Is there a language spec?\n\nThere is not currently a spec besides the documentation at \u003chttps://janet-lang.org\u003e.\n\n### Is this Scheme/Common Lisp? Where are the cons cells?\n\nNope. There are no cons cells here.\n\n### Is this a Clojure port?\n\nNo. It's similar to Clojure superficially because I like Lisps and I like the aesthetics.\nInternally, Janet is not at all like Clojure, Scheme, or Common Lisp.\n\n### Are the immutable data structures (tuples and structs) implemented as hash tries?\n\nNo. They are immutable arrays and hash tables. Don't try and use them like Clojure's vectors\nand maps, instead they work well as table keys or other identifiers.\n\n### Can I do object-oriented programming with Janet?\n\nTo some extent, yes. However, it is not the recommended method of abstraction, and performance may suffer.\nThat said, tables can be used to make mutable objects with inheritance and polymorphism, where object\nmethods are implemented with keywords.\n\n```clj\n(def Car @{:honk (fn [self msg] (print \"car \" self \" goes \" msg)) })\n(def my-car (table/setproto @{} Car))\n(:honk my-car \"Beep!\")\n```\n\n### Why can't we add (feature from Clojure) into the core?\n\nUsually, one of a few reasons:\n- Often, it already exists in a different form and the Clojure port would be redundant.\n- Clojure programs often generate a lot of garbage and rely on the JVM to clean it up.\n  Janet does not run on the JVM and has a more primitive garbage collector.\n- We want to keep the Janet core small. With Lisps, a feature can usually be added as a library\n  without feeling \"bolted on\", especially when compared to ALGOL-like languages. Adding features\n  to the core also makes it a bit more difficult to keep Janet maximally portable.\n\n### Can I bind to Rust/Zig/Go/Java/Nim/C++/D/Pascal/Fortran/Odin/Jai/(Some new \"Systems\" Programming Language)?\n\nProbably, if that language has a good interface with C. But the programmer may need to do\nsome extra work to map Janet's internal memory model to that of the bound language. Janet\nalso uses `setjmp`/`longjmp` for non-local returns internally. This\napproach is out of favor with many programmers now and doesn't always play well with other languages\nthat have exceptions or stack-unwinding.\n\n### Why is my terminal spitting out junk when I run the REPL?\n\nMake sure your terminal supports ANSI escape codes. Most modern terminals will\nsupport these, but some older terminals, Windows consoles, or embedded terminals\nwill not. If your terminal does not support ANSI escape codes, run the REPL with\nthe `-n` flag, which disables color output. You can also try the `-s` flag if further issues\nensue.\n\n## Why is it called \"Janet\"?\n\nJanet is named after the almost omniscient and friendly artificial being in [The Good Place](https://en.wikipedia.org/wiki/The_Good_Place).\n","funding_links":[],"categories":["C","Uncategorized","By Language","Lisp","Clojure-likes"],"sub_categories":["Uncategorized","C","Other dialects and variants","[Janet](https://janet-lang.org/)"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanet-lang%2Fjanet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjanet-lang%2Fjanet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanet-lang%2Fjanet/lists"}