on
Janet
After a long time (almost a year!) I am writing again. It took me some time to get fully installed in Hong Kong (I moved from Belgium to Hong Kong on July 18).
I enjoyed 3 months of “holiday” there while looking for a job and now I am fully installed !
Anyway, this (very short) post is about a nice language I discovered few months ago named Janet (yes like in The Good Place).
The language looks like this:
(defn main [& args]
(unless (= (length args) 4)
((eprintf "usage: %s [ip] [port] [hash file]" (args 0))
(os/exit 1)))
(def [ip port file] [(get args 1) (scan-number (get args 2)) (get args 3)])
(printf "Initialise db with %s" file)
(db-helper/initdb file)
(def server (net/listen ip port :datagram))
(printf "Listening on %s:%d" ip port)
(while true
(var buffer @"")
(def client (net/recv-from server 1024 buffer))
(match (peg/match peg-helper/hash-grammar (string/trim buffer))
["GET"] (send-hash server client)
["POST" hash password] (recv-hash server client hash password)
_ (printf "got garbage from a client: %q" buffer))))
What I like about Janet is its very similar to Lua but with a larger stdlib.
I also really like the package/binary manager called jpm, I find the syntax really easy to understand, for example for the project janbreak5 that I made with a friend, here is how the project.janet
looks like
(declare-project
:name "janbreak5"
:description ```simple md5 breaker client/server in Janet/C```
:dependencies ["https://github.com/joy-framework/db"
"https://github.com/janet-lang/sqlite3"])
(declare-executable
:name "server"
:entry "server/server.janet"
:lflags ["-lcrypto"])
(declare-native
:name "md5"
:source ["md5/md5.c"]
:ldflags ["-lcrypto"])
The project mixes C
(md5 library) and Janet
(server/client binaries).
Janet is mostly implemented in C99
, it is very easy to cross compile Janet
for different OS or Architecture.
There is a very nice book available for free online which will do a much better job than me at convincing you to try Janet, Janet for Mortals, the “book” is even interactive so you can try some Janet without installing it while reading !