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

(peg/match ~{:main (capture (some :S))}
           "hello world")
# => @["hello"]
peg/matchsogaiuPlayground
(tuple 1 2.3 :a "foo" true nil [] {} (fn []))
# =>  (1 2.3 :a "foo" true nil () {} <function 0x7FB2A3D030B0>)
tuplecellularmitosisPlayground
(var buf @"")
(buffer/push-word buf 2147483647)

(+
  (get buf 0)                # byte 1
  (blshift (get buf 1) 8)    # byte 2
  (blshift (get buf 2) 16)   # byte 3
  (blshift (get buf 3) 24))  # byte 4

# => 2147483647
buffer/push-wordleobmPlayground
(let [len 8
      rand-string (string/join (map |(string/format "%02x" $)
                                    (os/cryptorand len)))]
  (= (length rand-string) (* 2 len)))
# => true
os/cryptorandsogaiuPlayground
(seq [i :range [0 10] :when (odd? i)] (math/pow 2 i))

# => @[2 8 32 128 512]
# array with 2 to the power of all odd numbers smaller than 10
seqpepePlayground
(if-let [x true 
         y (not x)]
  :a
  :b)
# => :b
if-letsogaiuPlayground
(as?-> [1 2 3] _ 
  (sum _)
  (when (> 6 _) _))
# => nil

(as?-> [1 2 3] _ 
  (sum _)
  (when (>= 6 _) _))

# => 6
as?->leobmPlayground
(seq [i :range [0 3]
      j :range [0 3]
      :let [c (string/format "%c" (+ 97 i))]
      :when (and (even? i) (even? j))]
  [(keyword c) j])
# => '@[(:a 0) (:a 2) (:c 0) (:c 2)]
seqsogaiuPlayground
(mean [1 10 100])  # => 37
(mean [])          # => nan
meancellularmitosisPlayground
(reduce     + 1 [2 3 4])  # -> 10
(accumulate + 1 [2 3 4])  # -> @[3 6 10]
accumulatecellularmitosisPlayground
(math/random)  # 0.487181
math/randombtbytesPlayground
(os/mkdir "templates")
# => creates ./templates directory
os/mkdirpepePlayground
(buffer/format @"0 - 1 = " "%d" -1)
# =>
@"0 - 1 = -1"
buffer/formatsogaiuPlayground
(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
(map string/from-bytes "Hello, world!")  # => @["H" "e" "l" "l" "o" "," " " "w" "o" "r" "l" "d" "!"]
mapGrayJackPlayground