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

(empty? [])
# => true
empty?sogaiuPlayground
(min 1 2 3)             # => 1
(min (splice [1 2 3]))  # => 1
(min ;[1 2 3])          # => 1
(apply min [1 2 3])     # => 1
mincellularmitosisPlayground
(eval-string "(+ 1 2 3 4)") # -> 10
(eval-string ")") # -> parse error
(eval-string "(bloop)") # -> compile error
(eval-string "(+ nil nil)") # -> runtime error
eval-stringswlkrPlayground
(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
deep-not=cellularmitosisPlayground
(spit "/tmp/hello.sh" "#!/bin/bash\necho 'Hello from Bash!'\n")
(os/chmod "/tmp/hello.sh" "rwx------")
(os/setenv "PATH" (string (os/getenv "PATH") ":/tmp"))
(os/shell "hello.sh")
os/chmodcellularmitosisPlayground
(describe {:a 1}) # => "<struct 0x5564AF1BD6C0>"
describesogaiuPlayground
(-> @{:a 0 :b 0}
    (update :a inc)
    (update :b inc))
# => @{:a 1 :b 1}
updatesogaiuPlayground
(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/floorcellularmitosisPlayground
(/ 0)
# => inf
/sogaiuPlayground
(map false? [ false nil   true  0     1     42    'a    :a    "a"   [97]  {:a 42} (fn []) ])
# =>       @[ true  false false false false false false false false false false   false   ]
false?cellularmitosisPlayground
(map hash [nil true false -1 0 3.14 :a "foo" [1 2 3] {:a 1} (fn [])])
# => @[0 1 0 -1074790400 0 1244950043 -2107123988 -1254832049 -2021739803 -1395744911 53378043]
hashcellularmitosisPlayground
(let [p (parser/new)
      src ``
          (defn x
            [y]
            (+ 3 (* 4
                    (- 2 3)
          ``]
  (parser/consume p src)
  ((parser/state p) :delimiters))
# => "((("
parser/statesogaiuPlayground
(mean [1 10 100])  # => 37
(mean [])          # => nan
meancellularmitosisPlayground
(map truthy? [ nil   false true  0     1     'a    :a    "a"   []    {}    (fn []) ])
# =>        @[ false false true  true  true  true  true  true  true  true  true    ]

# note that 'not' works as an implementation of 'falsey?'
(map not     [ nil   false true  0     1     'a    :a    "a"   []    {}    (fn []) ])
# =>        @[ true  true  false false false false false false false false false   ]
truthy?cellularmitosisPlayground
(array 1 2.3 :a "foo" true nil [] {} (fn []))
# => @[1 2.3 :a "foo" true nil () {} <function 0x7FB2A3F02170>]
arraycellularmitosisPlayground