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

(apply * [1 2 3])     # -> 6
(* (splice [1 2 3]))  # -> 6
(* ;[1 2 3])          # -> 6
(* 1 2 3)             # -> 6
applycellularmitosisPlayground
(os/realpath ".") # => "/home/jgarte"

(os/realpath "Downloads") # => "/home/jgarte/Downloads"
os/realpathjgartePlayground
(describe @[:a :b]) # => "<array 0x55EC375CF440>"
describesogaiuPlayground
$ janet -e '(os/exit 42)' ; echo $?
42
os/exitcellularmitosisPlayground
(pp (all-bindings))
# => prints @[% %= * ... yield zero? zipcoll]

(def a "A")
(pp (all-bindings (curenv) true))
# => prints @[_ a] - only local bindings are listed
all-bindingspepePlayground
(drop 1 "smile")
# => "mile"
dropsogaiuPlayground
(as?-> [1 2 3] _ 
  (sum _)
  (when (> 6 _) _))
# => nil

(as?-> [1 2 3] _ 
  (sum _)
  (when (>= 6 _) _))

# => 6
as?->leobmPlayground
(range 12) # => @[0 1 2 3 4 5 6 7 8 9 10 11]

(range 0 12) # => @[0 1 2 3 4 5 6 7 8 9 10 11]

(range 0 12 1) # => @[0 1 2 3 4 5 6 7 8 9 10 11]

(range 0 12 2) # => @[0 2 4 6 8 10]

(range 0 12 3) # => @[0 3 6 9]

(range 0 12 4) # => @[0 4 8]

(range 0 12 6) # => @[0 6]
rangejgartePlayground
(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/roundcellularmitosisPlayground
(def f (generate [i :range [0 5]] (+ i i)))

(print (fiber/status f))
(print (resume f)) 
(print (resume f)) 
(print (resume f)) 
(print (resume f)) 
(print (resume f)) 
(print (fiber/status f)) # -> :pending
(print (resume f)) 
(print (fiber/status f)) # -> :dead


# :new
# 0
# 2
# 4
# 6
# 8
# :pending
#
# :dead
generateleobmPlayground
(take-while number? 
            (fiber/new
              |(each x [1 2 3 :hi]
                 (yield x))))
# => @[1 2 3]
take-whilesogaiuPlayground
(buffer/bit (buffer/new-filled 1 48) 4)
# => true
buffer/bitsogaiuPlayground
(def a @[1 2])
(array/pop a)  # => 2
a              # => @[1]
(array/pop a)  # => 1
a              # => @[]
(array/pop a)  # => nil
a              # => @[]
array/popcellularmitosisPlayground
(map  |($ {:a 7 :b 8} )   [  keys      values    kvs             pairs                 ])
# =>                     @[  @[:a :b]  @[7 8]    @[:a 7 :b 8]    @[(:a 7) (:b 8)]      ]

(map  |($ [4 5 6] )       [  keys      values    kvs             pairs                 ])
# =>                     @[  @[0 1 2]  @[4 5 6]  @[0 4 1 5 2 6]  @[(0 4) (1 5) (2 6)]  ]

(map  |($ 'ab )           [  keys      values    kvs             pairs                 ])
# =>                     @[  @[0 1]    @[97 98]  @[0 97 1 98]    @[(0 97) (1 98)]      ]

(map  |($ :ab )           [  keys      values    kvs             pairs                 ])
# =>                     @[  @[0 1]    @[97 98]  @[0 97 1 98]    @[(0 97) (1 98)]      ]

(map  |($ "ab" )          [  keys      values    kvs             pairs                 ])
# =>                     @[  @[0 1]    @[97 98]  @[0 97 1 98]    @[(0 97) (1 98)]      ]
pairscellularmitosisPlayground
(one? 1)  # => true
(map one? [0 1 2])  # => @[false true false]

(one? (math/next 1 math/inf))  # => false
one?cellularmitosisPlayground