JanetDocsPlaygroundI'm feeling luckyGitHub sign in

JanetDocs is a community documentation site for the Janet programming language

Loading...

Recent examples

(seq [i :range [0 3]
      j :range [0 3]
      :let [c (string/format "%c" (+ 97 i))]
      :when (and (even? i) (even? j))]
  [(keyword c) j])
# => '@[(:a 0) (:a 2) (:c 0) (:c 2)]
seqsogaiuPlayground
(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
(seq [i :range [0 3]
      j :range [0 3]]
  [(keyword (string/format "%c" (+ 97 i)))
   j])
# => '@[(:a 0) (:a 1) (:a 2) (:b 0) (:b 1) (:b 2) (:c 0) (:c 1) (:c 2)]
seqsogaiuPlayground
(var a nil)

(var b nil)

(varfn a
  [x]
  (if (zero? x)
    0
    (b x)))
    
(varfn b
  [y]
  (if (pos? y)
    1
    (a y)))
    
(a 1)
# => 1

(b 0)
# => 0
varfnsogaiuPlayground
(cmp 0.0 0)
# => 0
cmpsogaiuPlayground
(cmp [1 2] [1 2 3])
# => -1
cmpsogaiuPlayground
(cmp 1.0 2)
# => -1
cmpsogaiuPlayground
(table/clear @{:a 1 :b 2})
# => @{}
table/clearsogaiuPlayground
(->> ["small" "cuddly" "creature"]
     (interpose "-")
     splice
     keyword)
# => :small-cuddly-creature
keywordsogaiuPlayground
(keyword :)
# => :
keywordsogaiuPlayground
(keyword)
# => :
keywordsogaiuPlayground
(keyword "")
# => :
keywordsogaiuPlayground
(let [x false]
  (var y 0)
  (unless x
    (++ y)
    (++ y))
  y)
# => 2
unlesssogaiuPlayground
(-> @{:a 0 :b 0}
    (update :a inc)
    (update :b inc))
# => @{:a 1 :b 1}
updatesogaiuPlayground
(update @{:a 1} :a inc)
# => @{:a 2}
updatesogaiuPlayground
(let [c (ev/chan 1)
      before (ev/count c)]
  (ev/give c :hi)
  [before (ev/count c)])
# => '(0 1)
ev/countsogaiuPlayground
(/ 0)
# => inf
/sogaiuPlayground
(/ 1 2 3)
# => 0.166667
/sogaiuPlayground
(/ 2)
# => 0.5
/sogaiuPlayground
(/)
# => 1
/sogaiuPlayground
(peg/replace ~(sequence :s (thru "t")) 
             " duck"
             "smiling cat sleeps")
# => @"smiling duck sleeps"
peg/replacesogaiuPlayground
(comment

  # the content actually has to parse as janet

  # this is ok
  (+ 1 1)
  # => 2

  # if there is something with missing delimiters though...

  )
commentsogaiuPlayground
(scan-number "1_000_000")
# => 1000000
scan-numbersogaiuPlayground
(scan-number "111" 2)
# => 7
scan-numbersogaiuPlayground
(= (brushift 2r1000 1 1 1) 2r0001)
# => true
brushiftsogaiuPlayground
(do
  (def before (dyn :expression))
  (setdyn :expression :smile)
  [before (dyn :expression)])
# => '(nil :smile)
setdynsogaiuPlayground
(let [p @{:a 1}
      t @{:b 2}]
  (table/setproto t p)
  [(get t :a) (table/rawget t :a)])
# => '(1 nil)
table/rawgetsogaiuPlayground
(empty? :)
# => true
empty?sogaiuPlayground
(empty? {})
# => true
empty?sogaiuPlayground
(empty? [])
# => true
empty?sogaiuPlayground