Janet is a functional programming language that resembles a lisp, or clojure, but is noticeably missing lists. It is small, relatively quick, and easy to embed within other projects.
Janet is well documented, but it took me a long while to grok how to structure a project for compilation. Here's a basic example.
A "project" in Janet consists of a few pieces. First is the
project.janet file, used to describe the project and its dependencies. This is the file that Janet's
(declare-project :name "giblang" :description "giberish generator") (declare-source :source ["giblang.janet"]) (declare-executable :name "giblang" :entry "main.janet")
This project file describes a 2 file project with no dependencies. Dependencies would be included within the
Next is the project's source code – for that see giblang.
Last but not least is the
main.janet – whilst this file is totally optional, I like this model, using
main.janet as the entry point for the application.
(import giblang) (defn main [& args] (var user-input-number (scan-number (in args 1))) # scan-number is used here to cast the user input form a string to a number. (giblang/speak user-input-number))
main function here is akin to the main function in C or golang. All it is doing is parsing arguments passed into the program and passing them to the rest of the project, here,
With those 3 pieces in place I'm able to run
jpm build from within the project directory to automatically build an executable!