# A guided tour of Janet (a Lisp) running on calog. # Demonstrates: def/fn, a first-class function passed to map, an array and a table, then the # json + cryptoHashSha256 natives. Janet integers are doubles (exact to 2^53). Exports from other # scripts are reached with (calogCall "name" ...) -- Janet has no bare-name resolution hook. # run: bin/calog examples/scripts/languages/janet.janet (def nums [1 2 3 4 5]) (def total (reduce + 0 nums)) (def doubled (string/join (map (fn [x] (string (* x 2))) nums) " ")) (print "nums total = " total ", doubled = " doubled) (def user @{"name" "ada" "age" 36}) (print "user as JSON: " (jsonStringify user)) (def parsed (jsonParse `{"lang":"janet","ints":[10,20,30]}`)) (print "parsed lang = " (get parsed "lang") ", second int = " (get (get parsed "ints") 1)) (print "sha256(calog) = " (cryptoHashSha256 "calog")) (calogExit 0)