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

(-> "X"
    (string "a" "b")
    (string "c" "d")
    (string "e" "f"))  # => "Xabcdef"
->uvtcPlayground
(not=        [1 1]   [1 1])  # => false
(not=        [1 1]   [2 3])  # => true
(not=        [1 1]  @[1 1])  # => true
(not=        [1 1]  @[2 3])  # => true
(not=       @[1 1]  @[1 1])  # => true
(not=       @[1 1]  @[2 3])  # => true

(deep-not=   [1 1]   [1 1])  # => nil
(deep-not=   [1 1]   [2 3])  # => true
(deep-not=   [1 1]  @[1 1])  # => true
(deep-not=   [1 1]  @[2 3])  # => true
(deep-not=  @[1 1]  @[1 1])  # => nil
(deep-not=  @[1 1]  @[2 3])  # => true
not=cellularmitosisPlayground
(> 12 11 10 9 8 7 6 5 4 3 2 1) # => true

(> 12 11 10 9 8 7 6 5 4 3 2 9) # => false
>jgartePlayground
(math/exp 1)  # => 2.71828
math/e        # => 2.71828
math/expcellularmitosisPlayground
(var abc 123)
(= 356 (with-vars [abc 456] (- abc 100)))
with-varsnunziocPlayground
(mod 13 5)  # 3
modbtbytesPlayground
(parse "[:a :b :c]") # => [:a :b :c]
parsesogaiuPlayground
(string/check-set "0123456789abcdef" "deadbeef") # => true
string/check-setsogaiuPlayground
(empty? :)
# => true
empty?sogaiuPlayground
(from-pairs [[:hello "world"] [:foo "bar"]]) 

# => @{:foo "bar" :hello "world"}
from-pairsjgartePlayground
# from https://janet.guide/control-flow/
(defn calculate [expr]
  (match expr
    [:add x y] (+ x y)
    [:subtract x y] (- x y)
    [:multiply x y] (* x y)
    ([:divide x y] (= y 0)) (error "division by zero!")
    [:divide x y] (/ x y)))

(calculate [:subtract 5 10])

# Note, it checks prefixes, so you must order things this way:
(match [1 2]
  [x y z] "three elements"
  [x y] "two elements"
  [x] "one element"
  [] "no elements")
matchveqqqPlayground
(->> "X"
     (string "a" "b")
     (string "c" "d")
     (string "e" "f"))  # => "efcdabX"
->>uvtcPlayground
(array 1 2.3 :a "foo" true nil [] {} (fn []))
# => @[1 2.3 :a "foo" true nil () {} <function 0x7FB2A3F02170>]
arraycellularmitosisPlayground
(var x 1)
(loop [n :range-to [1 5]]
  (*= x n))
x # => 120
*=quexxonPlayground
# Convert an array of k/v pairs into a table

(def kvp @[[:foo 1] [:bar 2]])
(table ;(mapcat identity kvp))  # => @{:foo 1 :bar 2}
mapcatMikeBellerPlayground