- https://acha.ninja/blog/dsl_for_shell_scripting/ + 200 loc library for janet-sh
- https://ianthehenry.com/posts/ 7 about making a game
- https://janetdocs.org/ has many examples
- https://github.com/sogaiu/janet-features-demos
- most discussion on zulip
- the spork module holds most batteries like JSON
- toodle has an in browser graphics sandbox and tutorial
- janetdocs have community examples of every function
- but maintainer disappeared, so I should clone it
There are many accessors:
- associative structures like
(def m @{:k "val"})(get m :k)(in m :k)- n.b. it does not throw errors with tables & structs(m :k)
- indexed structures like
(def a [:a :b :c])(get a 0)(in a 0)- throws error on failure(a 0)(0 a)
getin
Pending Questions
- what does
math/nextdo?math/next 1 math/inf)just returns 1 - why do
productandsumexist?(product [1 2 3])is the same as(* ;[1 2 3]). People suggested using them in these cases:- You could write
(sum x)and(product x)instead of(reduce + 0 x)and(reduce * 1 x) (map (fn [[a b]] (* a b)))->(map product)- prefer
(sum (seq [[game-id rounds] :pairs data :when (all true? ...)] game-id))although slower, over:
- You could write
(loop [[game-id rounds] :pairs data]
(when (all true? ...)
(set total (+ total game-id)))
total)
Solved Questions and Insights
import- https://github.com/janet-lang/pkgs/blob/master/pkgs.janet is the list of “core” imports without git links required
jpm installseemms to only move the source without package name soimportonly works through your entry file’s name. Thus you should name the main how you want the import API to be. Package name from project.janet seems to just be for jpm itself. To be clearer, in package blabla with source my-file.janet you(import my-file)which should have imports to the other files in the project
- In the repl
(defn main [& args] (+ ;args))then(spit "test.janet" (make-image (curenv)))does not produce an image you can run withjanet -i test.janetwhy not?could not find method :+(defn main [waste & args] (print (reduce + 0 (map |(int/to-number (int/u64 $)) args))))- Both are possible:
(reduce + 0 (map |(int/to-number (int/u64 $)) args))or(reduce + 0 (map int/to-number (map int/u64 args))) - note that the first element passed is the filename janet is runniing, so you need to ignore that arg!
- use
(compose int/u64 int/to-number) scan-number
- how to create nested tables?
put-in- wrong solution:
merge-intois destructive -(defn insert-verse (abbrev ch verse quote) (merge-into verses @{abbrev @{ch @{verse quote}}})) - made my own
assoc-inhere
(defn assoc-in [m ks v]
``Insert (and make) deeply nested tables, based on Clojure's.
Use like: (var t (table)) (assoc-in t [:a :b :c :d] "e")``
(if (empty? ks)
v
(let [k (first ks)
nested (or (get m k) @{})]
(put m k (assoc-in nested (slice ks 1) v)))))
- how do you make
condnot print nil? - accepting cmd lin args via main into
condwith(or (= 0 (length args)) (= "-h" args) (= "help" args))to output help, why don’t they trigger?- args are a list, so use
;like;args
- args are a list, so use
- how do you use
ifineachorloopon a map, when it outputs nil at the end?(each a {:a 1 :b 2 :c 3} (if (= 1 a) "yes" "no"))(find |(string/has-prefix? "a" $) ["be" "cat" "art"])
- How does image based development work?
(load-image (slurp "test.jimage"))shows the image, but doesn’t bind the symbols etc.eval,repl,require,(run-context :read (slurp "test.jimage"))…(fiber/setenv (fiber/current) (load-image (slurp "test.jimage")))is also a no.
(defn restore-image [image]
(loop [[k v] :pairs source]
(put (curenv) k v)))
(restore-image (load-image (slurp "test.jimage")))
why does
[1 2 3]output(1 2 3)? Are the tuple docs wrong?- It seems like the docs are wrong, but it doesn’t matter.
- “The whole notion of tuple types seems a bit strange and it was just so we could have a little bit more syntactic variety and tuple constructor literals. Outside of things like the compilers and pretty printing, tuples of either type are considered equal. A bracket tuple will construct a parenthesized tuple, which should be considered the default.” - Bakpakin
condvs.case?- use
caseif the important value is like an enum (particular thing, state)otherwisecond`.
- use
whenorif?- prefer
when
- prefer
Libraries
sqlite3 Sqlite bindings
janet-pq Postgres bindings
janet-pobox - Clojure like atoms for concurrency
https://git.sr.ht/~pepe/kamilah - occasionally marshals a table to disc, for data storage, easy
web
- spork http adds functionality to the std lib’s http (circlet hasn’t been updated in some time)
- no https support
- https://bagatto.co/ ssg
- https://github.com/swlkr/janet-html hiccup html
- https://bakpakin.github.io/mendoza/ ssg
- https://github.com/CosmicToast/jurl like curl for gets etc.
- https://git.sr.ht/~pepe/chidi - api style sever
- https://github.com/pyrmont/churlish
- https://github.com/yumaikas/cartnet
- https://github.com/zevv/janetttls
- https://github.com/CFiggers/janet-libcurl
- https://github.com/pyrmont/ecstatic ssg
- https://github.com/swlkr/speakeasy ssg
- https://github.com/swlkr/stripe-janet
- https://github.com/pyrmont/markable - markdown parsing
- https://github.com/swlkr/sqlheavy for crud
- https://www.youtube.com/@swlkr_/search?query=janet many videos!
- swlkr: https://swlkr.com/posts
- Joy was hiss first framework, then trout which has less features (no DB, middleware) but less typing!
- https://github.com/swlkr/askjanet Q & A website explained here: https://swlkr.com/posts/ask-janet
- https://github.com/joy-framework/joy
- joy has db and sql, http, password crypto, markdown, halo2 http server
- docs: https://joy.swlkr.com/index.html
- docs: https://github.com/joy-framework/joy/blob/master/docs/introduction.md
- many of his videos are about developing it
- https://swlkr.com/posts/joy-routes-as-functions/
- “rapid development. What is the least amount of keystrokes I can make to get something up and running?”
- manifesto: https://swlkr.com/posts/joys-manifesto/
- https://github.com/swlkr/osprey
- “single file websites are the holy grail”
- “sqlite is enough”
- Routes Actions Data not MVC https://swlkr.com/posts/rad/
- spork http adds functionality to the std lib’s http (circlet hasn’t been updated in some time)
data
- https://github.com/pyrmont/medea - json
- https://git.sr.ht/~pepe/manisha
- spork has “data”
testing
- https://github.com/sogaiu/janet-ex-as-tests
- https://github.com/sogaiu/janet-minipbt-translation - property-based / generative
- https://github.com/ianthehenry/judge - snapshots
- https://github.com/pyrmont/testament - based on
clojure.test - https://github.com/ianthehenry/banquet - can visualize tables nicely for snapshots
TUI
- https://github.com/CFiggers/cmd - parse cmdlin args
- https://github.com/pyrmont/argy-bargy arg parsing
- https://git.sr.ht/~lucasemmoreira/janet-ncurses
- https://github.com/Alligator/jtermbox
- https://github.com/sepisoad/jtbox
- https://git.sr.ht/~nullevoid/jermbox
- https://git.sr.ht/~pepe/gp/tree/master/item/cjanet/term.janet
- https://git.sr.ht/~pepe/gp/tree/master/item/gp/tui.janet
graphics/frontend
- gui https://www.reddit.com/r/janetlang/comments/q3zxzf/janetui_false_start/
- jaylib
- janetui Bindings to libui
- jermbox Bindings to Termbox
- webview Electron-like webview bindings.
comp sci
- OOP https://fugue.soy/
- interesting documentation system https://pantagruel-language.com/
- persistent DS https://github.com/ianthehenry/jimmy