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

(do
  (def before (dyn :expression))
  (setdyn :expression :smile)
  [before (dyn :expression)])
# => '(nil :smile)
setdynsogaiuPlayground
(take 2 [1 -2 2 3 9 -10])  # (1 -2)
takebtbytesPlayground
(let [a 1]
 (let [b a]
  b)) # => 1
letjgartePlayground
(string/split "," "bruce,scott,tiger,woods")
# => @["bruce" "scott" "tiger" "woods"]
string/splitsogaiuPlayground
(loop [i :range [0 12]]
  (print i))

# => 0
# => 1
# => 2
# => 3
# => 4
# => 5
# => 6
# => 7
# => 8
# => 9
# => 10
# => 11
# => nil

loopjgartePlayground
(peg/find ':s "Battery temperature: 40 °C")

# => 7 index of the first whitespace character

# :s (set " \t\r\n\0\f\v")

peg/findjgartePlayground
(int/s64 42)    # => <core/s64 42>
(int/s64 42.1)  # => <core/s64 42>
(int/s64 "42")  # => <core/s64 42>
int/s64cellularmitosisPlayground
(in :yo 0)
# => 121
insogaiuPlayground
(let [c (ev/chan 1)
      before (ev/count c)]
  (ev/give c :hi)
  [before (ev/count c)])
# =>
'(0 1)
ev/countsogaiuPlayground
(ev/spawn (os/sleep 1) (print "Hard work is done!"))

# prints "Hard work is done!" after one second
# this is the easiest way to put some forms on the event loop
# but do not forget REPL is blocking, for now, so run the example with `janet -e`
ev/spawnpepePlayground
# note that os/touch does not create a file if it does not yet exist.
(os/touch "foo")
error: No such file or directory
  in os/touch
  in _thunk [repl] (tailcall) on line 2, column 1
os/touchcellularmitosisPlayground
(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          ]
table?cellularmitosisPlayground
(sorted [1 -2 2 3 9 -10])  # @[-10 -2 1 2 3 9]
sortedbtbytesPlayground
(eachk k [1 2 3] (print k))
# prints 0
# prints 1
# prints 2
# for indexed collections indices are printed  
eachkpepePlayground
(filter identity [1 true 2 3 nil 4 false])
# => @[1 true 2 3 4]
identityleobmPlayground