[go: up one dir, main page]
More Web Proxy on the site http://driver.im/

Janet Language

Janet is a functional and imperative programming language. It runs on Windows, Linux, macOS, BSDs, and should run on other systems with some porting. The entire language (core library, interpreter, compiler, assembler, PEG) is less than 1MB. You can also add Janet scripting to an application by embedding a single C source file and a single header.

Use Cases

Janet makes a good system scripting language, or a language to embed in other programs. Janet also can be used for rapid prototyping, dynamic systems, and other domains where dynamic languages shine. Implemented mostly in standard C99, Janet runs on Windows, Linux and macOS. The few features that are not standard C (dynamic library loading, compiler specific optimizations), are fairly straightforward. Janet can be easily ported to new platforms. While Janet is embeddable, it comes with a bit more out of the box than many other such easily embeddable languages such as threading, networking, an event loop, subprocess handling, regex-like library called PEG, and more.

Features

Code Example

(defn sum3
  "Solve the 3SUM problem in O(n^2) time."
  [s]
  (def tab @{})
  (def solutions @{})
  (def len (length s))
  (for k 0 len
    (put tab (s k) k))
  (for i 0 len
    (for j 0 len
      (def k (get tab (- 0 (s i) (s j))))
      (when (and k (not= k i) (not= k j) (not= i j))
        (put solutions {i true j true k true} true))))
  (map keys (keys solutions)))

(let [arr @[2 4 1 3 8 7 -3 -1 12 -5 -8]]
  (printf "3sum of %j: " arr)
  (printf "%j" (sum3 arr)))

Try It

>
(print "hello, world!")

Usage

A REPL is launched when the janet binary is invoked with no arguments. Pass the -h flag to display the usage information. Individual scripts can be run with janet myscript.janet

If you are looking to explore, you can print a list of all available macros, functions, and constants by entering the command all-bindings into the REPL.

$ janet
Janet 1.17.0-local linux/x64 - '(doc)' for help
repl:1:> (+ 1 2 3)
6
repl:2:> (print "Hello, World!")
Hello, World!
nil
repl:3:> (os/exit)
$ janet -h
usage: janet [options] script args...
Options are:
  -h : Show this help
  -v : Print the version string
  -s : Use raw stdin instead of getline like functionality
  -e code : Execute a string of janet
  -E code arguments... : Evaluate  an expression as a short-fn with arguments
  -d : Set the debug flag in the REPL
  -r : Enter the REPL after running all scripts
  -R : Disables loading profile.janet when JANET_PROFILE is present
  -p : Keep on executing if there is a top-level error (persistent)
  -q : Hide logo (quiet)
  -k : Compile scripts but do not execute (flycheck)
  -m syspath : Set system path for loading global modules
  -c source output : Compile janet source code into an image
  -n : Disable ANSI color output in the REPL
  -l lib : Import a module before processing more arguments
  -w level : Set the lint warning level - default is "normal"
  -x level : Set the lint error level - default is "none"
  -- : Stop handling options

Modules and Libraries

See some auxiliary projects on GitHub. Here is a short list of libraries for Janet to help you get started with some interesting stuff. See the Janet Package Listing for a more complete list. Packages in the listing can be installed via jpm install pkg-name.

Editor Support

Janet support exists for a number of editors. See the links below for some editor-specific details. The Zulip Instance also has an editors and tooling discussion area.

Community

NEW!

Check out the Janet Zulip Instance at https://janet.zulipchat.com (Invite Link)

Forum

We also support GitHub Discussions, but Zulip has richer functionality.

Janet Docs

For help, you can also check out Janet Docs for Janet documentation with user-provided examples. Feel free to contribute your own examples here to help fellow programmers.