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 odd? [1 2 3 4])  # => @[true false true false]
odd?cellularmitosisPlayground
(comment

  # the content actually has to parse as janet

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

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

  )
commentsogaiuPlayground
(cmp [1 2] [1 2 3])
# => -1
cmpsogaiuPlayground
# Map over multiple structures -- Stops after the shortest is exhausted.
(map (fn [& args] ;args) [1] [1 2] [1 2 3])

# => @[(1 1 1)]
mapGrazfatherPlayground
(def ds @[@{:a 1 :b 2}
          @{:a 8 :b 9}])

(defn thrice [x] (* x 3))

(update-in ds [0 :b] thrice)

# `ds` is now
@[@{:a 1 :b 6}
  @{:a 8 :b 9}]
update-inuvtcPlayground
(os/time)  # => 1593837535
os/timecellularmitosisPlayground
(map length  [  'a  :a  "a"  [97]  @[97]  {0 97}  @{0 97}  ])
# =>        @[  1   1   1    1     1      1       1        ]
lengthcellularmitosisPlayground
(tabseq [i :in (range 97 100)]
  i (string/from-bytes i))
# =>
@{97 "a"
  98 "b"
  99 "c"}
tabseqsogaiuPlayground
(trace +)
# <function +>

((trace +) 5 3)
# trace (+ 5 3)
# 8

(defn knorkulate [a b]
  ((trace +) a ((trace *) b b )))
# <function knorkulate>

(knorkulate 2 34)
# trace (* 34 34)
# trace (+ 2 1156)
# 1158
tracekamisoriPlayground
(map math/abs   [-2.9 -2.1 2.1 2.9])  # => @[ 2.9  2.1  2.1  2.9 ]
(map math/floor [-2.9 -2.1 2.1 2.9])  # => @[ -3   -3   2    2   ]
(map math/ceil  [-2.9 -2.1 2.1 2.9])  # => @[ -2   -2   3    3   ]
(map math/round [-2.9 -2.1 2.1 2.9])  # => @[ -3   -2   2    3   ]
(map math/trunc [-2.9 -2.1 2.1 2.9])  # => @[ -2   -2   2    2   ]
math/ceilcellularmitosisPlayground
(def b @"")
(def v (* 1000 (math/random)))
# => 487.181 your number can differ
(xprinf b "Value reached level %f" v)
# => nil
b
# => @"Value reached level 487.181188"
xprinfpepePlayground
(def new-bytes 512)

(var new-buffer (buffer/new new-bytes))

# --> @""
buffer/newMorganPetersonPlayground
# :as sets a /

(import /deeper/inside :prefix "" :export true)
# @{_ @{:value <cycle 0>} cat @{:private false}}
(import /deeper/inside :as "" :export true)
# @{/cat @{:private false} _ @{:value <cycle 0>} cat @{:private false}}

importveqqqPlayground
(abstract? (file/temp))  # => true
(abstract? (int/s64 1))  # => true

(map abstract?  [ nil true 97 'a :a "a" ])
# => @[false false false false false false]

(map abstract?  [ [97]  @[97]  {0 97}  @{0 97} ])
# => @[false false false false]

(map abstract?  [ even? loop file/open  (fn [])  ])
# => @[false false false false]

(map abstract?  [ (file/temp)  (fiber/new (fn []))  ])
# => @[true false]
abstract?cellularmitosisPlayground
(peg/find-all ':d "Battery temperature: 40 °C")

# => @[21 22] indices containing digits

# :d (range "09")

# peg grammars are contained in a table @{} (mutable) located in boot.janet source file.

peg/find-alljgartePlayground