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

(get @"A"                      0)  # => 65 (0b01000001)
(get (buffer/bit-clear @"A" 0) 0)  # => 64 (0b01000000)
(get (buffer/bit-clear @"A" 6) 0)  # =>  1 (0b00000001)
buffer/bit-clearcellularmitosisPlayground
(tabseq [i :in (range 97 100)]
  i (string/from-bytes i))
# =>
@{97 "a"
  98 "b"
  99 "c"}
tabseqsogaiuPlayground
# build own map-indexed with map

(defn map-indexed [f ds]
    (map f (range 0 (length ds)) ds))

(map-indexed (fn [i v] [i v] ) ["a" "b" "c" "d"])

# => @[(0 "a") (1 "b") (2 "c") (3 "d")]
mapleobmPlayground
(compare> 1 0) # => true
(compare> 10 9.9) # => true
(compare> :a :b) # => false
(compare> :b :a) # => true
compare>swlkrPlayground
(or true)        # => true
(or true true)   # => true
(or true false)  # => true

(or false 1 2)  # => 1
(or false 2 1)  # => 2

(or false nil)  # => nil
(or nil false)  # => false

# note that `or` does not behave as you might expect
# when used with `apply` and `splice`:
(or 1 2 3)             # => 1
(or (splice [1 2 3]))  # => (1 2 3)
(apply or [1 2 3])     # => (if 1 1 (if 2 2 3))
orcellularmitosisPlayground
(string/has-suffix? ".janet" "code.janet") # => true
string/has-suffix?sogaiuPlayground
(next  [4 5 6]    )  # => 0
(next  [4 5 6]  0 )  # => 1
(next  [4 5 6]  1 )  # => 2
(next  [4 5 6]  2 )  # => nil

# note that dictionary keys are not necessarily in the same order
# as the corresponding literal.
(next  {:a 5 :b 6 :c 7}     )  # => :a
(next  {:a 5 :b 6 :c 7}  :a )  # => :c
(next  {:a 5 :b 6 :c 7}  :c )  # => :b
(next  {:a 5 :b 6 :c 7}  :b )  # => nil
nextcellularmitosisPlayground
(/)
# => 1
/sogaiuPlayground
(def person-ids {"Alice" 42 "Bob" 23})

(keep person-ids ["Carl" "Bob" "Alice"])   # -> @[23 42]

(filter person-ids ["Carl" "Bob" "Alice"]) # -> @["Bob" "Alice"]
(map person-ids ["Carl" "Bob" "Alice"])    # -> @[nil 23 42]
keepfelixrPlayground
(def a @[23 42])
(array/clear a)
(pp a)
# => prints @[]
array/clearpepePlayground
(if-let [x true 
         y (not (not x))]
  :a
  :b)
# => :a
if-letsogaiuPlayground
(as-> [1 2 3] _ 
  (map inc _)
  (sum _)
  (- _ 10)
  (< _ 0))
# -> true

# same as
(< (- (sum (map inc [1 2 3])) 10) 0)
as->felixrPlayground
(in :yo 0)
# => 121
insogaiuPlayground
(os/execute
  ["python" "-c" "print('Hello Janet'"])
  :p
os/executegoldenHairDafoPlayground
(get default-peg-grammar :a)
# => '(range "az" "AZ")
default-peg-grammarsogaiuPlayground