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

(os/shell "touch foo")
(os/stat "foo" :modified)  # => 1593836002
(os/touch "foo")
(os/stat "foo" :modified)  # => 1593836013
os/touchcellularmitosisPlayground
(let [c0 (ev/chan)
      c1 (ev/chan 1)]
  [(ev/capacity c0) (ev/capacity c1)])
# => '(0 1)
ev/capacitysogaiuPlayground
(math/exp2 8)  # => 256
math/exp2cellularmitosisPlayground
(def a @[1 2])
(def b @[1 2])
(= a b)  # => false

(def a @[1 2])
(def b (array/concat a 3))
a        # => @[1 2 3]
b        # => @[1 2 3]
(= a b)  # => true
array/concatcellularmitosisPlayground
# sorted allocates the full memory of its input

(def d2  (range 10000000 0 -1)) # 87mb
(sorted d2) # now 167 mb
sortedveqqqPlayground
# wrap short-fn / | 
(-> 10
    (|(/ $ 2)))
# =>
5

# also wrap fn
(-> 10
    ((fn [n] (/ n 2))))
# =>
5
->sogaiuPlayground
(peg/match ~{:main (capture (some :S))}
           "hello world")
# => @["hello"]
peg/matchsogaiuPlayground
(type print)
# =>
:cfunction
typesogaiuPlayground
(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)]      ]
kvscellularmitosisPlayground
(drop-while |(> 3 $) [0 1 2 3 4 5 6 7 8 ])
# => (3 4 5 6 7 8)
drop-whileleobmPlayground
(update-in @{:a @{:b 1}} [:a :b] (fn [x] (+ 1 x)))
# @{:a @{:b 2}}
update-insbjaverPlayground
(let [buf @"hello"]
  (buffer/blit buf " there" -1))
# =>
@"hello there"
buffer/blitsogaiuPlayground
@[1 2 3]                 # -> @[1 2 3]
(array 1 2 3)            # -> @[1 2 3]
(array (splice [1 2 3])  # -> @[1 2 3]
(array ;[1 2 3])         # -> @[1 2 3]
arraycellularmitosisPlayground
# more at https://github.com/sogaiu/margaret/tree/master/examples
(peg/match ~{:main (replace (some :header-line)
                            ,(fn [& captures]
                               (table ;captures)))
             :header-line (sequence (capture :header-name) ":"
                                    :s+
                                    (capture :header-value) :crlf)
             :header-name (to ":")
             :header-value (to :crlf)
             :crlf "\r\n"}
           (string "Content-Type: text/plain\r\n"
                   "Content-Length: 1024\r\n"))
# => @[@{"Content-Length" "1024" "Content-Type" "text/plain"}]
peg/matchsogaiuPlayground
(<)        # -> true
(< 1)      # -> true
(< 1 2)    # -> true
(< 2 1)    # -> false
(< 1 2 3)  # -> true
(< 1 3 2)  # -> false
<cellularmitosisPlayground