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/find-all ~(capture (range "09"))
              "hi 0 bye 1")
# => @[3 9]
peg/find-allsogaiuPlayground
(os/lstat "t.janet")
# @{:size 249 :permissions "rw-r--r--" :nlink 1 :blocks 8 :dev 16777221 :accessed 1606236760 :modified 1606236759 :uid 501 :mode :file :blocksize 4096 :changed 1606236759 :inode 14801850 :rdev 0 :int-permissions 420 :gid 501}

(get (os/lstat "t.janet") :size)  # 249
os/lstatbtbytesPlayground
(sorted-by > @[1 2 3 4 5 6 7 8 9 10 11 12]) # => @[8 7 9 11 10 12 2 1 3 5 4 6]

(sorted-by < @[1 2 3 4 5 6 7 8 9 10 11 12]) # => @[8 7 9 11 10 12 2 1 3 5 4 6]

(sorted-by = @[1 2 3 4 5 6 7 8 9 10 11 12]) # => @[8 7 9 11 10 12 2 1 3 5 4 6]


sorted-byjgartePlayground
(math/hypot 1 1)  # => 1.41421
(math/sqrt 2)     # => 1.41421
math/hypotcellularmitosisPlayground
(last [1 1 2 3 5 8])
# => 8
lastsogaiuPlayground
# nested iteration
(loop [a :in [100 200 300]
       b :in [1 2 3]]
   (print (+ a b)))

# 101
# 102
# 103
# 201
# 202
# 203
# 301
# 302
# 303
looperichaneyPlayground
(varglobal "smile" false)
# => nil

smile
# => false

(set smile true)
# => smile

smile
# => true

(dyn 'smile)
# => @{:ref @[true]}
varglobalsogaiuPlayground
(def a @[])
(array/insert a  1 :a)  # error: index out of range
(array/insert a -2 :a)  # error: index out of range
array/insertcellularmitosisPlayground
(in :yo 0)
# => 121
insogaiuPlayground
(dyn :pretty-format)
# => "%.20Q"
dynsogaiuPlayground
(def request {:params {:id 1}}) # => {:params {:id 1}}

(get-in request [:params :id]) # => 1

(get-in request [:params :name]) # => nil

(get-in request [:params :name] "N/A") # => "N/A"
get-ininchingforwardPlayground
(def record @{:recipient @{:name "Bob" :age 60} :sender @{:name "Alice" :age 21}})

(put-in
  record
  [:sender :age] 
  26)

# @{:recipient @{:name "Bob" :age 60} :sender @{:name "Alice" :age 26}}

(put-in
  record
  [:recipient] 
  @{:name "Carl"})

# @{:recipient @{:name "Carl"} :sender @{:name "Alice" :age 26}}
put-infelixrPlayground
(def h ["a" "b" :c]) # => ("a" "b" :c)

(find (fn [a] (= "a" a)) h) # => "a"
findfaywongPlayground
(var a 2)
a        # => 2
(dec a)  # => 1
a        # => 2
(-- a)   # => 1
a        # => 1
--cellularmitosisPlayground
(tuple 1 2.3 :a "foo" true nil [] {} (fn []))
# =>  (1 2.3 :a "foo" true nil () {} <function 0x7FB2A3D030B0>)
tuplecellularmitosisPlayground