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

(var n 5) # n = 5
(-= n 1) # n -= 1
(print n) # 4
-=HoangTuan110Playground
(let [buf @"hello"]
  (buffer/blit buf " there" -1))
# =>
@"hello there"
buffer/blitsogaiuPlayground
(update @{:a 1} :a inc)
# => @{:a 2}
updatesogaiuPlayground
(slice [:a :b :c :d])  # => (:a :b :c :d)

(slice [:a :b :c :d] 0)  # => (:a :b :c :d)
(slice [:a :b :c :d] 1)  # => (:b :c :d)
(slice [:a :b :c :d] 3)  # => (:d)
(slice [:a :b :c :d] 4)  # => ()
(slice [:a :b :c :d] 5)  # error: index out of range

(slice [:a :b :c :d] -1)  # => ()
(slice [:a :b :c :d] -2)  # => (:d)
(slice [:a :b :c :d] -4)  # => (:b :c :d)
(slice [:a :b :c :d] -5)  # => (:a :b :c :d)
(slice [:a :b :c :d] -6)  # error: index out of range

(slice [:a :b :c :d] 0 0)  # => ()
(slice [:a :b :c :d] 0 1)  # => (:a)
(slice [:a :b :c :d] 0 4)  # => (:a :b :c :d)

(slice [:a :b :c :d] -1 -1)  # => ()
(slice [:a :b :c :d] -2 -1)  # => (:d)
(slice [:a :b :c :d] -5 -1)  # => (:a :b :c :d)

(slice [:a :b :c :d] 1 0)  # => ()
(slice [:a :b :c :d] 4 0)  # => ()
(slice [:a :b :c :d] -1 -2)  # => ()
(slice [:a :b :c :d] -1 -5)  # => ()
slicecellularmitosisPlayground
(<= 1 2 3) # => true
(<= 1 2 1) # => false
<=pepePlayground
(def f (ev/go (coro "world"))) # coro is great for fast fiber creating
(ev/sleep 0.0001) # give ev a chance in the REPL, remove in file
(fiber/last-value f) # "world"
ev/gopepePlayground
(string/join @["1" "2" "3"]) # => "123"
# The esp argument is optional, and defaults to empty string
string/joinyumaikasPlayground
(map tuple ["a" "b" "c" "d"] [1 2 3 4] "abcd")

# => @[("a" 1 97) ("b" 2 98) ("c" 3 99) ("d" 4 100)]
mapfelixrPlayground
# Get a new and different random number each time you run your program.
(math/seedrandom (os/cryptorand 8))
(math/random)
math/randomuvtcPlayground
(defn f1 [s] (string "-" s "-"))
(defn f2 [s] (string "=" s "="))
(defn f3 [s] (string "#" s "#"))

(def f (juxt f1 f2 f3))

(f "x") # => ("-x-" "=x=" "#x#")
juxtuvtcPlayground
(peg/replace ~(sequence :s (thru "t")) 
             " duck"
             "smiling cat sleeps")
# => @"smiling duck sleeps"
peg/replacesogaiuPlayground
(defn recent-mods
  "List the files in the current directory which have changed within the last hour."
  []
  (filter
    (fn [fname]
      (<
        (- (os/time) 3600)
        (os/stat fname :modified)))
    (os/dir ".")))
os/statcellularmitosisPlayground
(min 1 2 3)             # => 1
(min (splice [1 2 3]))  # => 1
(min ;[1 2 3])          # => 1
(apply min [1 2 3])     # => 1
mincellularmitosisPlayground
(let [c0 (ev/chan)
      c1 (ev/chan 1)]
  [(ev/capacity c0) (ev/capacity c1)])
# => '(0 1)
ev/capacitysogaiuPlayground
(symbol "foo")  # => foo

(def a "foo")
(symbol a)         # => foo
(symbol a 42 nil)  # => foo42nil
symbolcellularmitosisPlayground