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

(doc-of file/read) # => file/read docs are shown

(def tmpfile (file/temp))

(doc-of (tmpfile :read)) # => also shows the file/read docs. 
# Note that we didn't have to use the file/read symbol here to get docs.
doc-ofyumaikasPlayground
(keyword)
# => :
keywordsogaiuPlayground
(comment

  # the content actually has to parse as janet

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

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

  )
commentsogaiuPlayground
(math/atan2 0 0)
# => 0
math/atan2sogaiuPlayground
(math/acos 0.3)
1.2661036727795
math/acosbtbytesPlayground
(defn inc [x] (+ x 1))
(defn inv [x] (* x -1))
(defn sq  [x] (* x x))

(-> 2 inc)             # -> 3
(-> 2 inc inc)         # -> 4
(-> 2 inc inc inv)     # -> -4
(-> 2 inc inc inv sq)  # -> 16
->cellularmitosisPlayground
(sort-by
  (fn [x] (get x :b))
   @[{:a 1 :b 100} {:a 100 :b 1} {:a -1 :b 50}])

# -> @[{:a 100 :b 1} {:a -1 :b 50} {:a 1 :b 100}]
sort-byfelixrPlayground
(let [x false]
  (var y 0)
  (unless x
    (++ y)
    (++ y))
  y)
# => 2
unlesssogaiuPlayground
(bnot 255)  # => -256
bnotcellularmitosisPlayground
(array 1 2.3 :a "foo" true nil [] {} (fn []))
# => @[1 2.3 :a "foo" true nil () {} <function 0x7FB2A3F02170>]
arraycellularmitosisPlayground
(range 10000) # @[0 1 2 ... 9997 9998 9999]

# By default, pp truncates. You can change its behavior:
(setdyn :pretty-format "%j") # jdn format
(setdyn :pretty-format "%m") # full printing without truncation
# For a list of all print formats: https://janet-lang.org/capi/writing-c-functions.html#Panicking

(range 10000) # Prints all of them according to your dyn
ppveqqqPlayground
(parse "(+ 4 5)") # => (+ 4 5)
(type (parse "(+ 4 5)")) # => :tuple
parseskuzzymigletPlayground
(filter identity [1 true 2 3 nil 4 false])
# => @[1 true 2 3 4]
identityleobmPlayground
(def a-tuple-1 [:number 10])
(def a-tuple-2 [:string "Hello there!"])
(defn show [what]
  (match what
    [:number n] (printf "It's a number! %d" n)
    [:string s] (printf "Here's a string: %s" s)
    _ (printf "I dunno what this is: %q" what)))

(show a-tuple-1)
(show a-tuple-2)
(show [:array @[]])
matchroobiePlayground
(map math/abs   [-2.9 -2.1 2.1 2.9])  # => @[ 2.9  2.1  2.1  2.9 ]
(map math/floor [-2.9 -2.1 2.1 2.9])  # => @[ -3   -3   2    2   ]
(map math/ceil  [-2.9 -2.1 2.1 2.9])  # => @[ -2   -2   3    3   ]
(map math/round [-2.9 -2.1 2.1 2.9])  # => @[ -3   -2   2    3   ]
(map math/trunc [-2.9 -2.1 2.1 2.9])  # => @[ -2   -2   2    2   ]
math/abscellularmitosisPlayground