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

(merge {:a 1 :b 2} 
       {:c 3 :a 4})
# -> @{:c 3 :a 4 :b 2}
mergeKrasjetPlayground
(def a @[1 2])
(def b @[1 2])
(= a b)  # => false

(def a @[1 2])
(def b (array/concat a 3))
a        # => @[1 2 3]
b        # => @[1 2 3]
(= a b)  # => true
array/concatcellularmitosisPlayground
(reduce string "ha" ["ha" "ha" "ha" "ha"]) # => "hahahahaha"

(accumulate string "ha" ["ha" "ha" "ha" "ha"]) # => @["haha" "hahaha" "hahahaha" "hahahahaha"]
accumulatejgartePlayground
(dyn 'defn)
# => @{:source-map ("boot.janet" 12 1) :value <function defn> :doc "(defn name & more)\n\nDefine a function. Equivalent to (def name (fn name [args] ...))." :macro true}
dynsogaiuPlayground
(def kvpairs [[:x 1] [:y 2]])

(table ;(flatten kvpairs)) # => @{:x 1 :y 2}
flattenyumaikasPlayground
(empty? :)
# => true
empty?sogaiuPlayground
(repeat 3 (print "HO"))
# => prints
# HO
# HO
# HO
repeatpepePlayground

# sh/$'s contents are quasiquoted, allowing direct or string arguments
# so you need to unquote , variables:

(def out (file/open "trust-db.txt" :w))
(sh/$ "gpg" "--export-ownertrust" > ,out) # > requires an opened file object
(file/close out)

# note how > requires an opened file object
(with [out (file/open "trust-db.txt" :w)]
  (sh/$ gpg --export-ownertrust > ,out))
sh/$veqqqPlayground
(string/trimr " foo ")  # => " foo"
(string/trimr "_!_foo_!_" "_!")  # => "_!_foo"
string/trimrcellularmitosisPlayground
(def a @[23 42])
(array/clear a)
(pp a)
# => prints @[]
array/clearpepePlayground
(eachk k {:a "a val" :b "b val" :c "c val"} (print k))
# prints c
# prints a
# prints b
eachkpepePlayground
(get (os/environ) "HOME")  # => "/Users/cell"
(os/getenv "HOME")  # => "/Users/cell"
os/environcellularmitosisPlayground
(peg/find-all ~(capture (range "09"))
              "hi 0 bye 1")
# => @[3 9]
peg/find-allsogaiuPlayground
(string/join @["alice" "bob" "eve"] "\t")
# => "alice\tbob\teve"
string/joinsogaiuPlayground
(unmarshal @"hello world!") # => 104
unmarshaljgartePlayground