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

(some even? [1 3 5 7 11 18])
# =>
true
somesogaiuPlayground
(any? "")
# => nil

(any? "Hello")
# => 72

(any? @"Hello")
# => 72

(any? @[])
# => nil

(any? [])
# => nil

(any? {})
# => nil

(any? @{})
# => nil

(any? @[1 2 3 4])
# => 1 

(any? @{:a 2 :b 3})
# => 2
any?leobmPlayground
(def add17 (partial + 17))
(add17 3)            # -> 20
(add17 3 4)          # -> 24
(map add17 [1 2 3])  # -> @[18 19 20]
partialcellularmitosisPlayground
(math/floor 1.1)  # => 1
(map math/floor [1.1 1.2 1.3])  # => @[1 1 1]
math/floorcellularmitosisPlayground
(def b @"")
(xprin b "HOHOHO")
# => nil
b
# => "HOHOHO"
xprinpepePlayground
(scan-number "111" 2)
# => 7
scan-numbersogaiuPlayground
(/ 0)
# => inf
/sogaiuPlayground
(seq [i :range [0 3]
      j :range [0 3]]
  [(keyword (string/format "%c" (+ 97 i)))
   j])
# => '@[(:a 0) (:a 1) (:a 2) (:b 0) (:b 1) (:b 2) (:c 0) (:c 1) (:c 2)]
seqsogaiuPlayground
(if-let [x true 
         y (not x)]
  :a
  :b)
# => :b
if-letsogaiuPlayground
(last "hello")
# => 111
lastsogaiuPlayground
(defn eval-string
  ``Evaluates a string in the current environment. If more control over the
  environment is needed, use `run-context`.``
  [str]
  (var state (string str))
  (defn chunks [buf _]
    (def ret state)
    (set state nil)
    (when ret
      (buffer/push-string buf str)
      (buffer/push-string buf "\n")))
  (var returnval nil)
  (run-context {:chunks chunks
                :on-compile-error (fn compile-error [msg errf &]
                                    (error (string "compile error: " msg)))
                :on-parse-error (fn parse-error [p x]
                                  (error (string "parse error: " (:error p))))
                :fiber-flags :i
                :on-status (fn on-status [f val]
                             (if-not (= (fiber/status f) :dead)
                               (error val))
                             (set returnval val))
                :source :eval-string})
  returnval)
run-contexttionisPlayground
(- ;(range 10))
# => -45
-sogaiuPlayground
(->> 
  (string/split " " "this  is an  example yes, an example")
  (filter (complement empty?))
  (frequencies))
# -> @{"is" 1 "example" 2 "yes," 1 "an" 2 "this" 1}

# same as:
(frequencies
  (filter
    (complement empty?)
    (string/split " " "this  is an  example yes, an example")))
->>felixrPlayground
(defn get-time-str []
  (let [{:hours h :minutes m :seconds s} (os/date)]
    (string h ":" m ":" s)))

(get-time-str) => "23:18:16"
os/datetupini07Playground
# :when modifier argument example

(let [even-numbers  @[]]
    (loop [i :range [0 50] :when (even? i)]
        (array/push even-numbers i))
    even-numbers)

# => @[0 2 4 6 8 10 12 14 16 1.....]
loopleobmPlayground