JanetDocsSourcePlaygroundTutorialsI'm Feeling luckyCommunityGitHub sign in

Community documentation for Janet

Supported Modules

Welcome, I'm happy to see you here! Feel free to pick a function and add a happy example, the more the merrier!

Loading...

Random Examples

(os/time)  # => 1593838384
(os/date)  # => {:month 6 :dst false :year-day 185 :seconds 8 :minutes 53 :week-day 6 :year 2020 :hours 4 :month-day 3}
(os/mktime (os/date))  # => 1593838390
os/mktimecellularmitosisPlayground
(filter (fn [x] (> x 2)) [1 2 3 4 5])  # @[3 4 5]
filterbtbytesPlayground
(last "hello")
# => 111
lastsogaiuPlayground
(let [c0 (ev/chan)
      c1 (ev/chan 1)]
  [(ev/capacity c0) (ev/capacity c1)])
# => '(0 1)
ev/capacitysogaiuPlayground
$ janet -e '(os/exit 42)' ; echo $?
42
os/exitcellularmitosisPlayground
(buffer/bit-set @"hahaha" 3) # => @"hahaha"

(buffer/bit-set @"what" 3) # => @"\x7Fhat"

buffer/bit-setjgartePlayground
(interpose 0 [1])
# -> @[1]
interposeKrasjetPlayground
(scan-number "1_000_000")
# => 1000000
scan-numbersogaiuPlayground
# read input at compile-time and create a custom func to check whether a number is in one of the
# given ranges. This turned out to be almost 4x faster than writing it as a func
# from https://abhinavsarkar.net/notes/2025-aoc-1/#day-2

(defmacro in-range? [n & _]
  (def ranges (parse-input (slurp input-path)))
  ~(or ,;(map (fn [[s e]] ~(<= ,s ,n ,e)) ranges)))
defmacroveqqqPlayground
(extreme < [1 2 3])  # => 1
(extreme > [1 2 3])  # => 3
extremecellularmitosisPlayground
(map string/from-bytes "Hello, world!")  # => @["H" "e" "l" "l" "o" "," " " "w" "o" "r" "l" "d" "!"]
mapGrayJackPlayground
(print math/int-min)
-9007199254740992
nil
math/int-minbtbytesPlayground
(first [])  # => nil
(first "abc")  # => 97
firstAndriamanitraPlayground
(ev/call print 10)
(ev/sleep 0.0001) # give ev a chance in the REPL, remove in file
# => prints 10
ev/callpepePlayground
(type print)
# =>
:cfunction
typesogaiuPlayground