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

(get (os/environ) "HOME")  # => "/Users/cell"
(os/getenv "HOME")  # => "/Users/cell"
os/environcellularmitosisPlayground
(-> @{:a 0 :b 0}
    (update :a inc)
    (update :b inc))
# => @{:a 1 :b 1}
updatesogaiuPlayground
(-> "X"
    (string "a" "b")
    (string "c" "d")
    (string "e" "f"))  # => "Xabcdef"
->uvtcPlayground
(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
(os/date)
# => {:month 6 :dst false :year-day 185 :seconds 38 :minutes 44 :week-day 6 :year 2020 :hours 4 :month-day 3}
os/datecellularmitosisPlayground
(tuple 1 2.3 :a "foo" true nil [] {} (fn []))
# =>  (1 2.3 :a "foo" true nil () {} <function 0x7FB2A3D030B0>)
tuplecellularmitosisPlayground
(reduce (fn [s1 s2]
          (string "[" s1 "+" s2 "]"))
        "x"
        ["a" "b" "c"])

#=> "[[[x+a]+b]+c]"
reduceuvtcPlayground
# foo.txt is a file with contents "hello\nworld\n".
(slurp "foo.txt")  # => @"hello\nworld\n"
(string/split "\n" (slurp "foo.txt"))  # => @["hello" "world" ""]

(defn slurp-lines [path]
  (string/split "\n" (slurp path)))

(slurp-lines "foo.txt")  # => @["hello" "world" ""]

(string/join @["hello" "world" ""] "\n")  # => "hello\nworld\n"
(spit "foo2.txt" (string/join @["hello" "world" ""] "\n"))
# The contents of foo.txt and foo2.txt are now identical.

(defn spit-lines [path lines]
  (spit path (string/join lines "\n")))

(spit-lines "foo3.txt" (slurp-lines "foo.txt"))
# The contents of foo.txt and foo3.txt are now identical.
slurpcellularmitosisPlayground
(os/perm-int "rw-r--r--")  # => 420
(os/perm-int "rwxr-xr-x")  # => 493

# note:
8r644  # => 420
8r755  # => 493
os/perm-intcellularmitosisPlayground
(int/u64 "18446744073709551615")
# => <core/u64 18446744073709551615>
int/u64sogaiuPlayground
(map bytes?      [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ true  true  true   true   false    false     false        false         ]

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

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

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

(map buffer?     [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false false  true   false    false     false        false         ]
bytes?cellularmitosisPlayground
(math/ceil 1.1)  # => 2
(map math/ceil [1.1 1.2 1.3])  # => @[2 2 2]
math/ceilcellularmitosisPlayground
(os/shell "uptime > /tmp/uptime.txt")  # => 0
(slurp "/tmp/uptime.txt")
# => @"22:33  up 5 days,  9:34, 15 users, load averages: 1.93 1.74 1.59\n"
(os/rm "/tmp/uptime.txt")  # => nil
os/readlinkcellularmitosisPlayground
(peg/find ':a "Battery temperature: 40 °C")

# => 0 index of the first upper/lower case character

# :a (range "az" "AZ")
peg/findjgartePlayground
(comment

  # the content actually has to parse as janet

  # this is ok
  (+ 1 1)
  # => 2

  # if there is something with missing delimiters though...

  )
commentsogaiuPlayground