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

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

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

(map table?      [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false false  false  false    false     false        true          ]
dictionary?cellularmitosisPlayground
# convert a string to an integer
(peg/match '(number :d+) "123")
#=> @[123]

(first (peg/match '(number :d+) "123"))
#=> 123
peg/matcherichaneyPlayground
(seq [i :range [0 3]
      j :range [0 3]
      :let [c (string/format "%c" (+ 97 i))]]
  [(keyword c) j])
# => '@[(:a 0) (:a 1) (:a 2) (:b 0) (:b 1) (:b 2) (:c 0) (:c 1) (:c 2)]
seqsogaiuPlayground
(kvs (struct :a 1 :b 2))
# => @[:a 1 :b 2]
kvssogaiuPlayground
(defn f1 [s] (string "-" s "-"))
(defn f2 [s] (string "=" s "="))
(defn f3 [s] (string "#" s "#"))

(def f (juxt f1 f2 f3))

(f "x") # => ("-x-" "=x=" "#x#")
juxtuvtcPlayground
(var x 1)
(+= x 2 3 4)
# x = 10
+=erichaneyPlayground
(print math/int-min)
-9007199254740992
nil
math/int-minbtbytesPlayground
(eval-string "(+ 1 2 3 4)") # -> 10
(eval-string ")") # -> parse error
(eval-string "(bloop)") # -> compile error
(eval-string "(+ nil nil)") # -> runtime error
eval-stringswlkrPlayground
# 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
(defn dataframe 
  ``Create an empty dataframe with the given columns``
  [& columns]
  (tabseq [c :in columns] c @[]))
tabseqveqqqPlayground
(def h ["a" "b" :c]) # => ("a" "b" :c)

(find (fn [a] (= "a" a)) h) # => "a"
findfaywongPlayground
(update-in @{:a @{:b 1}} [:a :b] (fn [x] (+ 1 x)))
# @{:a @{:b 2}}
update-insbjaverPlayground
(disasm +)
# {:max-arity 2147483647
#  :constants @[]
#  :name "+"
#  :defs @[]
#  :vararg true
#  :environments @[]
#  :arity 0
#  :slotcount 6

#  :bytecode
#  @[(len 1 0)
#    (eqim 2 1 0)
#    (jmpno 2 3)
#    (ldi 3 0)
#    (ret 3)
#    (eqim 2 1 1)
#    (jmpno 2 5)
#    (ldi 3 0)
#    (geti 4 0 0)
#    (add 3 3 4)
#    (ret 3)
#    (geti 3 0 0)
#    (ldi 5 1)
#    (in 4 0 5)
#    (add 3 3 4)
#    (addim 5 5 1)
#    (eq 2 5 1)
#    (jmpno 2 -4)
#    (ret 3)]
#  :min-arity 0}
disasmskuzzymigletPlayground
(fiber? (fiber/new (fn [])))
# => true
fiber?sogaiuPlayground
(var buf @"")
(buffer/push-word buf 2147483647)

(+
  (get buf 0)                # byte 1
  (blshift (get buf 1) 8)    # byte 2
  (blshift (get buf 2) 16)   # byte 3
  (blshift (get buf 3) 24))  # byte 4

# => 2147483647
buffer/push-wordleobmPlayground