# Janet

- Page: https://shared.btbytes.com/p/janet
- Date: 2020-01-17
- Tags: clojure, lisp, programming-language

[Janet Programming Language](https://janet-lang.org/) is a Clojure
like Lisp scripting language also suitable for embedding.

## Why

[Why Janet?](https://ianthehenry.com/posts/why-janet/); Apr 2023. Book "[Janet for Mortals](https://janet.guide/)" by Ian Henry.


## Learn

- [Janet for Mortals](https://janet.guide/)
- [Janet Feature Demos](https://github.com/sogaiu/janet-features-demos)

## 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](https://janet-lang.org/docs/jpm.html))

```clojure
(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](https://github.com/bakpakin/littleserver) on how
  to build an **executable** from Janet source.

## Cool projects in Janet

* [Bauble studio](https://bauble.studio/) -- making art online with lisp(janet) and math.
* [Mendoza](https://bakpakin.github.io/mendoza/index.html) -- static
  website generator with a markdown language inspired by Scribble (of
  racket).

* [Tester](https://github.com/joy-framework/tester) -- testing
  framework. Readme file has an example of how to use
  [fswatch](https://github.com/emcrisostomo/fswatch) to run the tests
  when files change.
* [Joy Framework](https://joyframework.com/) -- a web framework for
  Janet.
  * `jpm install joy`.
  * has an ORM?
* [esv](https://github.com/staab/esv) a web application built using
  Janet, (and circlet library).



## Janet Shell

[janetsh](https://janet-shell.org/) "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](https://acha.ninja/blog/powerful-scripting-with-janetsh/) by
the creator -- Andrew Chambers.

In this article, -- [JSON in Janet
Shell](https://acha.ninja/blog/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.

```bash
# 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).
