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

 new Math.seedrandom('hello.');
math/seedrandomMonif2009Playground
# Interactively read a line from STDIN
(file/read stdin :line)

# Type abcd and then press ENTER
abcd

# Returns:
@"abcd\n"
stdinsemperosPlayground
(peg/find ':d "Battery temperature: 40 °C")
# => 21 index of the first number
peg/findpepePlayground
(do
  (def coll @[])
  (forv i 0 9
    (array/push coll i)
    (+= i 2))
  coll)
# => @[0 3 6]
forvsogaiuPlayground
(= 1 1)  # => true
(= 1 2)  # => false

(= 1.1 1.1)  # => true
(= 1.1 1.2)  # => false

(= 1 1.0)  # => true

# these are representations of two different IEEE-754 64-bit buckets:
(= 
 1.0000000000000001
 1.0000000000000002)  # => false

# these are two representations of the same IEEE-754 64-bit bucket:
(= 
 1.00000000000000001
 1.00000000000000002)  # => true
=cellularmitosisPlayground
(repeat 12 (-> 12 os/cryptorand pp))

# => @"\xA7li[ \xED\xD2\xF7O\xD6\x15="
# => @">\"-w+\x04\x1C\xC1KG\x9C\xE4"
# => @"\x06b\f\xBD\x12\x19\xB6\x1A\xCA\xB9[\x85"
# => @"\xBE`R\t\x13\x81\xED\x9D#\xD0\x11!"
# => @"\xE2\xC1\xD8\x7F\\\xA7\x84\xC0\v\x8B'\x98"
# => @"\xD6\x0Fz\x86\xE2\xB2\x1D}\xC6'{\xB5"
# => @"\x9D\x97\xA1\x07i\x9FW\x83h4n2"
# => @"d\x8E\xB8\xBA \xA6\x9C\f\xC6\xAD{g"
# => @"\r\xB5\xF84#\xB8c~V\xD7d>"
# => @"\xBB\x19\xB2\xDC\x8B\xD9\x7F\xDC\xBE\f\x88\xE3"
# => @"w\xB50\xF9\xFD\xEB\x1D\xFF:j]\xB8"
# => @"\x8F$\xEBKL~\xFD\t\xA8\xD1\x8C\xC5"
# => nil
repeatjgartePlayground
# :as sets a /

(import /deeper/inside :prefix "" :export true)
# @{_ @{:value <cycle 0>} cat @{:private false}}
(import /deeper/inside :as "" :export true)
# @{/cat @{:private false} _ @{:value <cycle 0>} cat @{:private false}}

importveqqqPlayground
path/delim # => ":" on Unix and Linux, ";" on Windows
spork/path/delimclementiPlayground
(def p1 (os/spawn ["echo" "hello"] :p {:out :pipe}))
(def p2 (os/spawn ["grep" "hello"] :p {:in (p1 :out)}))

(:wait p2)
# Creates a pipeline (e.g. echo hello | grep hello)
os/spawnbakpakinPlayground
(comment this is a
         multiline line comment.
         It won't do anything)
commentoz123Playground
(filter  even?                     [1 2 3 4 5])  # => @[2 4]
(filter  odd?                      [1 2 3 4 5])  # => @[1 3 5]
(filter  (fn [x] (not (even? x)))  [1 2 3 4 5])  # => @[1 3 5]
(filter  (complement even?)        [1 2 3 4 5])  # => @[1 3 5]

(def fns [even? odd?])
(map  (fn [f] (filter f [-2 -1 0 1 2]))  fns)  # => @[ @[-2 0 2] @[-1 1]   ]
(def fns (map complement fns))
(map  (fn [f] (filter f [-2 -1 0 1 2]))  fns)  # => @[ @[-1 1]   @[-2 0 2] ]
complementcellularmitosisPlayground
(seq [i :range [0 10] :when (odd? i)] (math/pow 2 i))

# => @[2 8 32 128 512]
# array with 2 to the power of all odd numbers smaller than 10
seqpepePlayground
(string "hello " "world") # => "hello world"
stringswlkrPlayground
# From: https://codeberg.org/veqq/janetdocs/src/commit/54a964d1a35920af2655c4932a9b51379e8b9380/main.janet#L30

# where in .env you have:
# DATABASE_URL=examples-db.sqlite3
# PORT=9025


(defn main [& args]
  (joy/db/connect (joy/env :database-url))
  (server app (joy/env :port) "0.0.0.0")
  (joy/db/disconnect))
joy/envveqqqPlayground
(inc 42)  # => 43
(map inc [1 2 3])  # => @[2 3 4]
inccellularmitosisPlayground