Janet Programming Language

Updated: Jan 17, 2020 by Pradeep Gowda.

Janet Programming Language is a Clojure like Lisp scripting language also suitable for embedding.

The structure of a project.janet file is: (See more here)

(declare-project
  :name "mylib" # required
  :description "a library that does things" # some example metadata.

  # Optional urls to git repositories that contain required artifacts.
  :dependencies ["https://github.com/janet-lang.json.git"])

Cool projects in Janet

Janet Shell

janetsh “A powerful new shell that uses the janet programming language for both the implementation and repl.”. This is pretty cool when you want a regular shell that can do mundane things like ls -lart, but also use janet as a REPL and scripting language when you want to more advaned things without resolving to bash scripting. See this introductory article by the creator – Andrew Chambers.

In this article, – JSON in Janet Shell you can see how to use the ~/.janetsh.rc file to load additional modules (in this case ability to process JSON) to extend the capability of janetsh.

# Tell janet it can load janet and native modules from ~/janet-modules
(array/insert module/paths 0 
   [(string (os/getenv "HOME") "/janet-modules/:all:.janet") :source]
   [(string (os/getenv "HOME") "/janet-modules/:all:.:native:") :native])
   
# copy combined dynamic library to janet-modules dir
cp build/json.so ~/janetsh-modules

# use it
$ (import json)
$ (var astronaut-in-space
    (json/decode ($$ curl http://api.open-notify.org/astros.json)))
# note: $$ appears to be the function call to invoke programs

# Print each one and the space craft they are in.
$ (each astronaut (astronauts-in-space "people")
    (print
      "Name: " (astronaut "name") 
      ", Craft: " (astronaut "craft")))
...
Name: Oleg Kononenko, Craft: ISS
Name: David Saint-Jacques, Craft: ISS
Name: Anne McClain, Craft: ISS

This is a very nice capability (being able to extend the shell programming language).