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 tips for working with bytes and unicode:
(string/bytes "что-нибудь")                         #> (209 135 209 130 208 190 45 208 189 208 184 ...
(print (string/from-bytes 208 176 208 177))         #> аб
(map string/from-bytes (string/bytes "что-нибудь")) #> @["\xD1" "\x87" "\xD1" "\x82" "\xD0" "\xBE" ...

# Print renders "\xD1" "\x87" as ч, as unicode characters may have multiple bytes
# So use apply:
(apply print (map string/from-bytes 
                  (string/bytes "что-нибудь")))     #> что-нибудь
string/bytesveqqqPlayground
(reduce (fn [s1 s2]
          (string "[" s1 "+" s2 "]"))
        "x"
        ["a" "b" "c"])

#=> "[[[x+a]+b]+c]"
reduceuvtcPlayground
(update @{:a 1} :a inc)
# => @{:a 2}
updatesogaiuPlayground
# 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
(any? [false false nil]) => nil
(any? [false false nil 1]) => 1
(any? [false false nil true]) => true
any?swlkrPlayground
(in "yo" 0)
# => 121
insogaiuPlayground
(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/ceilcellularmitosisPlayground
#!/usr/bin/env janet
# echo stdin to stdout.
(file/write stdout (file/read stdin :all))
file/readcellularmitosisPlayground
[1 2 3]               # => (1 2 3)
(tuple/type [1 2 3])  # => :parens

(tuple/brackets 1 2 3)               # => [1 2 3]
(tuple/type (tuple/brackets 1 2 3))  # => :brackets
tuple/typecellularmitosisPlayground
(import spork/charts :as c)
(c/line-chart
  :width 400 :height 200
  :data {:timestamp [1 2 3 5 40 60]
         :temperature-1 [75.1 75.2 75.4 75.5 75.5 75.4]
         :temperature-2 [55.1 55.4 55.7 60.0 60.4 60.9]}
  :save-as "bla.png"
  :x-column :timestamp
  :y-column [:temperature-1 :temperature-2])

# then open bla.png to view
# bakpakin shared this example
spork/charts/line-chartveqqqPlayground
# note that os/touch does not create a file if it does not yet exist.
(os/touch "foo")
error: No such file or directory
  in os/touch
  in _thunk [repl] (tailcall) on line 2, column 1
os/touchcellularmitosisPlayground
(get @"A"                      0)  # => 65 (0b01000001)
(get (buffer/bit-clear @"A" 0) 0)  # => 64 (0b01000000)
(get (buffer/bit-clear @"A" 6) 0)  # =>  1 (0b00000001)
buffer/bit-clearcellularmitosisPlayground
(describe @[:a :b]) # => "<array 0x55EC375CF440>"
describesogaiuPlayground
(var n 5) # n = 5
(-= n 1) # n -= 1
(print n) # 4
-=HoangTuan110Playground
(pp (all-bindings))
# => prints @[% %= * ... yield zero? zipcoll]

(def a "A")
(pp (all-bindings (curenv) true))
# => prints @[_ a] - only local bindings are listed
all-bindingspepePlayground