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

(flatten-into @[1 2 3] @[[4 5 6] @[7 8 9] @[10 11 12]]) # => @[1 2 3 4 5 6 7 8 9 10 11 12]
flatten-intojgartePlayground
(math/exp2 8)  # => 256
math/exp2cellularmitosisPlayground
(type print)
# =>
:cfunction
typesogaiuPlayground
(math/hypot 1 1)  # => 1.41421
(math/sqrt 2)     # => 1.41421
math/hypotcellularmitosisPlayground
(put  @{:a 4 :b 5}  :c 6         )  # => @{:a 4 :b 5 :c 6}
(put  @{:a 4 :b 5}  :b nil       )  # => @{:a 4}
(put  @{:a 4 :b 5}  :z nil       )  # => @{:a 4 :b 5}

(put  @[:a :b :c]   0  :z        )  # => @[:z :b :c]
(put  @[:a :b :c]   1  nil       )  # => @[:a nil :c]

(put  @[:a :b :c]   5  :d        )  # => @[:a :b :c nil nil :d]

(put  @"hello"      0  "z"       )  # error: can only put integers in buffers
(defn ord [ch] (first (string/bytes ch)))
(ord "z")  # => 122
(put  @"hello"      0  122       )  # => @"zello"
(put  @"hello"      0  (ord "z") )  # => @"zello"
(put  @"hello"      8  (ord "y") )  # => @"hello\0\0\0y"
putcellularmitosisPlayground
(assertf true "this sentence is %n" false)
# => true
assertfsogaiuPlayground
(get default-peg-grammar :a)
# => '(range "az" "AZ")
default-peg-grammarsogaiuPlayground
(update @{:a 1} :a inc)
# => @{:a 2}
updatesogaiuPlayground
(bxor 2r011 2r110)
# => 5
bxorsogaiuPlayground
(let [len 8
      rand-string (string/join (map |(string/format "%02x" $)
                                    (os/cryptorand len)))]
  (= (length rand-string) (* 2 len)))
# => true
os/cryptorandsogaiuPlayground
(drop-while |(> 3 $) [0 1 2 3 4 5 6 7 8 ])
# => (3 4 5 6 7 8)
drop-whileleobmPlayground
(defn f1 [s] (string "-" s "-"))
(defn f2 [s] (string "=" s "="))
(defn f3 [s] (string "#" s "#"))

(def f (juxt f1 f2 f3))

(f "x") # => ("-x-" "=x=" "#x#")
juxtuvtcPlayground
(let [a 1]
 (let [b a]
  b)) # => 1
letjgartePlayground
 new Math.seedrandom('hello.');
math/seedrandomMonif2009Playground
(defn square [x] (* x x))
(defn square-then-dec [x] ((comp dec square) x))
(defn dec-then-square [x] ((comp square dec) x))
(square-then-dec 3)  # => 8
(dec-then-square 3)  # => 4
compcellularmitosisPlayground