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

(defn knorkulate [a b]
  (tracev (+ a (* b b ))))
# <function knorkulate>

(knorkulate 2 34)
# trace on line 2, column 1: (+ a (* b b)) is 1158
# 1158
tracevkamisoriPlayground
(defn square [x] (* x x))
(defn square-then-dec [x] ((comp dec square) x))
(defn dec-then-square [x] ((comp square dec) x))
(square-then-dec 3)  # => 8
(dec-then-square 3)  # => 4
compcellularmitosisPlayground
# on a Core i5-4590:
(os/arch)  # => :x64

# on an Intel Atom N270:
(os/arch)  # => :x86

# on a raspberry pi:
(os/arch)  # => :arm
os/archcellularmitosisPlayground
(keyword "")
# => :
keywordsogaiuPlayground
# janet 1.10.1

(pos? 1)      # => true
(pos? 1.618)  # => true

(pos? 0)      # => false
(pos? -1)     # => false

(def pi 3.14159)
(pos? pi)       # => true

(pos? nil)      # => true
(pos? false)    # => true
(pos? "hello")  # => true
(pos? :heyo)    # => true
(pos? [-1])     # => true
(pos? {:a 1})   # => true
(pos? (fn []))  # => true
pos?cellularmitosisPlayground
(one? (math/next 1 math/inf))  # => false
math/nextcellularmitosisPlayground
(let [seed 0]
  (= (math/rng-uniform (math/rng seed))
     (math/rng-uniform (math/rng seed))))
# => true
math/rng-uniformsogaiuPlayground
(map  |($ {:a 7 :b 8} )   [  keys      values    kvs             pairs                 ])
# =>                     @[  @[:a :b]  @[7 8]    @[:a 7 :b 8]    @[(:a 7) (:b 8)]      ]

(map  |($ [4 5 6] )       [  keys      values    kvs             pairs                 ])
# =>                     @[  @[0 1 2]  @[4 5 6]  @[0 4 1 5 2 6]  @[(0 4) (1 5) (2 6)]  ]

(map  |($ 'ab )           [  keys      values    kvs             pairs                 ])
# =>                     @[  @[0 1]    @[97 98]  @[0 97 1 98]    @[(0 97) (1 98)]      ]

(map  |($ :ab )           [  keys      values    kvs             pairs                 ])
# =>                     @[  @[0 1]    @[97 98]  @[0 97 1 98]    @[(0 97) (1 98)]      ]

(map  |($ "ab" )          [  keys      values    kvs             pairs                 ])
# =>                     @[  @[0 1]    @[97 98]  @[0 97 1 98]    @[(0 97) (1 98)]      ]
valuescellularmitosisPlayground
(math/log (* math/e math/e))  # => 2
(math/log2 256)               # => 8
(math/log10 1000)             # => 3
math/logcellularmitosisPlayground
 new Math.seedrandom('hello.');
math/seedrandomMonif2009Playground
(os/cryptorand 1)  # => @"\n"
(os/cryptorand 1)  # => @"<"
(os/cryptorand 1)  # => @"\xC0"
(os/cryptorand 1)  # => @"\x89"

(os/cryptorand 8)  # => @"\x87\x13\x99\x95\x10su\e"
os/cryptorandcellularmitosisPlayground
(odd? 2) # => false
(odd? nil) # throws an error
(odd? 1) # => true
(odd? "a") # => throws an error
odd?swlkrPlayground
# opens a file named filename for writing, and writes Hello World!
(def f (file/open "filename" :w))
(file/write f "Hello World!")
(file/flush f)
(file/close f)
file/writeterminalcommandPlayground
(def request {:params {:id 1}}) # => {:params {:id 1}}

(get-in request [:params :id]) # => 1

(get-in request [:params :name]) # => nil

(get-in request [:params :name] "N/A") # => "N/A"
get-ininchingforwardPlayground
(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/setenvcellularmitosisPlayground