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

(one? 1)  # => true
(map one? [0 1 2])  # => @[false true false]

(one? (math/next 1 math/inf))  # => false
one?cellularmitosisPlayground
(trace +)
# <function +>

((trace +) 5 3)
# trace (+ 5 3)
# 8

(defn knorkulate [a b]
  ((trace +) a ((trace *) b b )))
# <function knorkulate>

(knorkulate 2 34)
# trace (* 34 34)
# trace (+ 2 1156)
# 1158
tracekamisoriPlayground
(->> "X"
     (string "a" "b")
     (string "c" "d")
     (string "e" "f"))  # => "efcdabX"
->>uvtcPlayground
$ janet -e '(os/exit 42)' ; echo $?
42
os/exitcellularmitosisPlayground
(map dictionary? [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false false  false  false    false     true         true          ]

(map struct?     [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false false  false  false    false     true         false         ]

(map table?      [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false false  false  false    false     false        true          ]
table?cellularmitosisPlayground
(def h ["a" "b" :c]) # => ("a" "b" :c)

(find (fn [a] (= "a" a)) h) # => "a"
findfaywongPlayground
(map type [nil true 42 [] @[] {} @{} "a" @"b" 'c :d identity (fn [])])
# => @[:nil :boolean :number :tuple :array :struct :table :string :buffer :symbol :keyword :function :function]
typecellularmitosisPlayground
(<)        # -> true
(< 1)      # -> true
(< 1 2)    # -> true
(< 2 1)    # -> false
(< 1 2 3)  # -> true
(< 1 3 2)  # -> false
<cellularmitosisPlayground
(def a @[1 2])
(array/pop a)  # => 2
a              # => @[1]
(array/pop a)  # => 1
a              # => @[]
(array/pop a)  # => nil
a              # => @[]
array/popcellularmitosisPlayground
(brshift 32 2)  # => 8
brshiftcellularmitosisPlayground
(let [len 8
      rand-string (string/join (map |(string/format "%02x" $)
                                    (os/cryptorand len)))]
  (= (length rand-string) (* 2 len)))
# => true
os/cryptorandsogaiuPlayground
(label result
  (each x [0 1 2 3]
    (when (= x 3)
      (print "reached the end"))
    (when (= x 2)
      (return result 8))))
# => 8
labelsogaiuPlayground
(map function? [ even?  (fn [])  |($)  file/read  ->   ])
# =>          @[ true   true     true  false      true ]
function?cellularmitosisPlayground
(let [tbl @{:a 1}]
  (merge-into tbl {:b 2})
  tbl)
# => @{:a 1 :b 2}

# real-world example: https://git.sr.ht/~subsetpark/bagatto/tree/19aea03fe23fe5486890912df7dc4a936ce617a3/item/main.janet#L23
merge-intosogaiuPlayground
(all-dynamics)
# => @[:args :err-color :executable :peg-grammar :pretty-format :syspath]

(setdyn :fixed true)
(all-dynamics)
# => @[:args :err-color :executable :fixed :peg-grammar :pretty-format :syspath]
all-dynamicspepePlayground