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

(nan? 1)  # => false
(nan? (/ 0 0))  # => true
(nan? (sqrt -1))  # => true
nan?cellularmitosisPlayground
(get (os/environ) "HOME")  # => "/Users/cell"
(os/getenv "HOME")  # => "/Users/cell"
os/environcellularmitosisPlayground
Math. Seedrandom(3206)
math/seedrandomMonif2009Playground
(def a @[1 2 3])
(array/fill a 17)   # => @[17 17 17]
(array/fill a "n")  # => @["b" "b" "b"]
(array/fill a)      # => @[nil nil nil]
a                   # => @[nil nil nil]
array/fillcellularmitosisPlayground
(last 'hello)
# => 111
lastsogaiuPlayground
(def a @[1 2])
(array/concat a 3 [4 5] @[6 7] [] @[] 8)
a  # => @[1 2 3 4 5 6 7 8]
array/concatcellularmitosisPlayground
(defn return-nil [x] nil)
(-?> 1 inc)                     # -> 2
(-?> 1 inc inc)                 # -> 3
(-?> 1 inc inc return-nil)      # -> nil
(-?> 1 inc inc return-nil inc)  # -> nil
-?>cellularmitosisPlayground
# create a channel without buffer, default is 0
(def channel (ev/chan))

(ev/spawn
  (ev/sleep 5)
  (ev/give channel "Hard work is done!"))

(print "do anything")
(for i 0 5
  (print i)
  (ev/sleep 0.5))

(print (ev/take channel)) # blocks here, until there is a result in the channel
(print "done")

ev/chanleobmPlayground
(compare> 1 0) # => true
(compare> 10 9.9) # => true
(compare> :a :b) # => false
(compare> :b :a) # => true
compare>swlkrPlayground
# There is a list of formatters here: https://janet-lang.org/capi/writing-c-functions.html


(string/format "With terminal colors: %M" [:array {:key-in "struct"}]) # => "With terminal colors: (\e[33m:array\e[0m {\e[33m:key-in\e[0m \e[35m\"struct\"\e[0m})"
string/formatroobiePlayground
(invert [:ant :bee :elephant :fox :penguin])
# => @{:bee 1 :fox 3 :elephant 2 :ant 0 :penguin 4}
invertsogaiuPlayground
(bor 1 2 4)  # => 7
(bor 7 12)  # => 15

#    0111   (7)
# or 1100  (12)
# -------
#    1111  (15)
borcellularmitosisPlayground
# janet 1.10.1

# non-numeric values appear to always be greater than numeric values
(< math/inf nil)      # -> true
(< math/inf true)     # -> true
(< math/inf false)    # -> true
(< math/inf "hello")  # -> true
(< math/inf :heyo)    # -> true
(< math/inf (fn []))  # -> true
(< math/inf {:a 1})   # -> true

# non-numeric values also follow an ordering.
# rearranging any of these values turns the result false:
(< nil false true "a" "b" :a :b [] [1] [1 1] [2] {} {:a 1} (fn []))  # -> true
<cellularmitosisPlayground
(buffer/bit (buffer/new-filled 1 (chr "0")) 4)
# => true
buffer/bitsogaiuPlayground
(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)]      ]
pairscellularmitosisPlayground