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

(sort (keys default-peg-grammar))
# => @[:A :D :H :S :W :a :a* :a+ :d :d* :d+ :h :h* :h+ :s :s* :s+ :w :w* :w+]
default-peg-grammarsogaiuPlayground
(= (brushift 2r1000 1 1 1) 2r0001)
# => true
brushiftsogaiuPlayground
# with by function 

(sorted [1 -2 2 3 9 -10] >)  #@[9 3 2 1 -2 -10]
sortedleobmPlayground
(scan-number "1_000_000")
# => 1000000
scan-numbersogaiuPlayground
(invert [:ant :bee :elephant :fox :penguin])
# => @{:bee 1 :fox 3 :elephant 2 :ant 0 :penguin 4}
invertsogaiuPlayground
(inc 42)  # => 43
(map inc [1 2 3])  # => @[2 3 4]
inccellularmitosisPlayground
(tuple 1 2.3 :a "foo" true nil [] {} (fn []))
# =>  (1 2.3 :a "foo" true nil () {} <function 0x7FB2A3D030B0>)
tuplecellularmitosisPlayground
(varglobal "smile" false)
# => nil

smile
# => false

(set smile true)
# => smile

smile
# => true

(dyn 'smile)
# => @{:ref @[true]}
varglobalsogaiuPlayground
(update-in @{:a 1} [:a] (fn [x] (+ 1 x)))
# @{:a 2}
update-insbjaverPlayground
(->> "X"
     (string "a" "b")
     (string "c" "d")
     (string "e" "f"))  # => "efcdabX"
->>uvtcPlayground
(buffer/bit-set @"hahaha" 3) # => @"hahaha"

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

buffer/bit-setjgartePlayground
(defn get-time-str []
  (let [{:hours h :minutes m :seconds s} (os/date)]
    (string h ":" m ":" s)))

(get-time-str) => "23:18:16"
os/datetupini07Playground
(def kvpairs [[:x 1] [:y 2]])

(table ;(flatten kvpairs)) # => @{:x 1 :y 2}
flattenyumaikasPlayground
(defn knorkulate [a b]
  (tracev (+ a (* b b ))))
# <function knorkulate>

(knorkulate 2 34)
# trace on line 2, column 1: (+ a (* b b)) is 1158
# 1158
tracevkamisoriPlayground
# Map over multiple structures -- Stops after the shortest is exhausted.
(map (fn [& args] ;args) [1] [1 2] [1 2 3])

# => @[(1 1 1)]
mapGrazfatherPlayground