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

(drop-until |(> $ 8)
            [1 1 2 3 4 5 8 13 21])
# => '(13 21)
drop-untilsogaiuPlayground
# *doc-width* is bound to the keyword :doc-width - it can be used in place of
# :doc-width in a call to `dyn`, `setdyn`, or `with-dyns` and is preferable
# to using the keyword directly. When set to a number, it indicates the
# maximum width (in columns) of a row of text returned by `doc-format`.

# - Like *doc-color*, *doc-width* can be used to adjust the output of
#   `doc-format`.
# - When the :doc-width dynamic binding is not set, the default width is 80.
# - By default, `doc-format` adds 4 space indentation and subtracts 8 from
#   the value of the :doc-width dynamic binding to calculate a max width.

# Default:
# repl> (doc doc)
# 
# 
#     macro
#     boot.janet on line 3573, column 1
# 
#     (doc &opt sym)
# 
#     Shows documentation for the given symbol, or can show a list of 
#     available bindings. If sym is a symbol, will look for documentation 
#     for that symbol. If sym is a string or is not provided, will show 
#     all lexical and dynamic bindings in the current environment 
#     containing that string (all bindings will be shown if no string is 
#     given).

# With *doc-width*:
# repl> (with-dyns [*doc-width* 40] (doc doc))
# 
# 
#     macro
#     boot.janet on line 3573, column 1
# 
#     (doc &opt sym)
# 
#     Shows documentation for the 
#     given symbol, or can show a 
#     list of available bindings. 
#     If sym is a symbol, will 
#     look for documentation for 
#     that symbol. If sym is a 
#     string or is not provided, 
#     will show all lexical and 
#     dynamic bindings in the 
#     current environment 
#     containing that string (all 
#     bindings will be shown if 
#     no string is given).
*doc-width*quexxonPlayground
(math/sqrt 9)  # => 3
math/sqrtcellularmitosisPlayground
(describe :a) # => ":a"
describesogaiuPlayground
(string/trimr " foo ")  # => " foo"
(string/trimr "_!_foo_!_" "_!")  # => "_!_foo"
string/trimrcellularmitosisPlayground
(map bytes?      [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ true  true  true   true   false    false     false        false         ]

(map symbol?     [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ true  false false  false  false    false     false        false         ]

(map keyword?    [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false true  false  false  false    false     false        false         ]

(map string?     [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false true   false  false    false     false        false         ]

(map buffer?     [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false false  true   false    false     false        false         ]
buffer?cellularmitosisPlayground
(math/floor 1.1)  # => 1
(map math/floor [1.1 1.2 1.3])  # => @[1 1 1]
math/floorcellularmitosisPlayground
(slice [:a :b :c :d])  # => (:a :b :c :d)

(slice [:a :b :c :d] 0)  # => (:a :b :c :d)
(slice [:a :b :c :d] 1)  # => (:b :c :d)
(slice [:a :b :c :d] 3)  # => (:d)
(slice [:a :b :c :d] 4)  # => ()
(slice [:a :b :c :d] 5)  # error: index out of range

(slice [:a :b :c :d] -1)  # => ()
(slice [:a :b :c :d] -2)  # => (:d)
(slice [:a :b :c :d] -4)  # => (:b :c :d)
(slice [:a :b :c :d] -5)  # => (:a :b :c :d)
(slice [:a :b :c :d] -6)  # error: index out of range

(slice [:a :b :c :d] 0 0)  # => ()
(slice [:a :b :c :d] 0 1)  # => (:a)
(slice [:a :b :c :d] 0 4)  # => (:a :b :c :d)

(slice [:a :b :c :d] -1 -1)  # => ()
(slice [:a :b :c :d] -2 -1)  # => (:d)
(slice [:a :b :c :d] -5 -1)  # => (:a :b :c :d)

(slice [:a :b :c :d] 1 0)  # => ()
(slice [:a :b :c :d] 4 0)  # => ()
(slice [:a :b :c :d] -1 -2)  # => ()
(slice [:a :b :c :d] -1 -5)  # => ()
slicecellularmitosisPlayground
# Note: the numbers may appear the same, but this is only due to printing truncation.
1                             # => 1
(math/next 1 math/inf)        # => 1
(< 1 1)                       # => false
(< 1 (math/next 1 math/inf))  # => true
math/nextcellularmitosisPlayground
(get default-peg-grammar :a)
# => '(range "az" "AZ")
default-peg-grammarsogaiuPlayground
(update-in @{:a @{:b 1}} [:a :b] (fn [x] (+ 1 x)))
# @{:a @{:b 2}}
update-insbjaverPlayground
(import joy)

# given a handler
(defn handle-func [request]
  (joy/text/plain (string "Hi " ((request :params) :name))))

# joy/defroutes will prepare routes
(joy/defroutes r [:get "/hi/:name" :handle-func])
# which you can pass to joy/app
(joy/server (joy/app {:routes r}) 9002)
# visit localhost:9002/hi/bob
joy/defroutesveqqqPlayground
(compare> 1 0) # => true
(compare> 10 9.9) # => true
(compare> :a :b) # => false
(compare> :b :a) # => true
compare>swlkrPlayground
(def [pipe-r pipe-w] (os/pipe))
(:write pipe-w "hello")
(:read pipe-r 5)
# => @"hello"

# send the string "hello" into the writable stream
# part and read it back from the readable one
os/pipeYohananDiamondPlayground
(get  [10 11 12 13]  0  )  # => 10
(get  {:a 10 :b 20}  :a )  # => 10

(get  [10 11 12]  99  )  # => nil
(get  [10 11 12]  -1  )  # => nil
(get  [10 11 12]  -2  )  # => nil
(get  {:a 1}      :z  )  # => nil

(map  (fn [x] (get x 0))   [  'a  :a  "a"  [97]  @[97]  {0 97}  @{0 97}  ])
# =>                      @[  97  97  97   97    97     97      97       ]
getcellularmitosisPlayground