Janet

a Clojure like lisp that is also suitable for embedding

Created: by Pradeep Gowda Updated: Apr 13, 2023 Tagged: programming-language · lisp · clojure

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

Why

Why Janet?; Apr 2023. Book “Janet for Mortals” by Ian Henry.

Learn

Notes

  • Project definitions go into a project.janet file.
  • Third party dependencies are defined like this: {:dependencies [{:repo "https://github.com/joy-framework/moondown" :tag "0.1.0"}]}

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"])
  • See littleserver on how to build an executable from Janet source.

Cool projects in Janet

  • Bauble studio – making art online with lisp(janet) and math.

  • Mendoza – static website generator with a markdown language inspired by Scribble (of racket).

  • Tester – testing framework. Readme file has an example of how to use fswatch to run the tests when files change.

  • Joy Framework – a web framework for Janet.

    • jpm install joy.
    • has an ORM?
  • esv a web application built using Janet, (and circlet library).

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